二进制安装MongoDB

Posted 巽逸

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二进制安装MongoDB相关的知识,希望对你有一定的参考价值。

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
#测试
[[email protected] 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
[[email protected] 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、配置启动文件

[[email protected] 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 

[[email protected] ~]# 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.

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

 

7、使用测试

[[email protected] ~]# 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的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB 学习笔记二:安装MongoDB

MongoDB安装

mongodb二进制安装文档

mongodb二进制安装文档

mongodb二进制安装文档

二进制安装MongoDB