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

文章插图
推荐阅读
-
怎么在公共场合说话不胆怯?孩子不敢在公共场合表现自己_1
-
-
-
-
【】热?热?热?热?热?!高温下,他们仍在坚守……
-
颜值拉胯、演技尴尬,《宣判》这个“混子”演员,真是尴尬的存在
-
-
券商|买一只股票一直持有,与经常换股,哪种方法更容易赚到钱?
-
-
-
科学家@人死后去了哪里?科学家给出大胆猜测,看完顿感有道理!
-
-
-
-
-
-
病人|为医之道 至精至微|江苏省中医院陈小宁:精、少、廉、效,于官窍脏腑间着手成春
-
“微博之夜”第六轮终于上干货了,刘诗诗、杨幂、杨紫等大咖官宣
-
-
小米手机安卓3款被称“神机”的手机,刻在大家心里,各方面优越!