一、安装源
配置yum源
1.备份原yum库文件并将新配置写入repo文件
mv /etc/yum.repos.d/ /etc/yum.repos.d-bak mkdir /etc/yum.repos.d echo -e "[kunpeng]\nname=CentOS-kunpeng - Base - mirrors.huaweicloud.com\nbaseurl=https://mirrors.huaweicloud.com/kunpeng/yum/el/7/aarch64/\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/CentOS-Base-kunpeng.repo
2.确认上一步操作写入成功
cat /etc/yum.repos.d/CentOS-Base-kunpeng.repo [kunpeng] name=CentOS-kunpeng - Base - mirrors.huaweicloud.com baseurl=https://mirrors.huaweicloud.com/kunpeng/yum/el/7/aarch64/ gpgcheck=0 enabled=1
二、安装RPM包
1.清除缓存
yum clean all
2.创建缓存
yum makecache
3.安装数据库rpm包
yum -y install mongo-4.0.12-1.el7.aarch64 mongodb-tools-4.0.6-1.aarch64
4.查看安装后的rpm包
rpm -qa | grep mongo mongo-4.0.12-1.el7.aarch64
三、创建数据目录和日志文件(我这里是启用的是多实例,根据自己需求来创建)
mkdir -p /usr/local/mongodb/data/ cd /usr/local/mongodb/data/ mkdir logs db0 db1 db2 cd /usr/local/mongodb/data/logs touch mongodb_0.log mongodb_1.log mongodb_2.log
四、创建配置文件(我这里是多实例的其一)
[root@localhost ~]# vim mongodb_0.conf dbpath =/usr/local/mongodb/data/db0 logpath =/usr/local/mongodb/data/logs/mongodb_0.log logappend = true noprealloc=true replSet = rs0 port = 28017 fork = true bind_ip=0.0.0.0 wiredTigerCacheSizeGB=1
五、启动mongodb
[root@localhost ~]# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/config/mongodb_0.conf 2021-07-15T00:01:12.398+0800 I CONTROL [main] note: noprealloc may hurt performance in many applications 2021-07-15T00:01:12.398+0800 I STORAGE [main] Max cache overflow file size custom option: 0 about to fork child process, waiting until server is ready for connections. forked process: 9302 child process started successfully, parent exiting
六、登录数据库(我这里是指定进入某个节点,单节点不用指定端口)
[root@localhost]# /usr/local/mongodb/bin/mongo --port 28017 MongoDB shell version v4.0.12-1.el7 connecting to: mongodb://127.0.0.1:28017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("f1d0b6b0-b250-42dc-8945-e4bcf579659b") } MongoDB server version: 4.0.12-1.el7 Server has startup warnings: 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] 2021-07-15T00:01:13.888+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. The locked memory size is 65536 bytes, it should be at least 1048576 bytes 2021-07-15T00:01:14.140+0800 I REPL [replexec-0] 2021-07-15T00:01:14.140+0800 I REPL [replexec-0] ** WARNING: This replica set uses arbiters, but readConcern:majority is enabled 2021-07-15T00:01:14.140+0800 I REPL [replexec-0] ** for this node. This is not a recommended configuration. Please see 2021-07-15T00:01:14.140+0800 I REPL [replexec-0] ** https://dochub.mongodb.org/core/psa-disable-rc-majority-4.0 2021-07-15T00:01:14.140+0800 I REPL [replexec-0] --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- rs0:PRIMARY> 查看当前存在的库 rs0:PRIMARY> show dbs admin 0.000GB config 0.000GB local 0.006GB 退出数据库 exit
注:这样在线安装可能bin目录下缺少二进制工具文件,如mongodump mongorestore等命令
官网下载对应的工具包解压替换bin目录即可