1. Unzip the installation
Get the installation package:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.2.tgz
Unzip:
tar zxvf mongodb-linux-x86_64-rhel70-3.6.2.tgz
[root@localhost mongodb]# ls
mongodb-linux-x86_64-rhel70-3.6.2 mongodb-linux-x86_64-rhel70-3.6.2.tgz
Rename the unzipped folder
[root@localhost mongodb]# mv mongodb-linux-x86_64-rhel70-3.6.2 mongdb
Create Create bin, conf, data, log under mongodb to store executable files, configuration files, data files and log files respectively
[root@localhost mongodb]# mkdir data
[root@localhost mongodb]# mkdir log
[root@localhost mongodb]# mkdir bin
[root@localhost mongodb]# mkdir conf
[root@localhost mongodb]# ls
bin conf data log mongodb mongodb-linux-x86_64-rhel70-3.6.2.tgz
Copy the mongod and mongo commands in the mongdb/bin directory to the bin directory
Create mongod.conf configuration file under conf
bind_ip=0.0.0.0
port = 27017
dbpath = /usr/local/mongodb/data/
logpath = /usr/local/mongodb/log/mongod.log
fork = true
bind_ip: bind ip address
port: port used by mongodb
dbpath and logpath refer to data files and log files respectively
fork: indicates that the mongo process is started in the background
Enter the bin directory and start mongodb
./mongod -f ../conf/mongod.conf
[root@localhost bin]# ./mongod -f ../conf/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20324
child process started successfully, parent exiting
The output shown above indicates that the startup was successful
Enter the bin directory and execute mongo to connect to the mongodb database
[root@localhost bin]# ./mongo 127.0.0.1:27017
The output is as follows:
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 3.6.2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten]
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten]
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-01-31T13:36:19.345+0800 I CONTROL [initandlisten]
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten]
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten]
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-01-31T13:36:19.346+0800 I CONTROL [initandlisten]
2018-01-31T13:39:20.634+0800 E - [main] Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: No such file or directory
>
Indicates that the connection is successful.
Warning content: Searched on the Internet, it probably means
It is to allow hugepage to be dynamically allocated, rather than pre-allocated at system startup. It seems that services that consume a lot of memory do not like it. It feels like a lazy loading design idea.
in the /etc/rc.local file as a permanent shutdown
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