本文主要介绍二进制安装。
安装环境:Linux xxx 4.19.90-25.41.v2101.ky10 .x86_64
一、从官网下载所需安装包
官网下载所需安装包,mongodb-linux-x86_64-rhel70-7.0.14.tgz
MongoDB:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-7.0.15.tgz
mongo-shell工具:https://downloads.mongodb.com/compass/mongosh-2.3.3-linux-x64.tgz
二、安装部署及设置MongoDB
1、上传安装包到服务器
解压缩安装包:
root@app-69-8 \~\]# tar -zxvf mongodb-linux-x86_64-rhel70-7.0.14.tgz -C /usr/local/ 创建软连接: \[root@app-69-8 \~\]# ln -s /usr/local/mongodb-linux-x86_64-rhel70-7.0.14/ /usr/local/mongodb ##### 2、添加全局环境变量 添加到环境变量,可以使用MongoDB的指令 \[root@app-69-8 \~\]# vim /etc/profile #mongodb export PATH=$PATH:/usr/local/mongodb/bin \[root@app-69-8 \~\]# source /etc/profile ##### 3、新增配置文件 \[root@app-69-8 \~\]# vim /usr/local/mongodb/mongodb.conf #注意配置文件格式,文件需创建新增。 ```bash [root@app-69-8 mongodb]# cat /usr/local/mongodb/mongodb.conf # mongod.conf # 设置系统用户UID systemLog: destination: file logAppend: true path: /data/mongodb/logs/mongod.log # 设置存储引擎 storage: dbPath: /data/mongodb/data # journal: # enabled: true # 设置网络接口 net: port: 27017 bindIp: 0.0.0.0 # 设置复制集 #replication: # replSetName: rs0 # 设置安全性 # 注意刚开始需要将该配置注释掉,部署完免密登录MongoDB,设置admin密码以后,打开注释, # 重启MongoDB,即可启用安全配置 security: authorization: enabled ``` ##### 4、添加系统服务 vim /usr/lib/systemd/system/mongod.service ```bash [Unit] Description=mongoDB After=network.target [Service] Type=simple Restart=on-failure ExecStart=/usr/local/mongodb/mongod --config=/usr/local/mongodb/mongodb.conf [Install] WantedBy=multi-user.target ``` ##### 5、启动服务,验证MongoDB 重载系统服务文件:systemctl daemon-reload 启动命令:systemctl start mongod 查看进程是否存在:ps -ef\|grep mongo 查看MongoDB运行状态。 **systemctl status mongod**  ##### 6、免密登录MongoDB,设置账密 ```bash [root@app-69-8 bin]# ./mongosh ---port 27017 --host 10.247.69.8 Current Mongosh Log ID: 672dc721dc75b4857ec1c18b Connecting to: mongodb://10.247.69.8:27017/?directConnection=true&appName=mongosh+2.3.3 Using MongoDB: 7.0.14 Using Mongosh: 2.3.3 For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/ test> test> use admin switched to db admin admin> show dbs MongoServerError[Unauthorized]: Command listDatabases requires authentication admin> admin> db.auth("admin","Sdsky@inspur123") { ok: 1 } admin> show dbs admin 132.00 KiB config 12.00 KiB local 40.00 KiB admin> exit ``` 最后打开"配置文件"中安全策略,重启MongoDB服务即可。 #### 注意: 启动MongoDB报错:./mongod: error while loading shared libraries: libcrypto.so.10: cannot open shared object file: No such file or directory; 此问题是缺少依赖包: 检查openssl-libs-\* 是否安装。**rpm -qa\|grep openssl-libs** 如果已安装,find / -name libcrypto.so.10 查找文件是否存在。 若存在只需建立软连接: ln -s /path/xxx/libcrypto.so.10 /lib/libcrypto.so.10; ln -s /path/xxx/libssl.so.10 /lib/libssl.so.10; ln -s /path/xxx/libcrypto.so.10 /lib64/libcrypto.so.10; ln -s /path/xxx/libssl.so.10 /lib64/libssl.so.10 ; 检查是否正确安装:  若不存在,拷贝其他相同Linux内核服务器上文件,放在/lib64 及/lib目录下即可。如下压缩包中附件,可以解决缺少依赖问题:[**libssl.so.10,libcrypto.so.10**](https://download.csdn.net/download/StudyHappiness/89978012 "libssl.so.10,libcrypto.so.10")。centos7、Kylin-Server V10-SP2 亲测可用。资源下载免费,免积分。如无法下载,可联系我。