centos7.5下mongodb安装和配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenchenm/article/details/84166901

1、下载安装包

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.4.tgz

2、解压

tar -zxvf mongodb-linux-x86_64-rhel70-4.0.4.tgz

3、移动到指定位置(位置放到你想放的文件夹)

mv mongodb-linux-x86_64-rhel70-4.0.4 /opt/mongodb

4、在/opt/mongodb/mongodb下创建文件夹

mkdir -p /data/db
mkdir  /logs

5、在/opt/mongodb/bin下新建配置

vi mongodb.conf

logpath = /opt/mongodb/logs/mongodb.log #日志文件存放目录
port = 27017  #端口
fork = true  #以守护程序的方式启用,即在后台运行
auth=true #登录mongodb 是否需要认证(可在之后创建登录用户和密码)
bind_ip=0.0.0.0

6、环境变量配置

export MONGODB_HOME=/usr/local/mongodb

export PATH=$PATH:$MONGODB_HOME/bin

保存退出

重启系统配置 source /etc/profile

7、启动

在/usr/local/mongodb/bin下

mongod -f mongodb.conf 或 ./mongod -f mongodb.conf

8、关闭

mongod -f ./mongodb.conf --shutdown  或./mongod -f ./mongodb.conf --shutdown

9、开启端口

firewall-cmd --zone=public --add-port=27017/tcp --permanent
查看端口
firewall-cmd --permanent --query-port=27017/tcp
重启防火墙

systemctl restart firewalld

10、创建用户


 创建用户管理员:
   use admin
   db.createUser({user:"root",pwd:"root123456",roles:["userAdminAnyDatabase"]})
   db.auth('root','root123456')
 以用户管理员身份登录,并切换数据库,创建数据库用户:
   切换到test数据库
   use test
   创建用户名、密码、角色
   db.createUser({user:"username",pwd:"@user123456*",roles:[{role:"readWrite",db:"securitydata"}]})
   设置mongodb配置中的auth为true(/etc/mongod.conf):
   security:
     authorization: enabled
   验证mongodb数据库权限。
   db.auth('user','@user123456*')

猜你喜欢

转载自blog.csdn.net/chenchenm/article/details/84166901