一 关闭防火墙
在通常的分布式架构中,各节点之间要进行通信或传输数据,而其中使用的所有端口我们并不完全了解,所以,直接将其关闭。
1.1 关闭防火墙
-
iptable
service iptables stop # 临时关闭防火墙 chkconfig iptables off # 永久关闭防火墙 service iptables status # 查看防火墙的状态
当查看防火墙状态时,打印的内容如下,则表示防火墙已关闭:
● iptable.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
-
firewalld
systemctl stop firewalld # 临时关闭防火墙 systemctl disable firewalld # 开机禁用 systemctl status firewalld # 查看状态
当查看防火墙状态时,打印的内容如下,则表示防火墙已关闭:
● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
1.2 关闭SELinux
安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。
-
查看SELinux状态
/usr/sbin/sestatus -v
或者使用
getenforce
查看状态。
若查询的结果不为 disabled,则需将其设置为 disabled。 -
临时关闭
setenforce 0
0:表示将 SELinux 成为 permissive 模式。
1:表示将 SELinux 成为 enforcing 模式。 -
永久关闭
将 /etc/selinux/config 文件内的 SELINUX 属性值变更为 disabled。SELINUX=disabled
可使用
reboot
重启机器使其生效。
二 变更hostname
2.1 CentOS 6
有如下两处需要修改,若只变更一处,将导致系统启动异常:
- /etc/hosts
- /etc/sysconfig/network
2.2 CentOS 7
# 使用这个命令会立即生效且重启也生效
hostnamectl set-hostname master1
# 验证修改结果
hostname
再在/etc/hosts
文件添加如下内容(具体的 IP 与 hostname 以实际为准):
158.222.189.89 master1
158.222.189.90 master2
158.222.187.156 slave01
158.222.188.243 slave02
注:每台机器往/etc/hosts
文件添加的内容保持一致即可。另,该文件的起始两行内容请保持不变,切勿变更任何内容。
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
三 时间同步
NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。
如下给出修改本地系统时间的命令,请按需选择执行:
date # 查看系统时间
hwclock --show # 查看硬件时间
timedatectl set-time 2018-08-27 # 更新系统年月日
timedatectl set-time 10:25:17 # 更新系统时分秒
timedatectl set-timezone Asia/Shanghai # 更新时区(亚洲-中国-上海)
timedatectl set-local-rtc 1 # 将硬件时间调整为与系统时钟一致
clock -w # 将日期写入CMOS
其中:同步系统与硬件时间的命令还可以用hwclock --systohc --localtime
3.1 服务端
重要:在开始配置前,请先配置并确定到指定的时区,再调整到指定的时间(相关的命令见上述)。
编辑 /etc/ntp.conf 文件,注释以 server 开头的配置,并添加内容:server 127.127.1.1 添加完成保存退出。关键内容如下:
server 127.127.1.0
fudge 127.127.1.0 stratum 10
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
重启 ntp 使配置生效。
systemctl restart ntpd
3.2 客户端
重要:在开始配置前,请先配置并确定到指定的时区(相关的命令见上述)。
编辑 /etc/ntp.conf 文件,注释以 server 开头的配置,并添加内容:server master1 添加完成保存退出。关键内容如下:
server master1 # ntp服务端主机名或IP
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
注:请确保已经成功配置了 hostname,且在 /etc/hosts 文件配置好了映射关系。
重启 ntp 让配置生效。
systemctl restart ntpd
一般情况下,会在几分钟内完成同步,可通过 ntpq -p
查看同步进度(左边出现 * 号表示同步成功)。