一、构建学习环境
1. 硬件要求
虚拟机:1G内存,20G硬盘,可上网
2. 软件要求
操作系统:CentOS 7.x / CentOS 8.x(区别在于CentOS 8.x 有两个YUM源)
3. 角色分配
角色 | 主机名 | IP |
---|---|---|
ansiblehost | student | 192.168.3.30 |
ansiblenode1 | node1 | 192.168.3.31 |
ansiblenode2 | node2 | 192.168.3.32 |
ansiblenode3 | node3 | 192.168.3.33 |
4. 部署环境步骤
(1)设置主机名
# 查看当前主机名
[root@root ~]# hostname
root
# 修改当前主机名为student
[root@root ~]# hostnamectl set-hostname student
# 注意:需要重启后生效,node{1..3}同理修改即可
[root@root ~]# reboot
(2)配置EPEL源
点击 阿里云镜像站 进行配置即可
(3)hosts解析
student主机上修改hosts文件,在最末尾加上机器的ip和hostname
[root@student ~]# vim /etc/hosts
192.168.3.30 student
192.168.3.31 node1
192.168.3.32 node2
192.168.3.33 node3
(4)student 以root 用户配置到所有机器免密钥
xshell 点击【工具】-【发送键输入到所有会话】
# 分发密钥
[root@student ~]# ssh-keygen -f ~/.ssh/id_rsa -P '' -q
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
[root@student ssh]# ssh-copy-id student
[root@student ssh]# for i in node{1..3}
> do
> ssh-copy-id $i
> done
Are you sure you want to continue connecting (yes/no)? yes
root@node1's password:
# 依次输入被管理主机的密码
测试:
[root@student ssh]