1.解压和复制mongodb至目录 /usr/local/mongodb2.mongodb配置
cd /opt/software
tar -zxvf mongodb-linux-x86_64-3.2.12.tgz
cp -r mongodb-linux-x86_64-3.2.12 /usr/local/mongodb
2.系统profile配置
vi /etc/profile
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:$MONGODB_HOME/bin
source /etc/profile
3.配置文件
在usr/local/mongodb/bin目录下创建vim.mongodb.conf文件
内容如下:
#----------------------------------------------------
#数据文件存放目录
dbpath = /usr/local/mongodb/data/db
#日志文件存放目录
logpath = /usr/local/mongodb/logs/mongodb.log
#端口
port = 27017
# 使用追加的方式写日志
logappend = true
# PID File 的完整路径,如果没有设置,则没有PID文件
pidfilepath=/usr/local/mongodb/mongod.pid
#每个数据库产生一个文件
directoryperdb=true
#以守护程序的方式启用,即在后台运行
fork = true
# 先关闭, 创建好用户在启动
##auth = true
#----------------------------------------------------
4.通过配置文件启动
./bin/mongod -f mongodb.conf
5.启动客户端测试:
./bin/mongo localhost:27017
命令:db.version()
6.查看进程杀死
netstat -anp|more
kill -9 PID
7.mongodb开机启动
cd /lib/systemd/system下创建 vim mongodb.service
内容如下:
#--------------------------------------------------------------
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod -shutdown -f /usr/local/mongodb/bin/mongodb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#--------------------------------------------------------------
8.设置mongodb.service权限
chmod 754 mongodb.service
9.系统mongodb.service操作命令
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service
9.设置管理员超级管理员
.bin/mongo
show dbs -- 看看有哪些数据库
use admin
db.createUser({user:"root",pwd:"123456",roles:["root","userAdminAnyDatabase"]}) -- 建立root并且分配角色
db.system.users.find() -- 查看系统的用户
10.设置普通用户
#使用某数据库
use xxx
db.createUser({user:"xxx",pwd:"xxx",roles:["readWrite","dbAdmin" ]})
最后都要认证一下
>db.auth("grs-wjh", "grs-wjh")
返回1代表成功,0代表失败。
>exit (退出)
db.auth("root","123456")
db.auth("root","123456")
问题:
查看Logs文件