mongodb部署
下载mongodb的版本,两点注意
- 根据业界规则,偶数为稳定版,如1.6.X,奇数为开发版,如1.7.X
- 32bit的mongodb最大只能存放2G的数据,64bit就没有限制
官网下载MongoDB的安装包, https://www.mongodb.com/try/download/community
# 下载mongodb
cd /usr/local/
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.13.tgz
mkdir -p /opt/mongodb/logs/
mkdir -p /opt/mongodb/data/db/
touch /opt/mongodb/logs/mongologs.log
tar -zxvf mongodb-linux-x86_64-rhel70-5.0.13.tgz
mv mongodb-linux-x86_64-rhel70-5.0.13 mongodb
mkdir /mongodb/conf
cat >>/usr/local/mongodb/conf/mongod.conf<<EOF
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,10.0.108.117 # Listen to local interface only, comment to listen on all interfaces.
security:
authorization: enabled
systemLog:
#mongodb发送所有日志输出的目标指定为文件
destination: file
path: "/opt/mongodb/logs/mongologs.log"
logAppend: true
storage:
#mongodb数据文件的存储目录
dbPath: "/opt/mongodb/data/db/"
journal:
enabled: true
processManagement:
#启用在后台运行mongod进程的守护进程模式
fork: true
EOF
配置环境变量
echo "export PATH=/usr/local/mongodb/bin:$PATH" >> /etc/profile
source /etc/profile
启动mongodb
mongod -f /usr/local/mongodb/conf/mongod.conf
[14:43:52 root@linuxmanager mongodb]#ps -ef |grep mongod
root 2124 29800 0 14:46 pts/1 00:00:00 grep --color=auto mongod
root 32140 1 0 14:03 ? 00:00:24 mongod -f /usr/local/mongodb/conf/mongod.conf
[14:46:31 root@linuxmanager mongodb]#netstat -lntup |grep mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 32140/mongod
防火墙配置
systemctl status firewalld
表示防火墙正在运行,需要添加mongodb的端口访问权限,mongodb默认端口是27017,添加放行mongodb端口
firewall-cmd --zone=public --add-port=27017/tcp --permanent
提示success表示添加成功,然后重新加载防火墙规则
firewall-cmd --reload
查看防火墙开放的端口
firewall-cmd --list-ports
yum方式安装
https://www.mongodb.com/docs/v5.0/tutorial/install-mongodb-on-red-hat/
cat >>/etc/yum.repos.d/mongodb-org-5.0.repo<<EOF
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
EOF
# 安装5.0最新版本
sudo yum install -y mongodb-org
# 启动mongodb
sudo systemctl start mongod
# 查看进程状态
sudo systemctl status mongod