DHCP和ansible

まず、LANユーザにIP 10.1.1.0/24ネットワークセグメントを提供するために、DHCPサービスを設定し、リース期間は、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脚本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+LzGwHhd2YCnKh6kOl6IZQcZ4 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.脚本スクリプトを定義します。

[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役割ビルドLNMP使用して自動化された方法
1。実験のホストを:

ansible主机:172.20.10.6
webservers:172.20.10.3
appservers:172.20.10.4

2.ansibleホストの役割ディレクトリ:
DHCP和ansible
結果の3.実装:
DHCP和ansible
4.アクセステストは以下のとおりです。
DHCP和ansible
DHCP和ansible

おすすめ

転載: blog.51cto.com/14418331/2458561