centos 7上mongodb单机版安装步骤
centos 7测试机器安装单机版mongodb,记录
1、下载解压
cd /usr/local/ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.13.tgz tar -zxvf mongodb-linux-x86_64-rhel70-4.4.13.tgz mv mongodb-linux-x86_64-rhel70-4.4.13 mongodb-4.4.13 cd mongodb-4.4.13 mkdir data mkdir logs touch mongodb.log mkdir conf touch mongodb.conf
2、mongodb配置文件
vi mongodb.conf
#数据库路径
dbpath=/usr/local/mongodb/data
#日志输出文件路径
logpath=/usr/local/mongodb/logs/mongodb.log
#错误日志采用追加模式
logappend=true
#启用日志文件,默认启用
journal=true
#这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet=true
#端口号 默认为27017
port=27017
#允许远程访问
bind_ip=0.0.0.0
#开启子进程
fork=true
#开启认证,必选先添加用户,先不开启(不用验证账号密码)
#auth=true
3、环境变量
vim /etc/profile export PATH=$PATH:/usr/local/mongodb-4.4.13/bin source /etc/profile
4、启动
/usr/local/mongodb-4.4.13/bin/mongod --config /usr/local/mongodb-4.4.13/conf/mongodb.conf &
5、创建用户和密码
mongo use admin db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]}) db.shutdownServer()
6、修改配置文件mongodb.conf
auth=true
#重启
/usr/local/mongodb-4.4.13/bin/mongod --config /usr/local/mongodb-4.4.13/conf/mongodb.conf &
7、登录
db.auth("root","123456");
8、创建其他数据库及用户
#testdb为database
use testdb
#创建用户 db.createUser( { user: "test", pwd: "123456", roles: [ { role: "readWrite", db: "testdb" } ]
} );
#登录
db.auth("test","123456");

浙公网安备 33010602011771号