一、MongoDB单实例的部署
## 操作系统环境介绍
[root@node31 ~]# cat /etc/redhat-release;uname -r;uname -m;
CentOS Linux release 7.5.1804 (Core)
3.10.0-862.el7.x86_64
x86_64
[root@node31 ~]# firewall-cmd --state ## 查看firewall墙的状态
not running
[root@node31 ~]# free -h ## 查看当前系统可用的内容
total used free shared buff/cache available
Mem: 1.8G 113M 1.3G 17M 384M 1.5G
Swap: 2.0G 0B 2.0G
[root@node31 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 47G 1.6G 46G 4% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 18M 894M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sdb1 100G 54M 100G 1% /data ## 一会把软件安装在该目录挂载的磁盘下
/dev/sda1 1014M 142M 873M 14% /boot
tmpfs 183M 0 183M 0% /run/user/1000
[root@node31 ~]# ifconfig ens33|awk -F " " 'NR==2{print $2}' ## 外网IP地址
10.0.0.31
[root@node31 ~]# ifconfig ens34|awk -F " " 'NR==2{print $2}' ## 内网IP地址
172.16.1.31
软件及实例部署规划
/data/apps # 该目录下安装mongodb软件,安装后就是/data/apps/mongodb
/data/mongodb/6379 # 该目录下部署mongodb 27017实例
/data/mongodb/27017/conf # 存放mongodb 27017实例的配置文件
/data/mongodb/27017/data # 存放mongodb 27017实例的持久化数据
/data/mongodb/27017/logs # 存放mongodb 27017实例的日志文件
/data/mongodb/27017/run # 存放mongodb 27017实例的pid和socket文件
## MongoDB软件的安装
## 创建mongodb用户(需要设置密码,需要远程登录,需要有家目录,不要让其用户和密码过期)
[root@node31 ~]# chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow
[root@node31 ~]# useradd mongodb
[root@node31 ~]# echo "mongodb"|passwd --stdin mongodb
Changing password for user mongodb.
passwd: all authentication tokens updated successfully.
[root@node31 ~]# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow
## 创建软件安装的目录
[root@node31 ~]# mkdir /data/apps
[root@node31 ~]# ls -ld /data/apps/
drwxr-xr-x 3 root root 62 Feb 21 10:19 /data/apps/
## 上传软件包准备安装
[root@node31 ~]# mkdir tools
[root@node31 ~]# cd tools/
[root@node31 tools]# rz
[root@node31 tools]# ll mongodb-linux-x86_64-rhel70-4.2.3.tgz
-rw-r--r-- 1 root root 132183978 Feb 21 10:16 mongodb-linux-x86_64-rhel70-4.2.3.tgz
[root@node31 tools]# tar xf mongodb-linux-x86_64-rhel70-4.2.3.tgz -C /data/apps/
[root@node31 tools]# ln -sv /data/apps/mongodb-linux-x86_64-rhel70-4.2.3/ /data/apps/mongodb
'/data/apps/mongodb' -> '/data/apps/mongodb-linux-x86_64-rhel70-4.2.3/'
[root@node31 ~]# chown -R mongodb:mongodb /data/apps/mongodb/
[root@node31 ~]# ls -ld /data/apps/mongodb/
drwxr-xr-x 3 mongodb mongodb 135 Feb 21 10:18 /data/apps/mongodb/
## 配置环境变量
[root@node31 ~]# ls -ld /data/apps/mongodb/bin/
drwxr-xr-x 2 mongodb mongodb 231 Feb 21 10:18 /data/apps/mongodb/bin/
[root@node31 ~]# echo "PATH=/data/apps/mongodb/bin:$PATH" >>/etc/bashrc
[root@node31 ~]# source /etc/bashrc
[root@node31 ~]# which mongod
/data/apps/mongodb/bin/mongod
[root@node31 ~]# mongod --version
db version v4.2.3
git version: 6874650b362138df74be53d366bbefc321ea32d4
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
## mongodb 27017实例的部署