## 1. 安装介质 ``` mongodb-linux-x86_64-rhel70-4.0.13.tgz ``` ## 2. 安装步骤 ``` tar -zxvf mongodb-linux-x86_64-rhel70-4.0.13.tgz mv mongodb-linux-x86_64-rhel70-3.6.12 /usr/local/mongodb export PATH=$PATH:/usr/local/mongodb/bin ``` ## 3. 创建配置文件
常规配置
``` dbpath=/usr/local/mongodb/data logpath=/usr/local/mongodb/log/mongodb.log pidfilepath=/usr/local/mongodb/log/master.pid directoryperdb=true logappend=true bind_ip=0.0.0.0 port=27017 fork=true ```
yml格式备用配置
``` vi /etc/mongod.conf
processManagement: fork: true # fork and run in background pidFilePath: /usr/local/mongodb/run/mongod.pid # location of pidfile net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. storage: dbPath: /usr/local/mongodb/data journal: enabled: true systemLog: destination: file logAppend: true path: /usr/local/mongodb/log/mongod.log security: authorization: enabled ``` ## 4. 创建mongodb数据目录,日志目录 ``` mkdir -p /usr/local/mongodb/{data,log} ``` ## 5. 配置mongod开机启动 ``` vi /usr/lib/systemd/system/mongod.service
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target
[Service] Type=forking ExecStart=/usr/local/mongodb/bin/mongod -f /etc/mongod.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /etc/mongod.conf PrivateTmp=true
[Install] WantedBy=multi-user.target
## 设置开机启动 systemctl daemon-reload systemctl start mongod systemctl enable mongod ``` ## 6. 关闭linux THP ``` vi /etc/rc.d/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
chmod +x /etc/rc.d/rc.local |