Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Dhcp and ansible

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 270

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report