Centos下安装MongoDB数据库

原创
2018/02/03 15:11
阅读数 415

1.解压版安装

获取安装包:

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.2.tgz

解压:

tar zxvf mongodb-linux-x86_64-rhel70-3.6.2.tgz
[root@localhost mongodb]# ls
mongodb-linux-x86_64-rhel70-3.6.2  mongodb-linux-x86_64-rhel70-3.6.2.tgz

重命名解压的文件夹

[root@localhost mongodb]# mv mongodb-linux-x86_64-rhel70-3.6.2 mongdb

创建在mongodb下创建bin、conf、data、log分别存放可执行文件、配置文件、数据文件和日志文件

[root@localhost mongodb]# mkdir data
[root@localhost mongodb]# mkdir log
[root@localhost mongodb]# mkdir bin
[root@localhost mongodb]# mkdir conf
[root@localhost mongodb]# ls
bin  conf  data  log  mongodb  mongodb-linux-x86_64-rhel70-3.6.2.tgz

将mongdb/bin目录下的mongod和mongo命令复制到bin目录下

在conf下创建mongod.conf配置文件

bind_ip=0.0.0.0
port = 27017
dbpath = /usr/local/mongodb/data/
logpath = /usr/local/mongodb/log/mongod.log
fork = true

bind_ip:绑定的ip地址

port:mongodb使用的端口

dbpath和logpath分别指数据文件和日志文件

fork:表示后台启动mongo进程

进入bin目录下,启动mongodb

./mongod -f ../conf/mongod.conf
[root@localhost bin]# ./mongod -f ../conf/mongod.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 20324
child process started successfully, parent exiting

输出如上所示表示启动成功

进入bin目录,执行mongo连接mongodb数据库

[root@localhost bin]# ./mongo 127.0.0.1:27017

输出如下:

MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 3.6.2
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: 
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] 
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] 
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-01-31T13:36:19.345+0800 I CONTROL  [initandlisten] 
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] 
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] 
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-01-31T13:36:19.346+0800 I CONTROL  [initandlisten] 
2018-01-31T13:39:20.634+0800 E -        [main] Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: No such file or directory
>

表示连接成功。

警告内容: 网上搜了一下,大概意思是

就是允许hugepage可以动态分配,而不是系统启动时预先分配,看上去对内存消耗很大的服务都不喜欢它。感觉这是一个lazy loading的设计思想。

在/etc/rc.local文件中作为永久关闭

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then  
   echo never > /sys/kernel/mm/transparent_hugepage/enabled  
fi  
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then  
   echo never > /sys/kernel/mm/transparent_hugepage/defrag  
fi  

展开阅读全文
加载中

作者的其它热门文章

打赏
0
1 收藏
分享
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部
返回顶部
顶部