#1、配置文件查看
[root@localhost ~]# cat /usr/local/mongodb/conf/mongodb.conf
#数据文件存放目录
dbpath = /data/mongodata
#日志文件存放目录
logpath = /data/logs/mongolog/mongodb.log
#端口
port = 27017
#以守护程序的方式启用,即在后台运行
fork = true
#监听ip
bind_ip=127.0.0.1
#最大连接数
maxConns=65536
# pid文件
pidfilepath=/var/run/mongo/mongod.pid
#开启认证
#auth = true
#2、创建mongo账号
useradd -s /sbin/nologin -M mongo
#创建目录与授权
mkdir -p /data/mongodata
mkdir -p /data/logs/mongolog
mkdir -p /var/run/mongo
chown -R /data/mongodata
chown -R /data/logs/mongolog
chown -R /var/run/mongo
#service配置文件
[root@localhost ~]# cat /usr/lib/systemd/system/mongodb.service
[Unit]
Description=mongodb
After=network.target
[Service]
Type=forking
PIDFile=/var/run/mongo/mongod.pid
ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
User=mongo
Group=mongo
[Install]
WantedBy=multi-user.target