1.搭建环境所需服务器
服务器名称 | ip |
---|---|
node1 | 80.80.109.1 |
node2 | 80.80.109.2 |
node3 | 80.80.109.3 |
node4 | 80.80.109.4 |
注释:需要在/etc/hosts中增加对应的主机名称与ip的映射
2.防火墙(关闭)
2.1关闭防护墙命令:
2.1.1 centos6: service iptables stop
2.1.2 centos7: systemctl stop firewalld
2.2禁止开机启动命令:
2.2.1 centos6: chkconfig iptables off
2.2.2 centos7: systemctl disable firewalld
2.3防火墙状态查询:
2.3.1 centos6: service iptables status
2.3.2 centos7: systemctl status firewalld
3.关闭selinux
3.1selinux工作模式:
3.1.1 enforcing 强制模式
3.1.2 permissive 宽容模式
3.1.3 disable 关闭模式
3.2操作步骤:
3.2.1修改selinux的配置文件: vi /etc/selinux/config
3.2.2修改结果且保存如下:
4.免密登录配置(服务器间无密访问)
4.1生成公钥与私钥:ssh-keygen -t rsa
注释:在四台机器上执行此命令,生产公钥与私钥,执行该命令,按三次回车即可;生成秘钥目录为:/root/.ssh/id_rsa.
4.2拷贝公钥到同一台机器:ssh-copy-id 主机名(或)ip
注释: 可能遇到报错:/usr/bin/ssh-copy-id: ERROR: Host key verification failed.
解决办法:
4.2.1:编辑 /etc/ssh/ssh_config
4.2.2: 配置 Host*StrictHostKeyChecking no
4.3将第一台机器的公钥拷贝到其它机器上:scp /root/.ssh/authorized_keys (ip或主机名):/root/.ssh
4.4验证免密登录: 在任意一台机器上登录其它主机,命令:ssh (ip/主机名)
5.四台机器时钟同步(因为是内网所有我选择如下同步方式)
注释:分布式系统是有状态的,存储数据的记录时间必须保持一致;
5.1 检查ntp
执行:rpm -qa|grep ntp
能查询到如下信息代表已经安装:
ntpdate-4.2.6p5-29.el7.centos.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
ntp-4.2.6p5-29.el7.centos.x86_64
5.2 修改ntp配置文件
5.2.1执行:vim /etc/ntp.conf
restrict 80.80.109.0 mask 80.80.109.0 nomodify notrap
注释:表示授权 80.80.109.0-80.80.109.255 网段上的所有机器可以从这台机器上查询和同步时间(一定根据自己的网段设置)
5.2.2注释同步其它互联网上的时间配置
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
5.2.3 配置: server 127.127.1.0
fudge 127.127.1.0 stratum 10
注释:当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步。
5.3 修改 /etc/sysconfig/ntpd 文件
执行:vim /etc/sysconfig/ntpd
配置:SYNC_HWCLOCK=yes
注释:增加配置(让硬件时间与系统时间一起同步)
5.4 重新启动ntpd服务
5.4.1 service ntpd status(状态)
5.4.2 service ntpd start(启动)
5.4.3 service ntpd stop(停止)
5.4.4 chkconfig ntpd on(设置开机启动ntpd服务)
5.5 其它节点机器配置定时任务同步主机时间(必须root用户)
执行:使用crontab定时任务,5分钟同步一次主机时间 crontab -e
增加:*/5 * * * * /usr/sbin/ntpdate 主机ip
验证:5分钟后验证每台机器的时间是否一致;