MongoDB--安装部署

Linux环境下安装MongoDB

说明:这里使用软件版本为:mongodb-linux-x86_64-rhel62-3.2.8.tgz

官网下载

本文所使用的安装包下载  提取码:zj43

具体步骤如下:

1)上传软件包到服务器并进行解压

[root@docker-02 ~]# tar xvzf mongodb-linux-x86_64-rhel62-3.2.8.tgz
[root@docker-02 ~]# mv mongodb-linux-x86_64-rhel62-3.2.8 /usr/local/mongodb

2)创建配置相关的目录及配置文件

[root@docker-02 ~]# cd /usr/local/mongodb/
[root@docker-02 mongodb]# ll
总用量 96
drwxr-xr-x 2 root root   224 3月  17 13:45 bin
-rw-r--r-- 1 root root 34520 7月  13 2016 GNU-AGPL-3.0
-rw-r--r-- 1 root root 16726 7月  13 2016 MPL-2
-rw-r--r-- 1 root root  1359 7月  13 2016 README
-rw-r--r-- 1 root root 35910 7月  13 2016 THIRD-PARTY-NOTICES
[root@docker-02 mongodb]# mkdir {data,conf,log}
[root@docker-02 mongodb]# ll
总用量 96
drwxr-xr-x 2 root root   224 3月  17 13:45 bin
drwxr-xr-x 2 root root     6 3月  17 13:48 conf
drwxr-xr-x 2 root root     6 3月  17 13:48 data
-rw-r--r-- 1 root root 34520 7月  13 2016 GNU-AGPL-3.0
drwxr-xr-x 2 root root     6 3月  17 13:48 log
-rw-r--r-- 1 root root 16726 7月  13 2016 MPL-2
-rw-r--r-- 1 root root  1359 7月  13 2016 README
-rw-r--r-- 1 root root 35910 7月  13 2016 THIRD-PARTY-NOTICES
[root@docker-02 mongodb]# vim conf/mongodb.conf

dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/log/mongodb.log
bind_ip=0.0.0.0
port=27017
logappend=1
fork=1

3)启动mongodb

[root@docker-02 mongodb]# cp bin/mongod /usr/bin/  #将命令copy到/usr/bin下,方便使用
[root@docker-02 mongodb]# mongod --config /usr/local/mongodb/conf/mongodb.conf  
about to fork child process, waiting until server is ready for connections.
forked process: 1413
child process started successfully, parent exiting
[root@docker-02 mongodb]# netstat -nlutp |grep 27017
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      1413/mongod 
[root@docker-02 mongodb]# echo "mongod --config /usr/local/mongodb/conf/mongodb.conf    #启动MongoDB" >> /etc/rc.local  #写入rc.local文件开机

 访问http://192.168.1.221:27017/ 如果在浏览器中出现下面一段英文说明成功了。

 

另外在打开一个ssh,启动mongodb的客户端,进入/usr/local/mongodb/bin目录下
     ./mongo 

[root@docker-02 mongodb]# /usr/local/mongodb/bin/mongo
MongoDB shell version: 3.2.8
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: 
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] 
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] 
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] 
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-03-17T13:51:27.628+0800 I CONTROL  [initandlisten] 
> dbdb
test
> 

 

posted @ 2020-03-17 14:05  星火撩原  阅读(151)  评论(0编辑  收藏  举报