OpenEuler安装MongoDB并配置访问密码
1. 下载MongoDB、安装
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.18.tgz
tar zxvf mongodb-linux-x86_64-rhel80-4.4.18.tgz
移动到/home路径下
mv mongodb-linux-x86_64-rhel80-4.4.18 /home
cd /home
mv mongodb-linux-x86_64-rhel80-4.4.18 mongodb
2. 配置MongoDB
cd mongodb
mkdir -p data logs conf
cd logs
touch mongo.log
cd .. /conf
touch mongo.conf
编辑mongo配置文件 vim mongo.conf
dbpath=/home/mongodb/data
logpath=/home/mongodb/logs/mongo.log
logappend=true
journal=true
quiet=true
port=27017
bind_ip=0.0.0.0
fork=true
3. 防火墙开端口
firewall-cmd --add-port=27017/tcp --permanent
service firewalld restart
4. 配置mongo启动脚本
cd
vim startMongo.sh
/home/mongodb/bin/mongod --config /home/mongodb/conf/mongo.conf
设置开机自启 vim /etc/rc.d/rc.local
/home/mongodb/bin/mongod --config /home/mongodb/conf/mongo.conf
chmod +x /etc/rc.d/rc.local
报错处理
cd ../bin
./mongod
缺啥装啥 比如我的少
libcrypto.so.1.1 => not found
libssl.so.1.1 => not found
解决方法:
dnf -y install libcrypto.so.*
# mongo设置密码
cd /mongodb/bin
./mongo
use admin
db.createUser({user: 'root', pwd: 'password', roles: ['root']})
db.auth('root','password')
返回1代表对头了
vim /home/mongodb/conf/mongo.conf
auth = true # 是否开启校验用户,设置为true后数据库连接时需要输入用户名密码!!!!!!!!!!!!!
代码调试
xxx.db('mongodb://your name: your pwd@127.0.0.1:27017/Article');
喜欢请赞赏一下啦^_^