vi /etc/selinux/config
SELINUX=disabled
然後重啟 OS
1. 加入 MongoDB Repository
vi /etc/yum.repos.d/mongodb.repo
參考 https://www.mongodb.com/download-center?jmp=nav#community
OS 是 64-Bit 的話
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
2. 安裝 3.4.x:
yum install -y mongodb-org
(會自動安裝五個套件:
mongodb-org-3.4.x
mongodb-org-server
mongodb-org-shell
mongodb-org-tools
mongodb-org-mongos
)
3. 修改
vi /etc/mongod.conf
先將預設的 bind IP 127.0.0.1 修改為 0.0.0.0
vi /etc/security/limits.d/20-nproc.conf
尾巴加一行後存檔
mongod soft nproc 500000
4. 防火牆設定
systemctl stop firewalld
systemctl disable firewalld
或者是
firewall-cmd --permanent --zone=public --add-port=27017/tcp
firewall-cmd --reload
systemctl restart mongod
5. 啟動與查服務的狀態
systemctl enable mongod
systemctl start mongod
ps auxw | grep mongod
systemctl status mongod
如果無法執行,可以考慮兩個方向:
1. SELINUX=disabled
vi /etc/selinux/config
SELINUX=disabled
2. 如果 SELinux 是enforcing 模式,則
yum -y install policycoreutils-python
semanage port -a -t mongod_port_t -p tcp 27017
查 LOG
/var/log/mongodb/mongod.log
6. 最後參照官網教學 Disable Transparent Huge Pages ( Link )
vi /etc/init.d/disable-transparent-hugepages
填入以下腳本檔內容
#!/bin/bash ### BEGIN INIT INFO # Provides: disable-transparent-hugepages # Required-Start: $local_fs # Required-Stop: # X-Start-Before: mongod mongodb-mms-automation-agent # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Disable Linux transparent huge pages # Description: Disable Linux transparent huge pages, to improve # database performance. ### END INIT INFO case $1 in start) if [ -d /sys/kernel/mm/transparent_hugepage ]; then thp_path=/sys/kernel/mm/transparent_hugepage elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then thp_path=/sys/kernel/mm/redhat_transparent_hugepage else return 0 fi echo 'never' > ${thp_path}/enabled echo 'never' > ${thp_path}/defrag re='^[0-1]+$' if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]] then # RHEL 7 echo 0 > ${thp_path}/khugepaged/defrag else # RHEL 6 echo 'no' > ${thp_path}/khugepaged/defrag fi unset re unset thp_path ;; esac設定可執行權限
chmod 755 /etc/init.d/disable-transparent-hugepages
根據 OS 的不同,參考以下指令:
Distribution | Command |
---|---|
Ubuntu and Debian | sudo update-rc.d disable-transparent-hugepages defaults
|
SUSE | sudo insserv /etc/init.d/disable-transparent-hugepages
|
Red Hat, CentOS, Amazon Linux, and derivatives |
sudo chkconfig --add disable-transparent-hugepages
|