- 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. 测试访问

文章插图
推荐阅读
-
「时评界评论」许卫兵:这名广州男子醉驾为啥“三进宫”
-
-
-
【游民星空】讲述后续优化《逆水寒》本周策划答疑,打击战场演员
-
-
『江瀚的视野』黄金能到1800美元?现在是买黄金的好时机吗?,高盛:赶快买黄金
-
财经锐眼|汽车业大变革:千亿市场诞生,二手车将大幅贬值,原创
-
UZI|Uzi看到后直呼退役早了?新神话装备“海妖杀手”,完美契合薇恩
-
怕老鼠的大脸猫|营养师:注意吃的时间和方法,每天吃蔬果还是缺维C
-
-
-
林郑月娥回应被美国制裁:并不向往到美国,看来可主动注销签证了
-
星座故事大咖带你玩|离婚后,女人要多长时间才能继续下一段感情?,原创
-
-
林妙可|有种长大成人叫林妙可!西服配黑色吊带裙,21岁少女感足,颜值不输闺蜜
-
「经济总量」长三角第二大城市大比拼,杭州、苏州和南京,未来谁能更胜一筹?
-
陆小曼|这家国产手机被称“非洲王”,一年净赚近18亿,崛起的何止华为
-
护发素和发膜的相同点和不同点 护发素和发膜的相同点和不同点有何区别
-
网友热议|大爷中921万迟迟不领 太热不想出门:网友直呼太凡尔赛
-