Get the App
SLTechnology News&Howtos  ›  Servers  › 

Dhcp and ansible

Shulou Source: shulou.com Published: 2022-06-03 06:44:35 09月19日 Update

First, set up a DHCP service to provide users in the local area network with a 10.1.1.0 IP of 24 network segments, and the lease period is 48 hours by default.

1. Install the package:

Yum install-y dhcp*

two。 Configure the service:

[root@localhost dhcp] # vim dhcpd.conf option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org;default-lease-time 172800; ns2.example.org;default-lease-time 172800; local7;subnet 10.1.1.0 netmask 255.255.255.0 {range 10.1.1.100 10.1.1.200

3. Start the service and verify:

Systemctl start dhcpdhclient-d

Second, on the basis of the above experiments, DHCP relay is realized:

# enable route forwarding function vim / etc/sysctl.confnet.ipv4.ip-forward=1sysctl-p # start dhcp relay service dhcrelay dhcp_server_ip

In the actual use of relay service, it is basically unnecessary to use it. It is good to create another dhcp service for hosts in other networks. There is no need to use relays.

Build LNMP environment with the help of Ansible Playbook automation (with the help of yum)

1. Lab host:

Ansible host: 172.20.10.6webservers:172.20.10.3appservers:172.20.10.4

2.ansible host key-free authentication

(1)

[root@localhost playbooks] # ssh-keygen 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:LFUqZ3zNLyVoJzwgIo+LzGwHhd2YCnKh7kOl6IZQcZ4 root@localhostThe key's randomart image is:+--- [RSA 2048]-+ | * o *. . . | | ooo@ + o = + | | + oint.E. * B =. | | * +. | * o + + | | = B.. . S. . | | B. . . |. = | |. . | +-[SHA256]-+ |

(2)

[root@localhost] ssh-copy-id 172.20.10.3 [root@localhost] # ssh-copy-id 172.20.10.4

3.ansible profile

[webservers] 172.20.10.3[appservers] 172.20.10.4

4. Define a playbook script:

[root@localhost playbooks] # vim lnmp.yml-hosts: webservers remote_user: root tasks:-name: install nginx yum: name=nginx-name: config copy: src=/data/nginx.conf dest=/etc/nginx/nginx.conf tags: conf notify: restart nginx-name: start nginx service: name=nginx state=started enabled=yes handlers:-name: restart nginx service: name=nginx state=restarted- hosts: appservers remote_user: root tasks:- Name: install services yum: name= {{item}} with_items:-mariadb- mariadb-server-php- php-fpm-php-mysql-name: php-fpm config copy: src=/data/www.conf dest=/etc/php-fpm.d/www.conf notify: restart php-fpm-name: start php-fpm service: name=php-fpm state=started enabled=yes -name: start mysql service: name=mariadb state=started enabled=yes-name: config mysql shell: mysqladmin-uroot password "centos"-name: config php-index-file copy: src=/data/index.php dest=/var/www/html/-name: config php-mysql-file copy: src=/data/mysql.php dest=/var/www/html/ handlers:-name: restart php-fpm service: name=php-fpm state=restart

(5) implementation result:

(6) Test:

Fourth, using Ansible Role to build LNMP automatically.

1. Lab host:

Ansible host: 172.20.10.6webservers:172.20.10.3appservers:172.20.10.4

2.ansible host roles directory:

3. The execution result is:

4. The access tests are:

Tags: Host service relay experiment necessity result test automation configuration script function foundation actual key hour local area LAN file mode environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Huawei Linux OPPO Reno