Manually uploading
Mongodb-Centos7
Preparations before installation
Download: https: //www.mongodb.org/dl/linux
Environment Description: Download
a virtual machine system information: CentOS7 X86_64 bit;
2 software and version: mongodb-linux-x86_64-3.6.3.tgz; Xshell tools
MongoDB provides a 64-bit release version of linux each installation package, you can official website to download the installation package, the following address: MongoDB official website, enter the official website, as shown below:
Click Download, the download page:
Select the version: Linux 64-bit legacy x64, click on the DOWNLOAD, click Download. Save locally.
Installation
start CentOS7, xshell connected to CentOS7, and upload mongodb-linux-x86_64-3.6.3.tgz CentOS7 to the / usr / local, particularly filezilla upload tool. After the upload list as shown below:
解压缩:tar zxvf mongodb-linux-x86_64-3.6.3.tgz
重命名: mv mongodb-linux-x86_64-3.6.3 mongodb
删除: rm -rf mongodb-linux-x86_64-3.6.3.tgz
After decompression mongodb then moved to / usr / local file in the following figure :
Mongodb then move to the / usr / local
mv mongodb /usr/local
Mongodb into the directory, create a directory data, logs and log file directories
cd mongodb && mkdir data logs && touch /usr/local/mongodb/logs/log && mkdir conf && cd conf && touch mongo.conf && vim mongo.conf
touch conf/mongo.conf
Under enter / usr / local / mongodb / bin directory, start the service mongodb
Option 1: Start configuration, the following configuration is written mongo.conf
# 配置文件
# 数据指定位置
dbpath = /usr/local/mongodb/data
# 日志指定位置
logpath = /usr/local/mongodb/logs/log
# 每个数据库将被保存在一个单独的目录
directoryperdb = false
# 日志追加形式写入
logappend = true
port = 27017
# 守护进程启动
fork = true
# 指定可连接的主机
bind_ip = 0.0.0.0
# 启动验证 [配置完验证用户后启用]
# auth = false
同时修改/etc/mongod.conf文件,对其进行修改,mongodb安装好后开机自启会加载
logpth dbpath bindip
之后重启
Boot from Kai Script
vim /etc/init.d/mongodb
script
#!/bin/sh
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongo.conf
}
stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongo.conf --shutdown
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
Become effective
cd /etc/init.d
chkconfig --add mongodb
chmod +x mongodb
chkconfig mongodb on
start up
mongod -f /usr/local/mongodb/conf/mongo.conf
Option 2: Start up
cd bin/ && ./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/log --logappend --bind_ip=0.0.0.0 --port=27017 --fork
其中的--bind_ip=0.0.0.0是为了开启远程客户端连接
Start the client, enter under / usr / local / mongodb / bin directory
./mongo
Solve WARNING MongoDB log
1. Run the installation is complete mongodb warning reads as follows:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
Warnings:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
1. Cause self-examination - Solution:
# 在系统 /etc/rc.local 设置 transparent_hugepage 为 never
[root@server_node01#>> /data/db]#cat /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
2. Add executable permissions of the file:
chmod +x /etc/rc.d/rc.local
3. Restart the system:
reboot
WARNING II:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
Set to allow access to the address mongodb of --bind_ip:
# 配置文件 添加 --bind_ip 指定可连接的主机
# 数据指定位置
dbpath = /data
# 日志指定位置
logpath = /data/db/logs/log
# 每个数据库将被保存在一个单独的目录
directoryperdb = true
# 日志追加形式写入
logappend = true
port = 27017
# 守护进程启动
fork = true
# 指定可连接的主机
bind_ip = 0.0.0.0
# 启动验证 [配置完验证用户后启用]
# auth = true
或者以这种格式启动
./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/log --logappend --bind_ip=0.0.0.0 --port=27017 --fork
Warning three:
WARNING: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted.
= True set a password to access auth:
1. Log mongo set the admin password
[root@server_node01#>> /usr/local/mongodb]#mongo
> use admin
> db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})
2. Open the configuration file auth certification
# 数据指定位置
dbpath = /data/db
# 日志指定位置
logpath = /data/db/logs/mongodb.log
# 每个数据库将被保存在一个单独的目录
directoryperdb = true
# 日志追加形式写入
logappend = true
port = 27017
# 守护进程启动
fork = true
# 指定可连接的主机
bind_ip = 0.0.0.0
# 启动验证 [配置完验证用户后启用]
auth = false
Restart mongodb Service
[root@server_node01#>> /data/db]#mongod --shutdown
[root@server_node01#>> /data/db]#mongod -f /usr/local/mongodb/conf/mongod.conf
log in:
[root@server_node01#>> /data/db]#mongo 127.0.0.1:27017/admin -u root -p
WARNING four: Do not start the MongoDB service user with root
2019-01-17T16:13:10.778+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.