码迷,mamicode.com
首页 > 数据库 > 详细

二进制安装MongoDB

时间:2019-01-22 17:26:22      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ice   shell   dir   base   network   连接数   running   oda   adc   

1、下载mongodb

cd /usr/local/src/
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.5.tgz
tar xf mongodb-linux-x86_64-4.0.5.tgz
mv mongodb-linux-x86_64-4.0.5 /usr/local/
ln -s /usr/local/mongodb-linux-x86_64-4.0.5   /usr/local/mongodb

2、创建数据与日志存放目录

mkdir  /data/mongodata -p
mkdir  /data/logs/mongolog -p

3、环境变量设置

echo export PATH=$PATH:/usr/local/mongodb/bin >>/etc/profile
source  /etc/profile
#测试
[root@iZm5e68ouhl866li7184cnZ src]# mongo -version
MongoDB shell version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

4、创建配置文件mongodb.conf

mkdir  /usr/local/mongodb/conf
[root@iZm5e68ouhl866li7184cnZ src]# cat /usr/local/mongodb/conf/mongodb.conf 
#数据文件存放目录
dbpath = /data/mongodata
#日志文件存放目录
logpath = /data/logs/mongolog/mongodb.log
#端口
port = 27017
#以守护程序的方式启用,即在后台运行
fork = true   
#监听ip
bind_ip=0.0.0.0
#最大连接数
maxConns=65536
# pid文件
pidfilepath=/var/run/mongod.pid

5、配置启动文件

[root@iZm5e68ouhl866li7184cnZ src]# cat   /usr/lib/systemd/system/mongodb.service
[Unit]
Description=mongodb
After=network.target
 
[Service]
Type=forking
PIDFile=/var/run/mongod.pid
ExecStart=/root/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

6、启动

systemctl  start  mongodb.service 

[root@iZm5e68ouhl866li7184cnZ ~]# systemctl  status mongodb.service 
● mongodb.service - mongodb
   Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-01-22 16:05:40 CST; 5min ago
  Process: 4541 ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf (code=exited, status=0/SUCCESS)
 Main PID: 4543 (mongod)
   CGroup: /system.slice/mongodb.service
           └─4543 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf

Jan 22 16:05:39 iZm5e68ouhl866li7184cnZ systemd[1]: Starting mongodb...
Jan 22 16:05:39 iZm5e68ouhl866li7184cnZ mongod[4541]: about to fork child process, waiting until server is ready for connections.
Jan 22 16:05:39 iZm5e68ouhl866li7184cnZ mongod[4541]: forked process: 4543
Jan 22 16:05:40 iZm5e68ouhl866li7184cnZ mongod[4541]: child process started successfully, parent exiting
Jan 22 16:05:40 iZm5e68ouhl866li7184cnZ systemd[1]: Started mongodb.

#查看
[root@iZm5e68ouhl866li7184cnZ ~]# ss -lntp|grep mongod
LISTEN     0      128          *:27017                    *:*                   users:(("mongod",pid=4543,fd=11))

 

7、使用测试

[root@iZm5e68ouhl866li7184cnZ ~]# mongo  --host 127.0.0.1
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("06f9f2c7-17d1-456e-9e77-e53bf66b2adc") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2019-01-22T16:05:39.029+0800 I STORAGE  [initandlisten] 
2019-01-22T16:05:39.029+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-01-22T16:05:39.029+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] 
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] 
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] 
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is always.
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] **        We suggest setting it to never
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] 
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is always.
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] **        We suggest setting it to never
2019-01-22T16:05:40.172+0800 I CONTROL  [initandlisten] 
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

 

二进制安装MongoDB

标签:ice   shell   dir   base   network   连接数   running   oda   adc   

原文地址:https://www.cnblogs.com/zhangb8042/p/10304434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!