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

相关内容

热门资讯

玩家最新攻略“乐暴延边麻将.辅... 玩家最新攻略“乐暴延边麻将.辅助开挂神器?”果然有透视挂您好,乐暴延边麻将这个游戏其实有挂的,确实是...
巴勒斯坦总统呼吁推进“两国方案... 总台记者获悉,当地时间12月21日,巴勒斯坦总统阿巴斯在约旦河西岸城市拉姆安拉会见了一个由以色列和平...
【今日要闻】“友乐广西麻将.辅... 家人们!今天小编来为大家解答友乐广西麻将透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里...
今日重大消息“新版wepoke... 您好:新版wepoker这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家...
【第一资讯】“阿道夫十三水.辅... 有 亲,根据资深记者爆料阿道夫十三水是可以开挂的,确实有挂(咨询软件无需...
玩家攻略科普“情怀古诗词.开挂... 有 亲,根据资深记者爆料情怀古诗词是可以开挂的,确实有挂(咨询软件无需打...
玩家最新攻略“樱花炸金花.开挂... 网上科普关于“樱花炸金花有没有挂”话题很是火热,小编也是针对樱花炸金花作*弊开挂的方法以及开挂对应的...
盐城固态电池产线落地经开区,未... 12月21日,固态离子能源科技(武汉)有限公司在盐城举办固态动力电池技术成果发布活动,中外行业专家、...
玩家分享攻略“YY棋牌.辅助开... 网上科普关于“YY棋牌有没有挂”话题很是火热,小编也是针对YY棋牌作*弊开挂的方法以及开挂对应的知识...
重磅消息“衡阳十胡卡.开挂器?... 重磅消息“衡阳十胡卡.开挂器?”确实真的有挂您好,衡阳十胡卡这个游戏其实有挂的,确实是有挂的,需要了...