dhcp和ansible
admin
2023-02-23 21:00:06
0

一、搭建DHCP服务,为局域网内用户提供10.1.1.0/24网段的IP,且租约期默认为48小时
1.安装软件包:
yum install -y dhcp*
2.配置服务:

[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;
max-lease-time 172800;
log-facility local7;
subnet 10.1.1.0 netmask 255.255.255.0 {
        range 10.1.1.100 10.1.1.200;

3.启动服务并验证:

systemctl start dhcp
dhclient -d

二、在上述实验基础上,实现DHCP中继:

# 开启路由转发功能
vim /etc/sysctl.conf
net.ipv4.ip-forward=1
sysctl -p
# 启动dhcp中继服务
dhcrelay dhcp_server_ip

中继服务实际使用中,基本没有必要使用。其他网络的主机另外新建一个dhcp服务就好,没有必要非得使用中继

三、借助Ansible Playbook自动化搭建LNMP环境(可借助yum)
1.实验主机:

ansible主机:172.20.10.6
webservers:172.20.10.3
appservers:172.20.10.4

2.ansible主机免密钥认证
(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@localhost
The key's randomart image is:
+---[RSA 2048]----+
|  *o* . . .      |
|ooo@ + o = +     |
|+o+.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配置文件

[webservers]
172.20.10.3
[appservers]
172.20.10.4

4.定义playbook剧本:

[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)执行结果:
dhcp和ansible
(6)测试:
dhcp和ansible
dhcp和ansible
四、采用Ansible Role方式自动化搭建LNMP
1.实验主机:

ansible主机:172.20.10.6
webservers:172.20.10.3
appservers:172.20.10.4

2.ansible主机roles目录:
dhcp和ansible
3.执行结果为:
dhcp和ansible
4.访问测试为:
dhcp和ansible
dhcp和ansible

相关内容

热门资讯

东莞移动:5G-A智擎护航, ... “五一”期间,松山湖草莓音乐节、广东国际汽车展示交易会·春季、2026茶园游会田园文化美食节、大岭山...
汉阳“知音数创”AI智能体创新... 4月30日,武汉市汉阳区数智产业推介会暨汉阳“知音数创”AI智能体创新大赛启动仪式在武汉基金产业基地...
伊朗最高领袖军事顾问:美国必须... 当地时间5月6日,伊朗最高领袖军事顾问穆赫辛·雷扎伊在接受采访时表示,伊朗不允许美国在不付出代价的情...
瑞士确诊、法国密接、西班牙待命... 综合法媒报道,国际探险邮轮“洪迪厄斯”号上的汉坦病毒事件,正从南美航程延伸至欧洲语境。最新进展显示,...
AMD锐龙X3D快到把游戏跑崩... 快科技5月6日消息,在Apex英雄最新Overclocked补丁中,修复了一个颇为尴尬的问题:AMD...
重磅|第十九届智慧城市大会将于... 2026年7月16日-18日,第十九届智慧城市大会将在天津社会山国际会议中心举办。本届大会由中国服务...
奥巴马暗批特朗普:不应将司法与... 美国前总统奥巴马近日在接受采访时,借列举总统权力被滥用的多个例子,含蓄批评总统特朗普,但全程未直接点...
三星宣布:在中国大陆市场停止销... 【大河财立方消息】5月6日,三星(中国)投资有限公司发布通知称,为应对急剧变化的市场环境,经慎重研究...
郑州商转公“直还”扩容!80家... 【大河财立方消息】5月6日,郑州住房公积金管理中心公告,13家银行已与郑州住房公积金管理中心签订《商...
男子花数十万买回犀牛角、熊胆,... 王绍斌至今想不通,自己是个三十多年的生意人,怎么会在老挝一下子刷出去六位数,买回来两片犀牛角、半块熊...