mongodb 4.2单机部署
时间:2021-07-01 10:21:17
帮助过:64人阅读
https://www.mongodb.com/download-center/community我这里下载的是mongodb-linux-x86_64-rhel70-4.2.9.tgz---------------------------------------安装部署---------------------------------------1.创建安装目录192.168.1.169:28001对应的安装目录[root@test services]# mkdir -p /usr/local/services[root@test services]# mkdir -p /home/middle/mongodb/data[root@test services]# mkdir -p /home/middle/mongodb/log[root@test services]# mkdir -p /home/middle/mongodb/key[root@test services]# mkdir -p /home/middle/mongodb/conf[root@test services]# mkdir -p /home/middle/mongodb/run2.安装数据库192.168.1.169:28001 安装[root@test]# cd /soft[root@test soft]# tar -xvf mongodb-linux-x86_64-rhel70-4.2.9.tgz[root@test soft]# mv mongodb-linux-x86_64-rhel70-4.2.9 /usr/local/services/mongodb3.产生秘钥验证在其中一个机器上创建秘钥文件,我这里是在192.168.1.169:29001[root@test key]# cd /home/middle/mongodb/key[root@test key]# openssl rand -base64 741 >>keyfile[root@test key]# chmod 700 keyfile4.生成日志文件192.168.1.169:28001[root@test key]#echo>/home/middle/mongodb/log/mongodb.log5.创建配置文件mongo.cnf##主节点的配置参数vi /home/middle/mongodb/conf/mongo.cnfport=28001fork=truedbpath=/home/middle/mongodb/datalogpath=/home/middle/mongodb/log/mongodb.logpidfilepath=/home/middle/mongodb/run/28001.pidlogappend=true##shardsvr=true ##创建副本集才需要##replSet=repltest ##创建副本集才需要bind_ip=192.168.1.169,127.0.0.1oplogSize=10000logRotate=reopen##auth=true这里keyFile和auth先注释,因为等部署完初始化完集群后再启用6.启动主节点启动:192.168.1.169:28001[root@test key]# /usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf7.创建管理员用户在主节点上(我这里是节点1)上创建管理员账号test[root@localhost bin]# /usr/local/services/mongodb/bin/mongo 192.168.1.169:28001use admindb.createUser({user:"yeemiao",pwd:"yeemiao123",roles:["root"]}); --创建用户db.auth("yeemiao","yeemiao123"); --设置用户登陆权限,密码一定要和创建用户时输入的密码相同show users; --查看创建的用户8.重启mongodb然后启用认证参数停掉mongodb/usr/local/services/mongodb/bin/mongo localhost:28001use admindb.auth("yeemiao","yeemiao123");db.shutdownServer()修改配置文件,将之前注释的两行,启用auth = true再次启动/usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf9.再次启动后创建普通账号,并写入记录[root@test key]#/usr/local/services/mongodb/bin/mongo 192.168.1.169:28001> use adminswitched to db admin> db.auth("yeemiao","yeemiao123");>use mgdb_zhibo>db.createUser({user:‘threedev‘,pwd:‘threedev123‘,roles:[{role:‘dbOwner‘,db:‘mgdb_zhibo‘}]})10.加入自动重启服务参考http://blog.chinaunix.net/uid-77311-id-5791282.html
-- The End --
mongodb 4.2单机部署
标签:use https logrotate blog 配置文件 download oplog font 管理