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

文章插图
推荐阅读
-
小李透王者|不是无尽战刃,而是少有人出的2230,能让铠皇成神的
-
沸腾人生|《沸腾人生》中三个“活得通透”的人,他们值得拥有幸福
-
这种植物原产于南美,随进口粮食偷偷进入我国,目前已泛滥成灾
-
程璐|调侃自己成了一个被迫独立的男性,程璐节目中呼唤思文复婚
-
爱奇艺|大厂女员工遭侵犯接连曝光爱奇艺发全员信:抵制职场潜规则
-
-
吴学民|减持!菲利华:公司实际控制人、董事减持约289万股
-
「嘉兴」背靠上海,连苏州,临杭州,长三角这座城市一直低调发
-
#旅行签证旅行社有能力把我的美国签证吊销吗真的觉得办签证别托旅行社 太坑了
-
DNF心情屋|DNF:武器附魔发生变化!希洛克新卡排面兼伤害,超越15属强
-
卤肉的正宗做法、卤肉做法流程、卤肉的做法视频,卤肉怎么做好吃卤肉的家常做法大全-
-
-
-
朱元璋为什么只封刘伯温为伯爵?明朝开国功臣为什么没有刘伯温
-
-
-
ZAKER|赚了420亿身家,中国第一位上榜的女首富:靠做“收破烂”生意
-
[安徽]中国一小镇, 安徽和江苏各占一半, 买早餐要跨省! 两边经
-
-
北晚新视觉网|新冠疫情致美国餐饮业损失逾两千亿美元!两万多家餐厅停业