Compartir tecnología

Configuración del entorno ansible

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Configuración del entorno ansible

1. Composición

Rolenombre de la CPUPropiedad intelectual
terminales de controlservidor.ejemplo.com192.168.80.129
Nodo controlado 1nodo1.ejemplo.com192.168.80.130
Nodo controlado 2nodo2.ejemplo.com192.168.80.131

2. Establezca una dirección IP estática para cada host

  • Operación del lado del servidor
[root@server ~]# nmcli connection modify ens160 ipv4.addresses 192.168.80.129/24 ipv4.gateway 192.168.80.2 ipv4.dns 114.114.114.114 ipv4.method manual
[root@server ~]# nmcli connection reload
[root@server ~]# nmcli connection up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)
  • operación lateral nodo1
[root@node1 ~]# nmcli connection modify ens160 ipv4.addresses 192.168.80.130/24 ipv4.gateway 192.168.80.2 ipv4.dns 114.114.114.114 ipv4.method manual
[root@node1 ~]# nmcli connection reload
[root@node1 ~]# nmcli connection up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
  • operación lateral nodo2
[root@node2 ~]# nmcli connection modify ens160 ipv4.addresses 192.168.80.131/24 ipv4.gateway 192.168.80.2 ipv4.dns 114.114.114.114 ipv4.method manual
[root@node2 ~]# nmcli connection reload
[root@node2 ~]# nmcli connection up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)

3. Establezca el nombre de host para cada host

  • lado del servidor
[root@server ~]# hostnamectl set-hostname server.example.com
[root@server ~]# bash
[root@server ~]# reboot
[root@server ~]#
  • lado nodo1
[root@node1 ~]# hostnamectl set-hostname node1.example.com
[root@node1 ~]# bash
[root@node1 ~]# reboot
[root@node1 ~]#
  • lado nodo2
[root@node2 ~]# hostnamectl set-hostname node2.example.com
[root@node2 ~]# bash
[root@node2 ~]# reboot
[root@node2 ~]#

4. Establecer la asignación de host para cada host

  • lado del servidor
[root@server ~]# vim /etc/hosts
[root@server ~]# cat /etc/hosts
127.0.0.1         server.example.com
192.168.80.129    server.example.com
192.168.80.130    node1.example.com
192.168.80.131    node2.example.com
  • lado nodo1
[root@node1 ~]# vim /etc/hosts
[root@node1 ~]# cat /etc/hosts
127.0.0.1         node1.example.com
192.168.80.129    server.example.com
192.168.80.130    node1.example.com
192.168.80.131    node2.example.com
  • lado nodo2
[root@node2 ~]# vim /etc/hosts
[root@node2 ~]# cat /etc/hosts
127.0.0.1         node2.example.com
192.168.80.129    server.example.com
192.168.80.130    node1.example.com
192.168.80.131    node2.example.com

5. Inicie sesión en varios hosts sin contraseña a través de ssh

  • Operación del lado del servidor
[root@server ~]# ssh-keygen -t rsa   #之后一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:087zOwx6jrL5/TT1N9 CY fmPdvIAcn3MyEHPK0Wwhg [email protected]
The key's randomart image is:
 ---[RSA 3072]---- 
|         E       |
|            . .  |
|         . o = . |
|         . ...=  |
|        S .   oo |
|          . . oo.|
|         . oo..  |
|      ...o. *o =O|
|      o oooo O=oB|
 ----[SHA256]----- 
[root@server ~]# ssh-copy-id    node1.example.com   #server端向node1分发密钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node1.example.com (192.168.80.130)' can't be established.
ED25519 key fingerprint is SHA256:8/9KJPE9MmvW3tHXlBouijAhOshcqcqUX2ejOmS28tk.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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
[email protected]'s password:       #输入登录node1的密码 
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'node1.example.com'"
and check to make sure that only the key(s) you wanted were added.

[root@server ~]# ssh-copy-id node2.example.com      #server端向node2分发密钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node2.example.com (192.168.80.131)' can't be established.
ED25519 key fingerprint is SHA256:8/9KJPE9MmvW3tHXlBouijAhOshcqcqUX2ejOmS28tk.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: node1.example.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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
[email protected]'s password:    #输入登录node2的密码 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'node2.example.com'"
and check to make sure that only the key(s) you wanted were added.
  • prueba
[root@server ~]# ssh node1.example.com  #server端远程登录到node1端
Activate the web console with: systemctl enable --now cockpit.socket

Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Fri Jul  5 07:34:02 2024 from 192.168.80.129
[root@node1 ~]# exit   #已成功,注销
注销
Connection to node1.example.com closed.
[root@server ~]#
[root@server ~]# ssh node2.example.com   #server端远程登录到node2端
Activate the web console with: systemctl enable --now cockpit.socket

Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Fri Jul  5 07:34:21 2024 from 192.168.80.130
[root@node2 ~]# exit    #已成功,注销后回到server端
注销
Connection to node2.example.com closed.
[root@server ~]# 

6. Apague todo el software de seguridad del host.

  • lado del servidor
[root@server ~]# getenforce
Disabled
[root@server ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: