標籤:ever   this   err   ready   開機   trying   kernel   started   pid   
環境: centos6.5 192.168.16.70
配置單一實例mongodb:
[[email protected] soft]# tar xf mongodb-linux-x86_64-rhel62-3.2.7.tgz 
[[email protected] soft]# ls
mongodb-linux-x86_64-rhel62-3.2.7 
mongodb-linux-x86_64-rhel62-3.2.7.tgz 
[[email protected] soft]# mv mongodb-linux-x86_64-rhel62-3.2.7 /usr/local/mongodb
[[email protected] soft]# cd /usr/local/mongodb/
[[email protected] mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# ulimit -n
1024
[[email protected] mongodb]# ulimit -n 25000 //指定同一時間最多可開啟的檔案數
[[email protected] mongodb]# ulimit -u
3648
[[email protected] mongodb]# ulimit -u 25000 //使用者最多可開啟的程式數目
[[email protected] mongodb]# ulimit -n
25000
[[email protected] mongodb]# ulimit -u
25000
[[email protected] mongodb]# mkdir -p /data/mongodb1
[[email protected] mongodb]# mkdir -p /data/logs/mongodb
[[email protected] mongodb]# touch /data/logs/mongodb/mongodb1.log
[[email protected] mongodb]# cd /usr/local/mongodb/
[[email protected] mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# mkdir conf
[[email protected] mongodb]# vim conf/mongodb1.conf
port=27017
dbpath=/data/mongodb1
logpath=/data/logs/mongodb/mongodb1.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
[[email protected] mongodb]# pwd
/usr/local/mongodb
[[email protected] mongodb]# ls
bin conf GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf //啟動mongodb資料庫 -f 指定設定檔
about to fork child process, waiting until server is ready for connections.
forked process: 1652
child process started successfully, parent exiting
[[email protected] mongodb]# ps -ef | grep mongod
root 1652 1 2 04:53 ? 00:00:00 bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf
root 1666 1607 0 04:53 pts/0 00:00:00 grep mongod
[[email protected] mongodb]# netstat -lnpt | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1652/bin/mongod 
[[email protected] mongodb]# lsof -i:27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 1652 root 6u IPv4 12709 0t0 TCP *:27017 (LISTEN)
[[email protected] conf]# vim /etc/rc.local //設定開機自啟動
rm -rf /data/mongodb1/mongod.lock
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf
[[email protected] mongodb]# bin/mongo //登陸mongodb資料庫
MongoDB shell version: 3.2.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2017-03-28T04:53:32.052+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-03-28T04:53:32.052+0800 I CONTROL [initandlisten] 
> show dbs
local 0.078GB
> exit
bye
去除報錯問題:
[[email protected] mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[[email protected] mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[[email protected] ~]# vim .bash_profile
。。。。。。。。。。。。。。。。
alias mongo=/usr/local/mongodb/bin/mongo
。。。。。。。。。。。。。。。。。。。
[[email protected] ~]# source .bash_profile 
關閉服務的三種方法:
方法一:
[[email protected] mongodb]# bin/mongo
MongoDB shell version: 3.2.7
connecting to: test
Server has startup warnings: 
2017-03-28T05:16:53.926+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-03-28T05:16:53.926+0800 I CONTROL [initandlisten] 
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
2017-03-28T05:38:06.756+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-03-28T05:38:06.758+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-03-28T05:38:06.758+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed 
> exit
bye
方法二:
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf --shutdown
killing process with pid: 1829
方法三:殺進程號(不建議用殺進程方法,mongodb叢集的話節點資料不易儲存)
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 1882
child process started successfully, parent exiting
[[email protected] mongodb]# ps -ef | grep mongod
root 1882 1 2 05:41 ? 00:00:00 bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf
root 1896 1717 0 05:41 pts/1 00:00:00 grep mongod
[[email protected] mongodb]# kill 1882
[[email protected] mongodb]# ps -ef | grep mongod
root 1899 1717 0 05:41 pts/1 00:00:00 grep mongod
 
開啟兩個執行個體,配置雙執行個體mongodb:
[[email protected] conf]# pwd
/usr/local/mongodb/conf
[[email protected] conf]# vim mongodb2.conf 
port=27018
dbpath=/data/mongodb2
logpath=/data/logs/mongodb/mongodb2.log
logappend=true //日誌追加
fork=true
maxConns=5000
storageEngine=mmapv1 //儲存引擎
[[email protected] conf]# ls /data/ //建立mongodb2資料檔案目錄
logs mongodb1 mongodb2
[[email protected] conf]# ls /data/logs/mongodb/ //建立mongodb2.log 記錄檔
mongodb1.log mongodb2.log
[[email protected] mongodb2]# chmod 777 /data/logs/mongodb/mongodb2.log //給mongodb2.log添加許可權
編寫啟停指令碼:
[[email protected] mongodb2]# cd /etc/init.d
[[email protected] init.d]# vim mongodb 
#!/bin/bash
INSTANCE=$1
ACTION=$2
case "$ACTION" in
start)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;
stop)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;
restart)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf --shutdown
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;
esac
[[email protected] init.d]# chmod +x mongodb
[[email protected] init.d]# /etc/init.d/mongodb mongodb1 start
about to fork child process, waiting until server is ready for connections.
forked process: 1957
child process started successfully, parent exiting
[[email protected] init.d]# /etc/init.d/mongodb mongodb2 start
about to fork child process, waiting until server is ready for connections.
forked process: 1973
child process started successfully, parent exiting
[[email protected] init.d]# ps -ef | grep mongodb 
root 1957 1 1 05:56 ? 00:00:00 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf
root 1973 1 1 05:56 ? 00:00:00 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf
root 1987 1902 0 05:56 pts/2 00:00:00 grep mongodb
 
mongodb 配置單一實例與雙執行個體