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

文章插图
推荐阅读
-
-
-
香辣酸爽的朝鲜冷面,是朝鲜人民的自豪,从君王到百姓人人都喜欢
-
-
央广网|还手持铁棍砸碎货车车窗,嚣张!司机超车逼停货车
-
科技小时代|Pro 青空上手一个月:说说无法量化的手感,一加8
-
「单品」那些忍住不买最新款的人 是因为点进这篇省了好几千
-
-
「历史每日揭秘」2RS,见证了保时捷911的崛起,一起欣赏下!,保时捷GT
-
川西|川西大环线与川西小环线,哪条线路更好?其实第3条线路更美
-
-
-
天然气入户垃圾分类 三江源百万民众受益“清洁工程”
-
国策|有四个是我们的邻居,我国周边环境有多险恶?全球军力前6名中
-
-
-
『Aggro电竞』却能一套秒C位,见到这些英雄一定别上,王者荣耀:定位是战士
-
我的武侠|我的侠客:江湖风云席卷而来,这一次又将开启新的旅程!
-
[特朗普]5月9日!世卫组织宣布了病毒起源!特朗普想哭来不及了
-