目录
1.更改主机名
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@master ~]#
2.主机名与IP地址映射
[root@master ~]# vi /etc/hosts
使用 vi /etc/hosts指令配置IP映射时,IP地址必须在VMware虚拟机网络IP地址范围内(图1-1所示 ),且主机名为刚才配置的主机名。如图2-2所示,在 /etc/hosts添加3行内容,后面两行内容为即将克隆的slave1和slave2主机。
图2-1 VM虚拟机网络IP地址范围界面
图2-2 主机名与IP映射
3.设置静态IP
[root@master ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
修改IP地址文件,设置静态IP时,通常需要配置或修改以下参数:
ONBOOT= yes 表示启动这块网卡
BOOTPROTO=staitc 表示静态路由协议,可以保持IP固定
IPADDR 表示虚拟机IP地址,需要与前面IP映射时的IP地址一致
GATEWAY 表示虚拟机网关,通常将IP地址最后一位变为2
NETMASK 表示虚拟机子网掩码,通常为255.255.255.0
DNS1 表示域名解析器,可采用Google的DNS服务器8.8.8.8
图3-1 设置静态IP界面
重启网络服务。
[root@master ~]# service network restart
Restarting network (via systemctl): [ OK ]
[root@master ~]#
4.关闭防火墙
关闭和停止并禁用开机启动防火墙。
[root@master ~]# systemctl stop firewalld.service
[root@master ~]# systemctl disable firewalld.service
5.免密登录
输入“ssh-keygen -t rsa”命令,并连续按四次回车键,并将密钥复制到master主机,实现master主机能够免密登录本机。
[root@master ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:yNG+twrrOgfyMiGEh6Yhzzi6BCx7QBiJ09yfNQMTwPw root@master
The key's randomart image is:
+---[RSA 2048]----+
|o+ +..+o |
|=.o + o+ |
|o+ o.o.o |
|Bo. .E+ |
|OB o S |
|Bo= . . |
|o+.+ .. . . |
|o.o o .o . . |
|.. o.=o ... |
+----[SHA256]-----+
[root@master ~]# ssh-copy-id master
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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
root@master's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'master'"
and check to make sure that only the key(s) you wanted were added.
[root@master ~]#