MongoDB軟件下載
主機環境配置
useradd mongo
echo "password"|passwd mongo --stdin 1>/dev/null;
mkdir -p /opt/mongodb
cd /opt/
chown mongo:mongo mongodb
su - mongo
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.18.tgz -C /opt/mongodb
tar -zxvf mongodb-database-tools-rhel70-x86_64-100.6.1.tgz -C /opt/mongodb
cd /opt/mongodb
mv mongodb-linux-x86_64-rhel70-4.4.18 mongodb_4.4.18
cd mongodb-database-tools-rhel70-x86_64-100.6.1
scp -r * /opt/mongodb/mongodb_4.4.18/
cd /opt/mongodb/
rm -rf mongodb-database-tools-rhel70-x86_64-100.6.1
exit
echo "############ for mongo ############">>/etc/profile
echo "if [ $USER = mongo ]; then">>/etc/profile
echo "export PATH=$PATH:/usr/local/mongodb/bin">>/etc/profile
echo "fi">>/etc/profile
source /etc/profile
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/* /etc/yum.repos.d/backup
touch /etc/yum.repos.d/CentOS7-source.repo
echo "[CentOS7]">>/etc/yum.repos.d/CentOS7-source.repo
echo "name=local_yum">>/etc/yum.repos.d/CentOS7-source.repo
echo "baseurl=file:///mnt">>/etc/yum.repos.d/CentOS7-source.repo
echo "gpgcheck=0">>/etc/yum.repos.d/CentOS7-source.repo
echo "enabled=1">>/etc/yum.repos.d/CentOS7-source.repo
yum install -y libcurl xz-libs cyrus-sasl cyrus-sasl-gssapi
cyrus-sasl-plain krb5-libs libcurl libpcap lm_sensors-libs
net-snmp net-snmp-agent-libs openldap openssl rpm-libs
tcp_wrappers-libs telnet sysstat iotop dstat nmap net-tools
1)官方文檔連接如下,可選擇需要安裝的MongoDB版本
https://www.mongodb.com/docs/v4.4/administration/production-checklist-operations/
本次安裝環境:
echo "############ for mongo ############">>/etc/security/limits.conf
echo "mongo soft nofile 64000">>/etc/security/limits.conf
echo "mongo hard nofile 64000">>/etc/security/limits.conf
echo "mongo soft nproc 32000">>/etc/security/limits.conf
echo "mongo hard nproc 32000">>/etc/security/limits.conf
su - mongo
ulimit -f
ulimit -t
ulimit -v
ulimit -l
ulimit -n
ulimit -m
ulimit -u
echo "############ for mongo ############">>/etc/sysctl.conf
echo "kernel.shmall = 536870912">>/etc/sysctl.conf
echo "kernel.shmmax = 12884901888">>/etc/sysctl.conf
echo "net.ipv4.conf.all.accept_redirects=0">>/etc/sysctl.conf
echo "vm.swappiness=5">>/etc/sysctl.conf
echo "vm.min_free_kbytes = 512000">>/etc/sysctl.conf
echo "vm.dirty_ratio = 80">>/etc/sysctl.conf
echo "vm.dirty_expire_centisecs = 500">>/etc/sysctl.conf
echo "vm.dirty_writeback_centisecs = 100">>/etc/sysctl.conf
echo "fs.file-max=98000 ">>/etc/sysctl.conf
echo "kernel.pid_max=64000 ">>/etc/sysctl.conf
echo "vm.max_map_count=12800">>/etc/sysctl.conf
echo "kernel.threads-max=64000">>/etc/sysctl.conf
dmesg | grep -i numa
如果有多個nodes則需要關閉numa
echo 0 > /proc/sys/vm/zone_reclaim_mode
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
cat /etc/default/grub |grep GRUB_CMDLINE_LINUX|grep ^[^#]
sed -i /GRUB_CMDLINE_LINUX/ s/quiet/quiet numa=off transparent_hugepage=never elevator=noop/ /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
參數解釋:
sudo blockdev --report
/dev/sdb為500 GB的數據磁盤,修改預讀值
sudo blockdev --setra 8 /dev/sdb
echo "/sbin/blockdev --setra 8 /dev/sdb">>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
cat /etc/rc.d/rc.local|grep ^[^#]
mount -t xfs -o noatime -o nodiratime /dev/sdb /data
echo "/dev/mapper/vgdata-data /data xfs noatime,nodiratime 0 0">>/etc/fstab
systemctl status tuned.service
systemctl stop tuned.service
systemctl disable tuned.service
yum -y install chrony
systemctl enable chronyd
systemctl start chronyd
echo "server 時鐘服務器IP iburst">>/etc/chrony.conf
systemctl restart chronyd
systemctl status chronyd
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
sed -i /SELINUX/ s/enforcing/disabled/ /etc/selinux/config
以上為MongoDB主機環境配置過程,配置過程需要根據實際環境進行修改。
MongoDB復制集群搭建
su – root
mkdir -p /data/mgmongo/log
mkdir -p /data/mgmongo/pid
mkdir -p /data/mgmongo/mongod_test
chown mongo:mongo -R /data/mgmongo
cd /etc/
mkdir mongodb
chown mongo:mongo mongodb
su - mongo
cd /etc/mongodb
touch mongo_test.conf
systemLog:
verbosity: 0
destination: file
path: "/data/mgmongo/log/mongod_test.log"
logAppend: true
logRotate: rename
processManagement:
fork: true
pidFilePath: "/data/mgmongo/pid/mongo_test.pid"
net:
port: 27017
bindIpAll: true
maxIncomingConnections: 5000
unixDomainSocket:
enabled: true
pathPrefix: "/tmp"
#security:
# keyFile: "/etc/mongodb/mongo_keyfile"
# clusterAuthMode: keyFile
# authorization: enabled
operationProfiling:
mode: slowOp
slowOpThresholdMs: 200
storage:
dbPath: "/data/mgmongo/mongod_test"
journal:
enabled: true
commitIntervalMs: 100
directoryPerDB: true
engine: wiredTiger
engineConfig:
cacheSizeGB: 12
cloud:
monitoring:
free:
state: off
replication:
oplogSizeMB: 2000
replSetName: rs_test
enableMajorityReadConcern: false
/usr/local/mongodb/bin/mongod -f /etc/mongodb/mongo_test.conf
/usr/local/mongodb/bin/mongo --host 服務器IP --port 27017
rs.initiate(
{
_id : "rs_test",
members: [
{ _id : 0, host : "服務器IP1:27017",priority:1 },
{ _id : 1, host : "服務器IP2:27017",priority:1 },
{ _id : 2, host : "服務器IP3:27017",priority:1 }
]
}
)
use admin
db.createUser(
{
user: "root",
pwd: "password",
roles: [{ role: "root", db: "admin" }]
}
)
cd /etc/mongodb
touch mongo_keyfile
openssl rand -base64 756 > /etc/mongodb/mongo_keyfile
chmod 400 /etc/mongodb/mongo_keyfile
/usr/local/mongodb/bin/mongod -f /etc/mongodb/mongo_test.conf –shutdown
/usr/local/mongodb/bin/mongod -f /etc/mongodb/mongo_test.conf
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129127.html
摘要:本文中我們就來聊一聊如何使用和兩個工具快速搭建一個測試集群。注意的目的旨在為我們快速搭建測試環境,絕對不應該用于生產環境的使用上。準備工作安裝是用于的一系列工具,就是其中用于快速啟動的一部分。以下這些參數是我們經常使用的啟動一個復制集。 前言 不知道大家在使用MongoDB的時候有沒有遇到突然想要一個集群但是手邊又沒有的時候?特別是我已經升級到4.0了,突然想要一個3.2的集群怎么辦?...
摘要:虛擬內存區域是一個連續的虛擬地址空間區域。四啟動集群首先切換為用戶,并啟動服務器上的節點注意參數表示以后臺進程啟動,默認情況下會在控制臺輸出日志。 最近在學習ES相關內容,為了方便自己使用,在本地虛擬機上搭建了一個3節點的ES集群,在搭建過程中,遇到了許多坑,網上的資料也比較分散,所以詳細整理一下搭建過程發出來供參考。搭建過程中,由于是兩臺虛擬機,所以有一種很快速的辦法,搭建一臺,然后...
摘要:原文保持更新及修正基于的客戶端配置選項,其它驅動大同小異。連接池中連接的最大使用壽命毫秒。設置該選項后,客戶端將進行以下行為以副本集模式連接,并根據給定的服務器發現副本集的所有成員。該選項可以和配合使用。編解碼器用于對進行編碼和解碼。 原文保持更新及BUG修正:http://kweny.io/mongodb-clien... 基于 MongoDB Java Driver 3.8.1 ...
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1860·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20