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
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129127.html
摘要:本文中我们就来聊一聊如何使用和两个工具快速搭建一个测试集群。注意的目的旨在为我们快速搭建测试环境,绝对不应该用于生产环境的使用上。准备工作安装是用于的一系列工具,就是其中用于快速启动的一部分。以下这些参数是我们经常使用的启动一个复制集。 前言 不知道大家在使用MongoDB的时候有没有遇到突然想要一个集群但是手边又没有的时候?特别是我已经升级到4.0了,突然想要一个3.2的集群怎么办?...
摘要:虚拟内存区域是一个连续的虚拟地址空间区域。四启动集群首先切换为用户,并启动服务器上的节点注意参数表示以后台进程启动,默认情况下会在控制台输出日志。 最近在学习ES相关内容,为了方便自己使用,在本地虚拟机上搭建了一个3节点的ES集群,在搭建过程中,遇到了许多坑,网上的资料也比较分散,所以详细整理一下搭建过程发出来供参考。搭建过程中,由于是两台虚拟机,所以有一种很快速的办法,搭建一台,然后...
摘要:原文保持更新及修正基于的客户端配置选项,其它驱动大同小异。连接池中连接的最大使用寿命毫秒。设置该选项后,客户端将进行以下行为以副本集模式连接,并根据给定的服务器发现副本集的所有成员。该选项可以和配合使用。编解码器用于对进行编码和解码。 原文保持更新及BUG修正:http://kweny.io/mongodb-clien... 基于 MongoDB Java Driver 3.8.1 ...
阅读 1250·2023-01-11 13:20
阅读 1559·2023-01-11 13:20
阅读 1013·2023-01-11 13:20
阅读 1680·2023-01-11 13:20
阅读 3972·2023-01-11 13:20
阅读 2520·2023-01-11 13:20
阅读 1356·2023-01-11 13:20
阅读 3486·2023-01-11 13:20