mongo standard install
创建用户
1
[root@mongodb app]# useradd -s /sbin/nologin mongo
解压和安装
1
2
3[root@mongodb app]# tar xzf mongodb-linux-x86_64-rhel70-3.4.10.tgz
[root@mongodb app]# mv mongodb-linux-x86_64-rhel70-3.4.10 /mnt/app/mongo
[root@mongodb app]# chown -R mongo.mongo /mnt/app/mongo设置环境变量
1
2
3
4
5[root@mongodb app]# cat >/etc/profile.d/mongo.sh <<EOF
export MONGO_HOME=/mnt/app/mongo
export PATH=\${MONGO_HOME}/bin:\$PATH
EOF
[root@mongodb app]# source /etc/profile创建mongo配置文件目录
1
2[root@mongodb app]# mkdir -p /mnt/app/mongo/conf
[root@mongodb app]# chown -R mongo.mongo /mnt/app/mongo/conf创建mongo数据文件目录
1
2[root@mongodb app]# mkdir -p /mnt/data/mongo
[root@mongodb app]# chown -R mongo.mongo /mnt/data/mongo创建mongo日志目录
1
2[root@mongodb app]# mkdir -p /mnt/log/mongo
[root@mongodb app]# chown -R mongo.mongo /mnt/log/mongo设置mongo配置文件
1
2
3
4
5
6
7
8
9[root@mongodb app]# cat > /mnt/app/mongo/conf/mongo.conf <<EOF
dbpath=/mnt/data/mongo
logpath=/mnt/log/mongo/mongo.log
logappend=true
port=27017
fork=true
nohttpinterface=true
#auth=true
EOF设置mongo systemd文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18[root@mongodb app]# cat > /usr/lib/systemd/system/mongo.service <<EOF
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/mnt/app/mongo/bin/mongod --config /mnt/app/mongo/conf/mongo.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/mnt/app/mongo/bin/mongod --shutdown --config /mnt/app/mongo/conf/mongo.conf
PrivateTmp=true
User=mongo
Group=mongo
[Install]
WantedBy=multi-user.target
EOF
[root@mongodb app]# systemctl daemon-reload启动mongo
1
2[root@mongodb app]# systemctl start mongo
[root@mongodb app]# systemctl enable mongo验证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[root@mongodb ~]# mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2017-11-13T15:13:35.914+0800 I CONTROL [initandlisten]
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten]
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten]
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten]
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-11-13T15:13:35.915+0800 I CONTROL [initandlisten]
> show dbs
admin 0.000GB
local 0.000GB
> exit
byemongo内核优化
1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@mongodb ~]# echo never |tee /sys/kernel/mm/transparent_hugepage/enabled
[root@mongodb ~]# echo never |tee /sys/kernel/mm/transparent_hugepage/defrag
[root@mongodb ~]# systemctl stop mongo && systemctl start mongo
[root@mongodb ~]# cat >>/etc/rc.local <<EOF
### mongodb close hugepage
if test -f /sys/kernel/mm/transparent_hugepage/enabled;then
echo never |tee /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag;then
echo never |tee /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF