Centos下安裝MongoDB數據庫

1.解壓版安裝linux

獲取安裝包:mongodb

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.2.tgz

解壓:shell

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

重命名解壓的文件夾數據庫

[root@localhost mongodb]# mv mongodb-linux-x86_64-rhel70-3.6.2 mongdb

建立在mongodb下建立bin、conf、data、log分別存放可執行文件、配置文件、數據文件和日誌文件this

[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

將mongdb/bin目錄下的mongod和mongo命令複製到bin目錄下google

在conf下建立mongod.conf配置文件spa

bind_ip=0.0.0.0
port = 27017
dbpath = /usr/local/mongodb/data/
logpath = /usr/local/mongodb/log/mongod.log
fork = true

bind_ip:綁定的ip地址設計

port:mongodb使用的端口rest

dbpath和logpath分別指數據文件和日誌文件日誌

fork:表示後臺啓動mongo進程

進入bin目錄下,啓動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

輸出如上所示表示啓動成功

進入bin目錄,執行mongo鏈接mongodb數據庫

[root@localhost bin]# ./mongo 127.0.0.1:27017

輸出以下:

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
>

表示鏈接成功。

警告內容: 網上搜了一下,大概意思是

就是容許hugepage能夠動態分配,而不是系統啓動時預先分配,看上去對內存消耗很大的服務都不喜歡它。感受這是一個lazy loading的設計思想。

在/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
相關文章
相關標籤/搜索