mongodb集群
#下载mongodb# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.6.tgz
# tar xf mongodb-linux-x86_64-rhel70-3.2.6.tgz -C /usr/local/
# ln -sv /usr/local/mongodb-linux-x86_64-rhel70-3.2.6 /usr/local/mongodb
‘/usr/local/mongodb’ -> ‘/usr/local/mongodb-linux-x86_64-rhel70-3.2.6’
#配置环境变量
# cat /etc/profile.d/mongodb.sh
#set for mongodb
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
# source /etc/profile.d/mongodb.sh
# mongod --version
db version v3.2.6
git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
#创建shard11.conf文件
# cat /usr/local/mongodb/shard11.conf
dbpath=/mongodb/data/shard11
logpath=/mongodb/log/shard11.log
pidfilepath=/mongodb/pid/shard11.pid
directoryperdb=true
logappend=true
replSet=shard1
port=27017
fork=true
shardsvr=true
journal=true
#创建shard21.conf文件
# cat /usr/local/mongodb/shard21.conf
dbpath=/mongodb/data/shard21
logpath=/mongodb/log/shard21.log
pidfilepath=/mongodb/pid/shard21.pid
directoryperdb=true
logappend=true
replSet=shard2
port=27018
fork=true
shardsvr=true
journal=true
#创建shard31.conf文件
# cat /usr/local/mongodb/shard31.conf
dbpath=/mongodb/data/shard31
logpath=/mongodb/log/shard31.log
pidfilepath=/mongodb/pid/shard31.pid
directoryperdb=true
logappend=true
replSet=shard3
port=27019
fork=true
shardsvr=true
journal=true
#创建相关目录
# mkdir -p /mongodb/{data,log,pid}
# mkdir -p /mongodb/data/{shard11,shard21,shard31}
# ll /mongodb/
total 0
drwxr-xr-x 2 root root 6 May8 16:20 data
drwxr-xr-x 2 root root 6 May8 16:20 log
drwxr-xr-x 2 root root 6 May8 16:20 pid
# ll /mongodb/data/
total 0
drwxr-xr-x 2 root root 6 May8 16:28 shard11
drwxr-xr-x 2 root root 6 May8 16:29 shard21
drwxr-xr-x 2 root root 6 May8 16:29 shard31
#编写shard11启动脚本
# cat /etc/init.d/mongo27017
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard11.conf
}
stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard11.conf --shutdown
echo "mongodb is stoped"
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
stop
start;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
# chmod +x /etc/init.d/mongo27017
#启动shard11实例,即27017端口
# netstat -tunlp |grep mongo |grep -v grep
# /etc/init.d/mongo27017 start
about to fork child process, waiting until server is ready for connections.
forked process: 11860
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11860/mongod
#编写shard21启动脚本
# cat /etc/init.d/mongo27018
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard21.conf
}
stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard21.conf --shutdown
echo "mongodb is stoped"
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
stop
start;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
#启动shard21实例,即27018端口
# netstat -tunlp |grep mongo |grep -v grep
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11860/mongod
# /etc/init.d/mongo27018 start
about to fork child process, waiting until server is ready for connections.
forked process: 11932
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11860/mongod
tcp 0 0 0.0.0.0:27018 0.0.0.0:* LISTEN 11932/mongod
#编写shard31启动脚本
# cat /etc/init.d/mongo27019
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard31.conf
}
stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard31.conf --shutdown
echo "mongodb is stoped"
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
stop
start;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
#启动shard31实例,即27019端口
# netstat -tunlp |grep mongo |grep -v grep
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11860/mongod
tcp 0 0 0.0.0.0:27018 0.0.0.0:* LISTEN 11932/mongod
# /etc/init.d/mongo27019 start
about to fork child process, waiting until server is ready for connections.
forked process: 11967
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11860/mongod
tcp 0 0 0.0.0.0:27018 0.0.0.0:* LISTEN 11932/mongod
tcp 0 0 0.0.0.0:27019 0.0.0.0:* LISTEN 11967/mongod
#检查mongod02的状态
# netstat -tunlp |grep mongo
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11427/mongod
tcp 0 0 0.0.0.0:27018 0.0.0.0:* LISTEN 11451/mongod
tcp 0 0 0.0.0.0:27019 0.0.0.0:* LISTEN 11475/mongod
#检查mongod03的状态
# netstat -tunlp |grep mongo
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11425/mongod
tcp 0 0 0.0.0.0:27018 0.0.0.0:* LISTEN 11449/mongod
tcp 0 0 0.0.0.0:27019 0.0.0.0:* LISTEN 11473/mongod
页:
[1]