大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
MongoDB 主从
我们提供的服务有:成都网站制作、做网站、微信公众号开发、网站优化、网站认证、金城江ssl等。为超过千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的金城江网站制作公司
系统:Centos6.6x64
安装目录:/usr/local/
主:172.16.15.101
从:172.16.15.102
1,下载安装:
# wget https://fastdl.mongodb.org/src/mongodb-src-r3.2.7.tar.gz?_ga=1.217384598.1880361485.1476164670
新版本 # wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.9.tgz
# tar -xf mongodb-linux-x86_64-3.2.7.tgz
# mv mmongodb-linux-x86_64-3.2.7 /usr/local/mongodb
2,mongodb环境变量配置
# cat /etc/profile
# export PATH=$PATH:/usr/local/mongodb/bin
# source /etc/profile
3,iptables/selinux及内核设置:
# cat /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 28017 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
# sed "s/SELINUX=enables/SELINUX=disabled/g" /etc/sysconfig/selinux
SELINUX=disabled
# cat >>/etc/rc.d/rc.local < echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag HERE 4,创建文件存放目录: # mkdir -p /usr/local/mongodb/{log,db,conf} 主服务 :172.16.15.101 5,mongod.conf 参考配置; ### **** systemLog: destination: file logAppend: true logRotate: rename timeStampFormat: ctime path: /usr/local/mongodb/log/mongod.log storage: dbPath: /usr/local/mongodb/db journal: enabled: true processManagement: fork: true # fork and run in background pidFilePath: /usr/local/mongodb/mongod.pid # location of pidfile net: port: 27017 #bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces. http: enabled: true JSONPEnabled: true RESTInterfaceEnabled: true setParameter: enableLocalhostAuthBypass: false master = true # # source = 172.16.15.102 # 从服务地址不用配置 部分参数解释 // 附件有官方配置文件 --fork #后台daemon运行 --bind_ip #监听IP地址列表,以逗号分隔 --port #监听端口,默认27017 --setParameter enableLocalhostAuthBypass=0 #所有接口都需要认证 --pidfilepath #pid文件 --dbpath #db存放路径 --logpath #日志文件 --config #配置文件 --auth #启用认证 --httpinterface #启用web接口 --rest #rest api --jsonp #json api 从服务:172.16.15.102 6, mongod.conf 参考配置; ### **** systemLog: destination: file logAppend: true logRotate: rename timeStampFormat: ctime path: /usr/local/mongodb/log/mongod.log storage: dbPath: /usr/local/mongodb/db journal: enabled: true processManagement: fork: true # fork and run in background pidFilePath: /usr/local/mongodb/mongod.pid # location of pidfile net: port: 27017 #bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces. http: enabled: true JSONPEnabled: true RESTInterfaceEnabled: true setParameter: enableLocalhostAuthBypass: false slave = true # source = 172.16.15.101 # 7,从服务器启动 /usr/local/mongodb/bin/mongod --fork --slave --source 172.16.15.101:27017 --port 27017 --dbpath /usr/local/mongodb/db --logpath /usr/local/mongodb/log/mongodb.log 8,启动检测mongod进程以及端口 # mongod --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /usr/local/mongodb/mongod.pid --dbpath /usr/local/mongodb/db --logpath /usr/local/mongodb/log/mongod.log --logappend --logRotate rename --timeStampFormat ctime 主要的配置文件 日志 进程端口启动就好; 主的启动: /usr/local/mongodb/bin/mongod --fork --master --oplogSize=1024 --port 27017 --dbpath /usr/local/mongodb/db --logpath /usr/local/mongodb/log/mongodb.log # ps -ef|grep mongod # netstat -tunlp|grep mongod 9,init.d/mongod 自控脚本 # useradd -s /sbin/nologin -r mongod # chown -R mongod: /usr/local/mongodb # /etc/init.d/mongod // * 这个附件有官方配置信息 # chmod +x /etc/init.d/mongod // * 需要更改配置目录 # sed -i '/CONFIGFILE=/i MONGOD="/usr/local/mongodb/bin/mongod"' /etc/init.d/mongod # sed -i '/CONFIGFILE=/s:/etc/mongod.conf:/usr/local/mongodb/conf/mongod.conf:g' /etc/init.d/mongod
本文标题:MongoDB_3.2.7主从部署
网页URL:http://dzwzjz.com/article/pjopgg.html