以下配置一般需要切换为root用户下进行。
1、修改主机名
node1主机终端执行:
hostnamectl set-hostname node1
node2主机终端执行:
hostnamectl set-hostname node2
node3主机终端执行:
hostnamectl set-hostname node3
2、配置固定IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static # 将动态改为静态
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=d6d52208-4601-4686-9d57-a3400b2c662a
DEVICE=ens33
ONBOOT=yes # 将no改为yes
# 以下是需要新增的配置
IPADDR="192.168.77.101"
NETMASK="255.255.255.0"
GATEWAY="192.168.77.2"
DNS1="192.168.77.2"
然后每台主机对应修改即可,修改后需要重启网络生效:
systemctl restart network
3、主机名映射
win主机名映射文件位置:
“C:\Windows\System32\drivers\etc\hosts”
修改:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# 配置主机名映射
192.168.77.101 node1
192.168.77.102 node2
192.168.77.103 node3
Linux主机名映射文件位置:
vim /etc/hosts
修改:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# 配置主机名映射
192.168.77.101 node1
192.168.77.102 node2
192.168.77.103 node3
然后在每台主机对应修改即可
4、配置免密登录
每台主机执行命令:
ssh-keygen -t rsa -b 4096
一直回车即可
然后每台主机分别执行:
ssh-copy-id node1
ssh-copy-id node2
ssh-copy-id node3
执行过程输入密码确认即可。
5、配置java环境
官网下载:
jdk-8u381-linux-x64.tar
上传到主机后解压:
tar -zxvf jdk-8u381-linux-x64.tar
创建软连接jdk:
ln -s /usr/local/apps/jdk1.8.0_381 jdk
配置环境变量:
vim /etc/profile
在文件最下面添加环境变量:
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
# 配置java环境变量
export JAVA_HOME=/usr/local/apps/jdk
export PATH=$PATH:$JAVA_HOME/bin
修改后保存退出,更新环境变量,使刚配置的环境变量生效:
source /etc/profile
删除系统自带的java:
rm -f /usr/bin/java
把新安装的软连接过去:
ln -s /usr/local/apps/jdk/bin/java /usr/bin/java
查看是否安装配置成功:
查看java版本:java -version
查看javac版本:javac -version
正常看到版本即表示安装完成。
最后将解压后的jdk文件传送到其他主机:
scp -r jdk1.8.0_381 node2:`pwd`/
scp -r jdk1.8.0_381 node3:`pwd`/
然后重复上面的步骤即可。
6、关闭防火墙
生产环境不建议关闭防火墙
关闭防火墙:
systemctl stop firewalld
关闭防火墙开机自启动:
systemctl disable firewalld
7、关闭SElinux
vim /etc/sysconfig/selinux
修改为 disabled 千万不可写错,否则系统无法启动:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
重启系统:
init 6
8、修改时区和设置时间自动同步
查看时区是否准确:
timedatectl status
Local time: 一 2024-03-25 12:01:22 CST
Universal time: 一 2024-03-25 04:01:22 UTC
RTC time: 一 2024-03-25 04:01:22
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
看到Asia/Shanghai说明时区是准确的,无需修改
时间自动同步:
安装ntp:
yum install -y ntp
开启ntpd服务:
systemctl start ntpd
开启自启动服务:
systemctl enable ntpd
以上全部配置完毕,记得保存快照。