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

文章插图
推荐阅读
-
【米莉时尚经|黑红绿搭配像60岁大妈,终于承认自己老了,44岁赵薇罕见青涩照】
-
-
-
末言雨|50岁的张嘉译为何改名?一字之差音同字不同,或许另有玄机
-
『申请』山东正在申请国家中心城市的地方,为何会让济南感到尴尬
-
明星穿搭记|老爹鞋成就本季穿搭经典,欧美潮人续写“时尚教科书”
-
电影生活|《怪你过分美丽》完美结局?高以翔回眸引爆泪点,但这些坑还没填
-
-
静思夜读@才会愿意和你聊这些话题,女人别不在意,男人爱你到骨子里了
-
德云社|德云社烧饼夫妻日常曝光!打翻妻子手机引争议,女方颜值胜女明星
-
「中国军魂」中国的回复充满底气,美国扬言3周击沉中国航母
-
糖果儿@命比纸薄,人吃三饭,寿命减半,说的都是啥?,人睡三觉
-
-
张丹峰|张丹峰主动牵老婆秀恩爱,十指紧扣好甜蜜,洪欣幸福满面状态好
-
「洪七公」4度诠释洪七公,3次出演《倚天屠龙记》,演员刘丹究竟演过多少金庸剧
-
安信证券|安信证券:农业行业表现亮眼 坚定看好后周期板块
-
-
-
-
科技鲜Phone死亡搁浅弩哥同款设计师,这次设计的衣服让电竞达人心动了