下载
下载地址 https://www.mongodb.com/download-center?jmp=nav#community
这里选用最新版的 Linux 64-bit legacy x64
mkdir /download
cd /download
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz
安装
建立不可登陆用户mongo
useradd -s /sbin/nologin mongo
解压缩
cd /download
tar zxvf mongodb-linux-x86_64-3.6.3.tgz
mv mongodb-linux-x86_64-3.6.3 /opt/mongodb-3.6.3
建立文件夹
mkdir -p /opt/mongodb-3.6.3/conf
mkdir -p /data/mongo-data/data
mkdir /data/mongo-data/logs
建立配置文件
vim /opt/mongodb-3.6.3/conf/mongo.conf
dbpath=/data/mongo-data/data
pidfilepath=/data/mongo-data/mongo.pid
logpath=/data/mongo-data/logs/mongo.log
logappend=true
port=27017
fork=true
#nohttpinterface=true
制作成服务
vim /usr/lib/systemd/system/mongo.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
User=mongo
Type=forking
PIDFile=/data/mongo-data/mongo.pid
ExecStart=/opt/mongodb-3.6.3/bin/mongod --config /opt/mongodb-3.6.3/conf/mongo.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
授权
chown mongo:mongo -R /opt/mongodb-3.6.3
chown mongo:mongo -R /data/mongo-data
启动与停止
首先 systemctl daemon-reload 重载所有修改过的配置文件
systemctl start mongo 启动
systemctl stop mongo 停止
systemctl restart mongo 重启
systemctl status mongo 状态