mongodb 配置单实例与双实例

环境: centos6.5 192.168.16.70

配置单实例mongodb:
[root@www soft]# tar xf mongodb-linux-x86_64-rhel62-3.2.7.tgz
[root@www soft]# ls
mongodb-linux-x86_64-rhel62-3.2.7
mongodb-linux-x86_64-rhel62-3.2.7.tgz
[root@www soft]# mv mongodb-linux-x86_64-rhel62-3.2.7 /usr/local/mongodb
[root@www soft]# cd /usr/local/mongodb/
[root@www mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[root@www mongodb]# ulimit -n
1024
[root@www mongodb]# ulimit -n 25000 //指定同一时间最多可开启的文件数
[root@www mongodb]# ulimit -u
3648
[root@www mongodb]# ulimit -u 25000 //用户最多可开启的程序数目
[root@www mongodb]# ulimit -n
25000
[root@www mongodb]# ulimit -u
25000
[root@www mongodb]# mkdir -p /data/mongodb1
[root@www mongodb]# mkdir -p /data/logs/mongodb
[root@www mongodb]# touch /data/logs/mongodb/mongodb1.log
[root@www mongodb]# cd /usr/local/mongodb/
[root@www mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[root@www mongodb]# mkdir conf
[root@www mongodb]# vim conf/mongodb1.conf

port=27017
dbpath=/data/mongodb1
logpath=/data/logs/mongodb/mongodb1.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
[root@www mongodb]# pwd
/usr/local/mongodb
[root@www mongodb]# ls
bin conf GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[root@www 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
[root@www 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
[root@www mongodb]# netstat -lnpt | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1652/bin/mongod
[root@www mongodb]# lsof -i:27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 1652 root 6u IPv4 12709 0t0 TCP *:27017 (LISTEN)
[root@www conf]# vim /etc/rc.local //设置开机自启动
rm -rf /data/mongodb1/mongod.lock
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf

[root@www 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

去除报错问题:
[root@www mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@www mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@www ~]# vim .bash_profile
。。。。。。。。。。。。。。。。
alias mongo=/usr/local/mongodb/bin/mongo
。。。。。。。。。。。。。。。。。。。
[root@www ~]# source .bash_profile

关闭服务的三种方法:
方法一:
[root@www 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

方法二:
[root@www mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf --shutdown
killing process with pid: 1829

方法三:杀进程号(不建议用杀进程方法,mongodb集群的话节点数据不易保存)
[root@www 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
[root@www 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
[root@www mongodb]# kill 1882
[root@www mongodb]# ps -ef | grep mongod
root 1899 1717 0 05:41 pts/1 00:00:00 grep mongod

 

开启两个实例,配置双实例mongodb:

[root@www conf]# pwd
/usr/local/mongodb/conf
[root@www conf]# vim mongodb2.conf

port=27018
dbpath=/data/mongodb2
logpath=/data/logs/mongodb/mongodb2.log
logappend=true //日志追加
fork=true
maxConns=5000
storageEngine=mmapv1 //存储引擎

[root@www conf]# ls /data/ //建立mongodb2数据文件目录
logs mongodb1 mongodb2
[root@www conf]# ls /data/logs/mongodb/ //建立mongodb2.log 日志文件
mongodb1.log mongodb2.log
[root@www mongodb2]# chmod 777 /data/logs/mongodb/mongodb2.log //给mongodb2.log添加权限

编写启停脚本:
[root@www mongodb2]# cd /etc/init.d
[root@www 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

[root@www init.d]# chmod +x mongodb
[root@www 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
[root@www 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
[root@www 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

 

posted @ 2017-09-16 20:59  刘振川的博客  阅读(618)  评论(0编辑  收藏  举报