您好,登錄后才能下訂單哦!
MongoDB官網下載安裝包 3.6.8版本 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.8.tgz 3.4.18版本 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.18.tgz 解壓 tar zxf mongodb-linux-x86_64-rhel62-3.4.18.tgz mv mongodb-linux-x86_64-rhel62-3.4.18 /usr/local/mongodb echo 'export PATH=$PATH:/usr/local/mongodb/bin'>> /etc/profile source /etc/profile groupadd mongo useradd -g mongo mongo mkdir -p /server/mongodb27017/data mkdir -p /server/mongodb27017/log chown -R mongo.mongo /server/mongodb27017/ chown -R mongo.mongo /usr/local/mongodb vim /server/mongodb27017/mongodb27017.cnf
配置文件
#SERVER fork = true port = 27017 quiet = true dbpath = /server/mongodb27017/data logpath = /server/mongodb27017/log/mongod.log logappend = true journal = true #auth = true #開啟認證 # <=3.4 nohttpinterface = true directoryperdb = true #SLOW_LOG profile = 1 slowms = 500 #RS replSet = rs01 oplogSize = 4096 # add for 3.4 # shardsvr = true #SCO #cinfigsvr = true #configdb = MSCHOST #USER #keyFile=/ #setParameter=enableLocalhostAuthBypass=1 storageEngine=wiredTiger wiredTigerCacheSizeGB=1 wiredTigerCollectionBlockCompressor=snappy #mongo_version=mongodb34
啟動
sudo -u mongo mongod -f /server/mongodb27017/mongodb27017.cnf
進入命令行
mongo 127.0.0.1:27017
敲命令報錯
"errmsg" : "not master and slaveOk=false",
初始化
rs.initiate({_id:'rs01',version:1,members:[{_id:0,host:'10.238.162.33:27017'}]}) ;
完成
安裝完成后進入MongoDB的shell命令行后出現了很多報警如下,雖然都是一些warning,不影響使用,但是感覺就像是一個人處于亞健康狀態,當數據庫壓力過大的時候這些warning有可能導致數據庫出現error。所以下面挨著每個解決一下。
告警1
** WARNING: You are running this process as the root user, which is not recommended.
解決:啟動MongoDB的時候使用普通用戶,而不用root用戶執行
sudo -u mongo mongod -f /server/mongodb27017/mongodb27017.cnf
告警2
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] 2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
解決
echo "never" >> /sys/kernel/mm/transparent_hugepage/enabled
echo "never" >> /sys/kernel/mm/transparent_hugepage/defrag
并添加到 /etc/rc.local
告警3
** WARNING: soft rlimits too low. rlimits set to 4096 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files. 解決 vim /etc/security/limits.conf mongo soft nofile 65535 mongo hard nofile 65535 mongo soft nproc 65535 mongo hard nproc 65535 mongo soft stack 1024 mongo hards tack 1024 vim /etc/security/limits.d/90-nproc.conf soft nproc 65535
告警4
WARNING: Access control is not enabled for the database. 2018-11-15T17:38:44.181+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. use admin db.createUser( { user: "root", //用戶名 pwd: "root", //密碼 roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //權限 } 在配置文件中添加 auth = true
依次解決后進入shell命令行,真的干凈!沒有任何告警信息,簡直是強迫癥患者福音 O(∩_∩)O哈哈~
再見 各位~
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。