Centos7.5部署mongodb集群

基础环境介绍

环境中采用的是两个虚拟机部署,对应信息如下

	主节点		:ipaddr: 192.168.200.101		hostname: mongo-master
备节点&仲裁节点	:ipaddr:192.168.200.102			hostname:mongo-node

基础环境准备

master-configure
[root@localhost ~]# hostnamectl set-hostname mongo-master && bash				//设置主机名
[root@mongo-master ~]# hostname --all-ip-address								//查看本机IP地址
192.168.200.101 
[root@mongo-master ~]# systemctl stop firewalld									//关闭firewall防火墙
[root@mongo-master ~]# 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@mongo-master ~]# iptables -F
[root@mongo-master ~]# setenforce 0
setenforce: SELinux is disabled
[root@mongo-master ~]# ping -c 4 csdn.net
PING csdn.net (47.95.164.112) 56(84) bytes of data.
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=1 ttl=128 time=4.74 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=2 ttl=128 time=5.97 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=3 ttl=128 time=4.76 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=4 ttl=128 time=4.90 ms

--- csdn.net ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 4.741/5.096/5.979/0.518 ms

slave-configure
[root@localhost ~]# hostnamectl set-hostname mongo-node  && bash
[root@mongo-node ~]# systemctl stop firewalld
[root@mongo-node ~]# 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@mongo-node ~]# iptables -F
[root@mongo-node ~]# setenforce 0
setenforce: SELinux is disabled
[root@mongo-node ~]# ping -c 4 csdn.net
PING csdn.net (47.95.164.112) 56(84) bytes of data.
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=1 ttl=128 time=4.66 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=2 ttl=128 time=6.18 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=3 ttl=128 time=5.47 ms
64 bytes from 47.95.164.112 (47.95.164.112): icmp_seq=4 ttl=128 time=8.51 ms

--- csdn.net ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 4.662/6.209/8.513/1.435 ms

mongo环境部署

1.下载mongo软件包

[root@mongo-master ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.10.tgz

2.创建ssh-key秘钥【没有其他作用只是为了方便传包及配置文件】

[root@mongo-master ~]# ssh-keygen -t rsa									//生成秘钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zuXmZBo5/eDNgxQegMDIxiHCqFMeL9rHUYSgFCRDGSE root@mongo-master
The key's randomart image is:
+---[RSA 2048]----+
|EXB=.+..         |
|**B o o .        |
|o+ o .   .       |
|o o o     o      |
| + o .  S..o     |
|. . o  o =o      |
|   .    *.B.     |
|         X.=.    |
|        . o +.   |
+----[SHA256]-----+
[root@mongo-master ~]# ssh-copy-id 192.168.200.102				//将秘钥copy过去
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.102 (192.168.200.102)' can't be established.
ECDSA key fingerprint is SHA256:UaQUa6bWaxIBXBPc+2XSvvlDRjdj/TbpXOz7x2eJyWI.
ECDSA key fingerprint is MD5:b6:e5:99:6b:ea:e8:fe:29:ad:e3:4d:7f:6e:74:71:e3.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.200.102'"
and check to make sure that only the key(s) you wanted were added.
[root@mongo-master ~]# scp mongodb-linux-x86_64-rhel70-3.4.10.tgz 192.168.200.102:/root/
mongodb-linux-x86_64-rhel70-3.4.10.tgz                                                     100%   96MB  61.1MB/s   00:01    

3.mongodb安装部署

[root@mongo-master ~]# tar xf mongodb-linux-x86_64-rhel70-3.4.10.tgz 
[root@mongo-master ~]# mv mongodb-linux-x86_64-rhel70-3.4.10/ /usr/local/mongo-3.4.10
[root@mongo-master ~]# cd /usr/local/mongo-3.4.10/
[root@mongo-master mongo-3.4.10]# mkdir config						//创建配置文件目录
[root@mongo-master mongo-3.4.10]# vim config/mongo-master.conf
[root@mongo-master mongo-3.4.10]# cat config/mongo-master.conf 
port=27017
bind_ip=192.168.200.101
dbpath=/data/mongodb
logpath=/data/logs/mongodb/mongodb.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
pidfilepath=/var/run/mongodb/mongo.pid
directoryperdb=true
noprealloc=true
oplogSize=10000
#replSet=mslinux
配置文件讲解
port:指的是mongodb启动监听的端口
bind_ip:指的是监听地址
dbpath:数据目录存储位置
logpath:日志文件位置
logappend:以追加的方式记录日志
fork:以后台的方式运行
maxConns:最大连接数
storageEngine:设置mongodb存储引擎【MMAPv1 是mongodb 在3.2以前默认的存储引擎,在3.2 之后默认的存储引擎为WiredTiger,MMAPv1存储引擎基于内存映射文件,它擅长高容量的插入,读取和更新。】
pidfilepath:mongodb启动后pid文件路径
directorype
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值