- MongoDB 下载链接:
- centos7 镜像下载链接:
- 也可以在服务器上面:wget
1.创建基础目录(已经有的话 , 请跳过)
# 用来存储我们下载好的一些文件或者软件mkdir -p /home/service# 用来存储配置文件mkdir -p /home/config# 用来存储日志mkdir -p /home/logs# sh脚本mkdir -p /home/sh安装wget:yum install wget2. 下载解压mongo(复制全部 , 粘贴运行就好了)
# 没有wget 的话 , yum install wgetcd /home/servicewget tar -xzvf mongodb-linux-x86_64-rhel70-4.4.0.tgz -C /home/service/mv /home/service/mongodb-linux-x86_64-rhel70-4.4.0 /home/service/mongodb3. 编写mongo配置(复制全部 , 粘贴运行就好了)
mkdir -p /home/service/mongodb/myconfigln -s /home/service/mongodb/myconfig /home/config/mongodbcat <<'EOF'> /home/service/mongodb/myconfig/mongodb.confdbpath = /home/service/mongodb/data/dblogpath = /home/service/mongodb/data/logs/mongodb.logport = 27017# 测试下可以0.0.0.0,正式环境:127.0.0.1bind_ip=0.0.0.0fork = true#nohttpinterface = trueauth=trueEOF# 软链ln -s /home/service/mongodb/data/logs /home/logs/mongodb4. 设置mongo自启文件(复制全部 , 粘贴运行就好了)
mkdir -p /home/service/mongodb/data/dbmkdir -p /home/service/mongodb/data/logscat <<'EOF'> /home/service/mongodb/myconfig/mongodb.service[Unit]Description=mongodbAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/home/service/mongodb/bin/mongod --config /home/service/mongodb/myconfig/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/home/service/mongodb/bin/mongod --shutdown --config /home/service/mongodb/myconfig/mongodb.confPrivateTmp=true[Install]WantedBy=multi-user.targetEOFcp /home/service/mongodb/myconfig/mongodb.service /lib/systemd/system/mongodb.servicesystemctl enable mongodb.servicesystemctl start mongodb.serviceservice mongodb status5. 配置系统环境(复制全部 , 粘贴运行就好了)
cat <<'EOF'>> /etc/profileexport MONGODB_HOME=/home/service/mongodbexport PATH=$PATH:$MONGODB_HOME/binEOFsource /etc/profile6.创建MongoDB管理员
【centos7 安装 MongoDB (复制粘贴系列)】mongouse admin#创建mongo管理员 , 并且赋予权限db.createUser({ user: 'admin', pwd: 'mongoAdmin', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });#退出登录exit7. 防火墙开启27017端口(复制全部 , 粘贴运行就好了)
yum -y install firewalldsystemctl start firewalld.servicechkconfig --level 35 firewalld onfirewall-cmd --zone=public --add-port=27017/tcp --permanentfirewall-cmd --reloadfirewall-cmd --list-ports8. 测试访问

文章插图
推荐阅读
-
聊聊星座那些事|天真善良,福气满满,一生都是好命的四大生肖,12生肖:为人正直
-
大门|教你合理布置自家财位,家中摆了它财运越来越好
-
「宝宝洗澡,宝宝护理,如何给宝宝洗澡」宝宝洗澡小课堂 新手爸妈看过来
-
每日小情书:她也叫我嫂子,知道我们是什么关系?,十条段子:我叫她嫂子
-
[强生公司]强生CD38单抗皮下注射剂型获批!给药时间缩短至5分钟
-
【天天科技范|Find X2 Pro竹青版6月1日开售,治愈系色彩登场,OPPO】
-
-
小罗伊·琼斯|2020年7月26日,世界职业拳坛新闻资讯
-
-
[怒火娱乐]她也有责任,43岁的陈数自爆离婚原因:第一段婚姻走向离婚
-
#开黑新使者#打野刀可忽略,但这件装备必出!,寂然公布韩信新赛季最佳出装
-
代古龙|马竞神锋沦为大水货,欧冠对阵德甲球队8场0球,本赛季7场0球
-
-
绅士老司机|太原:麻辣拌店主刷快手,三年花了20万元……
-
「小龙女」看到Baby的小龙女造型后,才明白“冰清玉洁”,真是演不出来的
-
-
钱江晚报|从警10多年,他说从没遇过这样的事!面包车高速腾空跃起,护栏却“毫发无损”
-
-
-