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

文章插图
推荐阅读
-
-
行业互联网抱大腿?三大运营商选用欧洲巨头5G基站,爱立信5G订单数超华为?
-
体育乐鱼烽火|新赛季目标就是重返西甲,武磊:很高兴完成续约
-
梦见开车迷路了找不到回家的路 梦见开车迷路绕不出去
-
秦时丽人明月心|迪丽热巴《秦时丽人明月心》大结局这个穿帮镜头,太破坏气氛了
-
-
-
-
经济日报-中国经济网综合|张家明任北京市委秘书长 崔述强不再担任(图|简历)
-
【大众报业·海报新闻】2020年全国游泳冠军赛在青岛落幕 对标东京奥运成绩亮眼
-
-
#冷知识#DNF:本想强化碎换点材料,没想到武器上了16,看到职业玩家笑了
-
酒精和花露水可以杀螨虫吗 花露水和酒精混在一起能除螨虫吗
-
|气象台发布暴雨蓝色预警,全国13省市区有大到暴雨
-
集成灶十大品牌推荐 它到底有什么魅力深受众人喜爱?,这么多人都选择金牌厨柜
-
联想|从民族之光到美帝良心想,年薪1.5亿的杨元庆高呼:国家应该扶持
-
-
|《智爱2026》,人工智能走进现实家庭,带来科技与亲情不一样的思考
-
「小林读史」里面有多少水分?专家:当作笑话看就行,古代动辄十万百万大军
-