版本: mongodb-org-server-4.2.1-1.el7.x86_64
OS : CentOS Linux release 7.7.1908 (Core)
一、系统基础配置
1.基础软件安装
[root@localhost yum.repos.d]# yum install ntp vim wget net-tools curl -y
2.selinux及firewall的配置
[root@localhost yum.repos.d]# vim /etc/selinux/config
[root@localhost yum.repos.d]# grep 'SELINUX=' /etc/selinux/config
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@localhost yum.repos.d]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost yum.repos.d]# systemctl stop firewalld
[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# getenforce
Permissive
3.mongodb之yum源配置
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# cat mongodb.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
4.limits修改
[root@localhost yum.repos.d]# tail -n 3 /etc/security/limits.conf
mongod soft nofiles 64000
mongod soft nproc 64000
# End of file
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
[root@localhost yum.repos.d]# echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
5.ntp服务器的配置
[root@localhost yum.repos.d]# vim /etc/ntp
ntp/ ntp.conf
[root@localhost yum.repos.d]# vim /etc/ntp.conf
[root@localhost yum.repos.d]# grep '^server' /etc/ntp.conf
server ntp.aliyun.com
[root@localhost yum.repos.d]# ntpdate ntp.aliyun.com
27 Aug 09:19:37 ntpdate[1852]: step time server 203.107.6.88 offset -28799.187003 sec
[root@localhost yum.repos.d]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost yum.repos.d]# systemctl start ntpd
[root@localhost yum.repos.d]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-08-27 09:19:52 CST; 3s ago
Process: 1877 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 1878 (ntpd)
CGroup: /system.slice/ntpd.service
└─1878 /usr/sbin/ntpd -u ntp:ntp -g
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen and drop on 1 v6wildcard :: UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen normally on 2 lo 127.0.0.1 UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen normally on 3 ens33 192.168.43.120 UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen normally on 4 lo ::1 UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listen normally on 5 ens33 fe80::152c:8360:6fae:47dd UDP 123
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: Listening on routing socket on fd #22 for interface updates
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: 0.0.0.0 c016 06 restart
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Aug 27 09:19:52 localhost.localdomain ntpd[1878]: 0.0.0.0 c011 01 freq_not_set
[root@localhost yum.repos.d]#
二、MongoDB Server的安装配置
1.安装
[root@localhost yum.repos.d]# sudo yum install -y mongodb-org-4.2.1 mongodb-org-server-4.2.1 mongodb-org-shell-4.2.1 mongodb-org-mongos-4.2.1 mongodb-org-tools-4.2.1
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package mongodb-org-4.2.1-1.el7.x86_64 already installed and latest version
Package mongodb-org-server-4.2.1-1.el7.x86_64 already installed and latest version
Package mongodb-org-shell-4.2.1-1.el7.x86_64 already installed and latest version
Package mongodb-org-mongos-4.2.1-1.el7.x86_64 already installed and latest version
Package mongodb-org-tools-4.2.1-1.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost yum.repos.d]# rpm -qa | grep mongo
mongodb-org-tools-4.2.1-1.el7.x86_64
mongodb-org-shell-4.2.1-1.el7.x86_64
mongodb-org-server-4.2.1-1.el7.x86_64
mongodb-org-mongos-4.2.1-1.el7.x86_64
mongodb-org-4.2.1-1.el7.x86_64
[root@localhost yum.repos.d]#
2.启动数据库
[root@localhost yum.repos.d]# systemctl start mongod
[root@localhost yum.repos.d]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-08-27 09:32:19 CST; 16s ago
Docs: https://docs.mongodb.org/manual
Process: 1900 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 1896 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 1894 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 1892 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 1903 (mongod)
CGroup: /system.slice/mongod.service
└─1903 /usr/bin/mongod -f /etc/mongod.conf
Aug 27 09:32:18 localhost.localdomain systemd[1]: Starting MongoDB Database Server...
Aug 27 09:32:18 localhost.localdomain mongod[1900]: about to fork child process, waiting until server is ready for...ons.
Aug 27 09:32:18 localhost.localdomain mongod[1900]: forked process: 1903
Aug 27 09:32:19 localhost.localdomain systemd[1]: Started MongoDB Database Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost yum.repos.d]# systemctl enable mongod
[root@localhost yum.repos.d]# systemctl stop mongod
[root@localhost yum.repos.d]# systemctl restart mongod
[root@localhost yum.repos.d]# mongo
MongoDB shell version v4.2.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1509140c-3718-4a95-9864-a7ba5884d5a4") }
MongoDB server version: 4.2.1
Server has startup warnings:
2020-08-27T09:37:49.543+0800 I CONTROL [initandlisten]
2020-08-27T09:37:49.543+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-08-27T09:37:49.543+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-08-27T09:37:49.543+0800 I CONTROL [initandlisten]
---
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()
---
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
3.查看配置文件、进程状态及端口监听状态
[root@localhost yum.repos.d]# grep -v '^#' /etc/mongod.conf | grep -v '^$'
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
[root@localhost yum.repos.d]# ps -ef | grep mongo
mongod 2053 1 1 09:37 ? 00:00:06 /usr/bin/mongod -f /etc/mongod.conf
root 2111 1537 0 09:44 pts/0 00:00:00 grep --color=auto mongo
[root@localhost yum.repos.d]# netstat -anultp | grep mongo
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 2053/mongod
[root@localhost yum.repos.d]#