您好,登錄后才能下訂單哦!
MongoDB 主從
系統: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 <<HERE
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。