MongoDB安装包下载地址:https://www.mongodb.com/download-center
[root@localhost src]# tar -zxvf mongodb-linux-x86_64-rhel62-3.4.2.tgz [root@localhost src]# mv mongodb-linux-x86_64-rhel62-3.4.2 /usr/local/mongodb [root@localhost src]# cd /usr/local/mongodb [root@localhost src]# cp /usr/local/mongodb/bin/mongo /usr/local/bin/ [root@localhost src]# cp /usr/local/mongodb/bin/mongo /usr/bin/ [root@localhost mongodb]# mkdir data [root@localhost mongodb]# mkdir logs [root@localhost mongodb]# echo > logs/mongodb.log
[root@localhost mongodb]# vim /usr/local/mongodb/mongodb.conf #内容如下 dbpath=/usr/local/mongodb/data/ logpath=/usr/local/mongodb/logs/mongodb.log logappend=true bind_ip=192.168.1.159 port=27000 fork=true
[root@localhost ~]# vim /etc/init.d/mongod
其脚本内容如下:
#!/bin/sh # #chkconfig: 2345 80 90 #description: mongodb start() { /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb.conf } stop() { /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb.conf --shutdown } restart() { stop sleep 2 start } case “$1” in start) start ;; stop) stop ;; restart) restart ;; *) echo $“Usage: $0 {start|stop|restart}” exit 1 esac
[root@localhost mongodb]# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb.conf --rest
访问地址:http://192.168.1.159:28000/ ,MongoDB 的 Web 界面访问端口比服务的端口多1000