linux 虚拟机-静态IP地址配置第一部分:主机环境准备
linux123:
IP: 192.168.27.131
子网掩码:255.255.255.0
网关:192.168.27.2
linux122:
IP: 192.168.27.130
子网掩码:255.255.255.0
网关:192.168.27.2
linux121:
IP: 192.168.27.129
子网掩码:255.255.255.0
网关:192.168.27.2
一、静态IP配置
IPADDR=
NETMASK=
GATEWAY=
DNS=
1.查看IP网段
2.查看IP网关与子网掩码
3.配置IP地址,重启网络服务,ping 百度地址:
service network restart
ping www.baidu.com
二.修改主机名
- 使用hostname 查看主机名
2.查看 /etc目录下是否有 hostname文件
3.对比hostname的命令,查看主机名一样,修改这里的主机名可以生效,如果在/etc/sysconfig/下面没有 network目录的话,可以在/etc/目录下面查看是否有hostname这个文件,修改这里主机名,可以配置生效!(亲测,即使我在/etc/sysconfig/目录下新建文件network文件 ,配置hostname也没有用,哎!心塞!)
hostname 文件修改完保存之后,输入hostname命令查看修改后的主机名
为刚刚自定义的主机名,执行 reboot重启生效
三、配置hostname与IP映射
vi /etc/hosts
192.168.27.129 linux121
192.168.27.130 linux122
192.168.27.131 linux133
1.配置好ip 与主机名的映射之后,ping 自己的主机名可以ping通,说明映射配置成功,修改完配置文件之后,重启一下网络服务,让配置生效
2.也可以进行主机名的互ping
这里是linux122去ping去pinglinux121
四、关闭防火墙与selinux
1.关闭防火墙
systemctl status firewalld.service 查看firewall状态
systemctl stop firewalld.service 停⽌止firewall
systemctl disable firewalld.service 禁⽌止firewall开机启动
2.关闭selinux
vi /etc/selinux/config
五、三台机器免密登录
1.在所有主机上创建⽬目录并赋予权限
mkdir /root/.ssh chmod 700 /root/.ssh
2.在三台机器器执⾏行行以下命令,⽣生成公钥与私钥
cd ~ #进⼊入⽤用户⽬目录
ssh-keygen -t rsa -P ""
是⽣生成ssh密码的命令,-t 参数表示⽣生成算法,有rsa和dsa两种;-P表示使⽤用的密码,这里使用""空字符串,表示无密码。
3.追加密钥到authorized_keys文件中
cd ~/.ssh 进⼊入.ssh
cat id_rsa.pub >> authorized_keys
4.复制第一台的认证到其他两台机器
[root@linux121 .ssh]# scp authorized_keys linux122:/root/.ssh/
The authenticity of host ‘linux122 (192.168.27.130)’ can’t be established.
ECDSA key fingerprint is f7:4c:9b:36:6b:d6:51:ef:45:86:84:ef:1a:96:9b:17.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘linux122,192.168.27.130’ (ECDSA) to the list of known hosts.
root@linux122’s password:
authorized_keys 100% 395 0.4KB/s 00:00
[root@linux121 .ssh]# scp authorized_keys linux123:/root/.ssh/
The authenticity of host ‘linux123 (192.168.27.131)’ can’t be established.
ECDSA key fingerprint is f7:28:2b:3a:0b:11:f7:10:4b:a3:b9:79:fe:fd:fa:74.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added ‘linux123,192.168.27.131’ (ECDSA) to the list of known hosts.
root@linux123’s password:
authorized_keys 100% 395 0.4KB/s 00:00
[root@linux121 .ssh]#
密码传输过程中只使⽤一次,以后再使用ssh linux121或ssh linux123即不在需要密码,实现免密钥登录。
六、三台机器时钟同步
时间同步的⽅方式:在集群中找一台机器器,作为时间服务器器。
通过⽹网络连接外⽹网进⾏行行时钟同步,必须保证虚拟机连上外⽹网
ntpdate us.pool.ntp.org;
阿⾥里里云时钟同步服务器器
ntpdate ntp4.aliyun.com
集群中其他机器器与这台机器器定时的同步时间,⽐比如,每 隔⼗十分钟,同步⼀一次时间。
1.时间服务器配置(必须root⽤用户)
步骤一:确定是否安装了ntpd服务
如果没有安装,可以进行在线安装
yum -y install ntp
启动ntpd的服务
service ntpd start
设置ntpd的服务开机启动
chkconfig ntpd on第⼀一步:确定是否安装了了ntpd的服务
rpm -qa | grep ntpd
步骤二: 编辑/etc/ntp.conf
编辑第一台机器的/etc/ntp.conf
vim /etc/ntp.conf
在文件中添加如下内容
(取消注释)
restrict 192.168.80.0 mask 255.255.255.0 nomodify notrap
注释⼀一下四⾏行行内容
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
#server 3.centos.pool.ntp.org
去掉以下内容的注释,如果没有这两⾏行行注释,那就⾃自⼰己添加上
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
配置以下内容,保证BIOS与系统时间同步 vim /etc/sysconfig/ntpd
添加⼀一⾏行行内容
SYNC_HWLOCK=yes
步骤三: 重新启动ntpd
service ntpd restart:重启服务
chkconfig ntpd on:设置开机启动
2.其他机器设置
注意:
如果客户机没有ntpdate,可以下载ntpdate.tar.gz到/usr/sbin/目录,然后解压:
wget http://blog.s135.com/attachment/200708/ntdate.tar.gz
cd /usr/sbin/
tar zxvf ntpdate.tar.gz
-bash: wget: 未找到命令
yum -y install wget
之前我这里时间没有同步,因为客户机没有安装ntp服务,导致时间同步失败
这里两台客户机都要装ntp服务
yum -y install ntp
步骤一:在其他机器配置10分钟与时间服务器同步一次
crontab -e
编写脚本
另外两台机器器与192.168.80.121进⾏行行时钟同步
*/10 * * * * /usr/sbin/ntpdate 192.168.80.121
步骤二:修改任意机器时间
date -s “2020-06-20 11:11:11”
步骤三:十分钟后查看是否与时间服务器同步
date
七、三台机器安装jdk
1.上传jdk并解压
所有软件的安装路路径
mkdir -p /opt/lagou/servers
所有软件压缩包的存放路路径
mkdir -p /opt/lagou/software
上传jdk到/opt/lagou/software路路径下去,并解压
tar -zxvf jdk-8u141-linux-x64.tar.gz -C …/servers/
2.配置环境变量
3.配置文件生效
source /etc/profile
4.方便以后上转文件,安装rz命令
yum -y install lrzsz rz
注意:MobaXterm不能安装rz命令
xshell 和 secureCRT都可以



