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

文章插图
推荐阅读
-
-
-
【兵王故事】派出300架战机,空降部队参与行动,俄方坚决不会向西方认输
-
-
-
-
「娄娄娱乐」阿娇再谈照片门含泪表白阿Sa,Rain为和金泰熙的婚礼动用定期存款
-
天涯明月刀|天刀开服仅一个月,前十榜单出炉,对比上榜人员后发现,9成都有这个特点
-
「凌贞茂」还有4个细节,判断一个人开车技术好不好?老司机:别只看驾龄
-
相宁的|颜值超伊丽莎白二世,却因情场失意郁郁而终,她一出生就备受宠爱
-
营养师雪姐姐|小心胃“病”了,最好去查查,切莫“拖”成癌,饭后有4种表现
-
39岁余文乐官宣二胎得女,宝宝刚脱离危险期,六嫂高龄生产太辛苦
-
-
-
一家人在除夕晚上有没有比看春晚更有意义的事情可以做?
-
-
[白马入芦花6]都知道蜀国有五虎上将魏国却有五子良将
-
[神经内科孙庆利]又一起!多人复工后突发高热、呼吸困难
-
生活海风说联发科驳斥“华为借联发科迂回采购台积电芯片”的报道
-