ansible 배치 간단 하고 사용 가능 한 LAMP

ansible 배치 간단 하고 사용 가능 한 LAMP
ansible 호스트: 192.168.152.145HA 1 (HighAvailable): 192.168.152.140HA 2: 192.168.152.141VIP 1 (virtual IP): 192.168.152.190VIP 2: 192.168.152.191AP 1 (아파 치 + PHP): 192.168.152.142AP 2 (아파 치 + PHP): 192.168.152.143DB: 192.168.152.152.144
구성 가능
yum -y install ansiblevim /etc/ansible/hosts
[nginx]
192.168.152.140
192.168.152.141
[ap]
192.168.152.142
192.168.152.143
[db]
192.168.152.144

ssh-keygen -t rsa -P ''ssh-copy-id -i .ssh/id_rsa.pub [email protected] -i .ssh/id_rsa.pub [email protected] -i .ssh/id_rsa.pub [email protected] -i .ssh/id_rsa.pub [email protected] -i .ssh/id_rsa.pub [email protected] - m ping 테스트 연결 성
rolesmkdir / etc / Ansible / roles / keepalived / {files, tasks, templates, handlers, vars, default} - pvmkdir / etc / ansible / roles / nginx / {files, tasks, templates, handlers, vars, default} - pvmkdir / etc / ansible / roles / apachephp / {files, tasks, templates, handlers, vars, default} - pvmkdir / etc / ansible / roles / database / {files, tasks, templates, handlers, vars, default} - pv
vim /etc/ansible/roles/keepalived/tasks/main.yml
- name: install keepalived
  yum: name=keepalived state=present
- name: install conf file
  template: src=keepalived.conf.j2 dest=/etc/keepalived/keepalived.conf
- name: start keepalived
  service: name=keepalived state=started enabled=true

vim /etc/ansible/roles/nginx/tasks/main.yml
- name: install nginx
  yum: name=nginx state=present
- name: install conf file
  template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
- name: start nginx
  service: name=nginx state=started enabled=true

vim /etc/ansible/roles/apachephp/tasks/main.yml
- name: install httpd
  yum: name=httpd state=present
- name: install php
  yum: name=php state=present
- name: install php-mysql
  yum: name=php-mysql state=present
- name: install httpconf file
  template: src=http.conf.j2 dest=/etc/httpd/conf/httpd.conf
- name: install html file
  template: src=html.index.j2 dest=/var/www/html/index.php
- name: start httpd
  service: name=httpd state=started enabled=true

vim /etc/ansible/roles/database/tasks/main.yml
- name: install mysql
  yum: name=mysql-server state=present
  when: ansible_distribution_major_version == "6"
- name: install mariadb
  yum: name=mariadb-server state=present
  when: ansible_distribution_major_version == "7"
- name: install conf file
  template: src=db.conf.j2 dest=/etc/my.cnf
- name: start mysql
  service: name=mysqld state=started enabled=true
  when: ansible_distribution_major_version == "6"
- name: start mariadb
  service: name=mariadb state=started enabled=true
  when: ansible_distribution_major_version == "7"

cd /etc/ansible/roles/vim keepalived/templates/keepalived.conf.j2
vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.152.190
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eno16777736
    virtual_router_id 151
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.152.191
    }
}

vim nginx/templates/nginx.conf.j2
http {
    upstream webservers {
        server 192.168.152.142:80;
        server 192.168.152.143:80;
    }
    location / {
                proxy_pass http://webservers;
        }
}

vim apachephp/templates/http.conf.j2
 DirectoryIndex index.html index.php

vim apachephp/templates/html.index.j2
<h1>192.168.152.142</h1>
<?php
        phpinfo()
?>
<?php
        $link = mysql_connect('192.168.152.144','root','12345678');
        if($link)
                echo "Success...";
        else
                echo "Failed....";
        mysql_close;
?>

vim database/templates/db.conf.j2
[mysqld]
innodb_file_per_table = ON
skip_name_resolve = ON

rolesmkdir / etc / ansible / ymlvim / etc / ansible / yml / keepalived. yml 호출
- hosts: nginx
  remote_user: root
  roles:
  - keepalived

vim /etc/ansible/yml/nginx.yml
- hosts: nginx
  remote_user: root
  roles:
  - nginx

vim /etc/ansible/yml/apachephp.yml
- hosts: ap
  remote_user: root
  roles:
  - apachephp

vim /etc/ansible/yml/database.yml
- hosts: db
  remote_user: root
  roles:
  - database

테스트 ansible - playbook -- check / etc / ansible / yml / keepalived. ymlansible - playbook -- check / etc / ansible / yml / nginx. ymlansible - playbook -- check / etc / ansible / yml / yml / apache php. ymlansible - playbook -- check / etc / ansible / yml / database. yml
ansible - playbook / etc / ansible / yml / keepalived. ymlansible - playbook / etc / ansible / yml / ngix. ymlansible - playbook / etc / ansible / yml / apache php. ymlansible - playbook / etc / ansible / yml / database. yml 실행
완성 후 에는 미조정 을 해 야 한다
192.168.152.141        #주 주 는 높 은 사용 가능, 140 은 190 주, 191 비;141 은 191 주, 190 비 vim / etc / keepalived / keepalived. conf
vrrp_instance VI_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.152.190
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface eno16777736
    virtual_router_id 151
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.152.191
    }
}

192.168.152.143        #142 홈 페이지 내용 과 구별 하기 위해 IP 디 스 플레이 vim / var / www / html / index. php 변경
<h1>192.168.152.143</h1>
<?php
        phpinfo()
?>
<?php
        $link = mysql_connect('192.168.152.144','root','12345678');
        if($link)
                echo "Success...";
        else
                echo "Failed....";
        mysql_close;
?>

192.168.152.144        #루트 권한 을 위 한 데이터베이스 권한 관리, 원 격 테스트 연결 성 mysqlgrant all privileges on. to 'root' @ '192.168.%.%' identified by '12345678'
완료 후 호스트 keepalived 서 비 스 를 닫 고 ip address list 를 통 해 가상 주소 의 이동 을 관찰 하고 호스트 HTTP 서 비 스 를 닫 으 며 웹 페이지 가 계속 접근 할 수 있 는 지 확인 하면 됩 니 다.

좋은 웹페이지 즐겨찾기