2021-06-02

Posted givenchy_yzl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-06-02相关的知识,希望对你有一定的参考价值。

[root@m01 ~]# yum install -y ansible

做好免密:

配置主机清单
[root@m01 ansible]# vim /etc/ansible/hosts
[lb]
172.16.1.5
172.16.1.6
[web]
172.16.1.7
172.16.1.8
172.16.1.9
[nfs]
172.16.1.31
[backup]
172.16.1.41
[db]
172.16.1.51
[m01]
172.16.1.61
[jumpserver]
172.16.1.71

nginx

[root@m01 ansible]# cd roles/
[root@m01 roles]# ansible-galaxy init nginx
- Role nginx was created successfully
[root@m01 roles]# ls
nginx

[root@m01 roles]# vim nginx/tasks/create_user.yml
    - name: Create User
      user:
        name: {{ USER_NAME }}
        uid: {{ UID }}
        
[root@m01 roles]# vim nginx/tasks/create_repo.yml
    - name: create repo
        template:
          src: nginx.repo.j2
          dest: /etc/yum.repos.d/nginx.repo
          
[root@m01 roles]# vim nginx/templates/nginx.repo.j2
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
module_hotfixes=true

[root@m01 roles]# vim nginx/tasks/install.yml
    - name: Install Nginx Service
      yum: 
        name: nginx
        state: installed
        
[root@m01 roles]# vim nginx/tasks/nginx.conf.yml
    - name: Create Nginx Config
      template:
        src: nginx.conf.j2
        dest: /etc/nginx/nginx.conf
        
[root@m01 roles]# vim nginx/templates/nginx.conf.j2
    - name: Start Nginx Server
      service:
        name: nginx
        state: started

[root@m01 roles]# vim nginx/tasks/start.yml
    - name: Start Nginx Server
      service:
        name: nginx
        state: started
        

[root@m01 roles]# vim ../nginx.yml

---
- hosts: web
  remote_user: root
  roles:
    - nginx  


[root@m01 roles]# vim nginx/tasks/main.yml

- include: create_user.yml
- include: create_repo.yml
- include: install.yml
- include: nginx.conf.yml
- include: start.yml

php

[root@m01 roles]# ansible-galaxy init php
[root@m01 roles]# vim php/tasks/php.repo.yml

  • name: create PHP Yum Repo
    template:
    src: php.repo.j2
    dest: /etc/yum.repos.d/php.repo

[root@m01 roles]# vim php/templates/php.repo.j2
[php-webtatic]
name = PHP Repo
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

[root@m01 roles]# vim php/tasks/install.yml

  • name: Install PHP Service
    yum:
    name: php71w,php71w-cli,php71w-common,php71w-devel,php71w-embedded,php71w-gd,php71w-mcrypt,php71w-mbstring,php71w-pdo,php71w-xml,php71w-fpm,php71w-mysqlnd,php71w-opcache,php71w-pecl-memcached,php71w-pecl-redis,php71w-pecl-mongodb
    state: installed
    notify: Start_PHP_Serivice

[root@m01 roles]# vim php/handlers/Start_PHP_Serivice

  • name: Start_PHP_Serivice
    service:
    name: php-fpm
    state: started
    [root@m01 ansible]# vim roles/php/handlers/main.yml
  • include: Start.yml

[root@m01 roles]# vim php/tasks/www.conf.yml

  • name: Copy PHP Config
    template:
    src: www.conf.j2
    dest: /etc/php-fpm.d/www.conf

[root@m01 ansible]# vim roles/php/templates/www.conf.j2
[www]
user = {{ USER_NAME }}
group = {{ USER_NAME }}
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache

[root@m01 ansible]# cat roles/php/defaults/main.yml
USER_NAME: www

mysql

[root@m01 roles]# ansible-galaxy init mariadb

[root@m01 ansible]# vim roles/mariadb/tasks/install.yml

  • name: Install MariaDB Service
    yum:
    name: mariadb,mariadb-server
    state: installed

[root@m01 ansible]# vim roles/mariadb/tasks/start.yml

  • name: Start MariaDB Service
    service:
    name: mariadb
    state: started

[root@m01 ansible]# vim roles/mariadb/tasks/creat.passwd.yml

  • name: create mysql_user
    shell:
    cmd: “mysqladmin -uroot password ‘123’”

[root@m01 ansible]# vim roles/mariadb/tasks/copy.sh.yml

  • name: create jiance.sh
    template:
    src: jiance.sh.j2
    dest: /root/jiance.sh

[root@m01 ansible]# vim roles/mariadb/tasks/run.yml

  • name: run check.sh
    shell:
    cmd: “sh /root/jiance.sh”

[root@m01 ansible]# vim roles/mariadb/tasks/create_database.yml

  • name: create database
    shell:
    cmd: ‘mysql -uroot -p123 -e “create database yzl;”’

[root@m01 ansible]# vim roles/mariadb/tasks/permission.yml

  • name:
    shell:
    cmd: “mysql -root -p123 -e grant all on yzl.* to yzl@’%’ identified by ‘123’;” 有问题

package

[root@m01 roles]# vim package/tasks/create_dir.yml

  • name: Create Dir
    shell: ‘mkdir -pv {{ ROOT_PATH }}’
    [root@m01 deployment]# cat tasks/unarchive.yaml
  • name: Decompression Package
    unarchive:
    copy: yes
    src: /opt/Z-BlogPHP_1_7_0_2950_Tenet.tar.gz
    dest: “{{ ROOT_PATH }}”
    owner: www
    [root@m01 deployment]# cat tasks/vhost.yaml
  • name: Create zblog Vhost Config
    template:
    src: zblog.conf.j2
    dest: /etc/nginx/conf.d/zblog.conf

copy.sh.yml create_database.yml creat.passwd.yml install.yml main.yml permission.yml run.yml start.yml

使用Roles编排web机器

创建用户(变量)

安装Nginx

修改配置文件(变量及循环)

启动


  • hosts: web
    remote_user: root
    gather_facts: no
    tasks:
    • name: Create User
      user:
      name: {{ USER_NAME }}
      uid: {{ UID }}
    • name: create repo
      template:
      src: nginx.repo.j2
      dest: /etc/yum.repos.d/nginx.repo
    • name: Install Nginx Service
      yum:
      name: nginx
      enablerepo: nginx-stable
      state: installed
    • name: Create Nginx Config
      template:
      src: nginx.conf.j2
      dest: /etc/nginx/nginx.conf
    • name: Start Nginx Server
      service:
      name: nginx
      state: started

  • hosts: web
    remote_user: root
    roles:

    • nginx
  • hosts: web
    remote_user: root
    gather_facts: no
    tasks:

    • name: test
      shell: “pwd”
      when: ansible_distribution_major_version == “7”

项目分析

安装wordpress和discuz

负载均衡,web服务,PHP服务,Mysql服务

  • hosts: db
    remote_user: root
    tasks:
    • name: Stop MariaDB Service
      service:
      name: mariadb
      state: stopped
    • name: Uninstall MariaDB service
      yum:
      name: mariadb
      state: absent
    • name: Remove MariaDB Config File
      file:
      path: “{{ item }}”
      state: absent
      with_items:
      • /etc/my.cnf
      • /var/lib/mysql
      • /var/log/mariadb
      • /var/run/mariadb
      • /etc/my.cnf.d
    • name: Copy Config File
      template:
      src: my.cnf.j2
      dest: /etc/my.cnf
      owner: mysql
      group: mysql
      mode: 600
    • name: Install MariaDB Service
      yum:
      name: mariadb,mariadb-server
      state: installed
      notify: Start MariaDB Service
    • name: Start MariaDB Service
      service:
      name: mariadb
      state: started
    • name: tance.yml

PHP服务

  • hosts: web
    remote_user: root
    tasks:
    • name: Stop PHP Service
      service:
      name: php-fpm
      state: stopped
    • name: Uninstall PHP Service
      yum:
      name: php71w*
      state: absent
    • name: Remove PHP Config
      file:
      path: {{ item }}
      state: absent
      with_items:
      • /etc/php.d
      • /etc/php-fpm.conf
      • /etc/php-fpm.d
      • /etc/php.ini
      • /etc/php.ini.rpmnew
      • /etc/php.ini.rpmsave
      • /etc/php-zts.d
    • name: Create User
      user:
      name: www
      uid: 550
    • name: Config PHP Yum Repo
      template:
      src: php.repo.j2
      dest: /etc/yum.repos.d/php.repo
    • name: Install PHP Service
      yum:
      name: php71w*
      state: installed
      notify: Start PHP Serivice
    • name: Copy PHP Config
      template:
      src: www.conf.j2
      dest: /etc/php-fpm.d/www.conf
      handlers:
    • name: Start PHP Serivice
      service:
      name: php-fpm
      state: started

#php71w,php71w-cli,php71w-common,php71w-devel,php71w-embedded,php71w-gd,php71w-mcrypt,php71w-mbstring,php71w-pdo,php71w-xml,php71w-fpm,php71w-mysqlnd,php71w-opcache,php71w-pecl-memcached,php71w-pecl-redis,php71w-pecl-mongodb




以上是关于2021-06-02的主要内容,如果未能解决你的问题,请参考以下文章

2021-06-02

2021-06-02

林梓琦|2021软件代码开发技术作业五|代码开发测试及发布

2021-06-02 Hive课后实验5(一些小建议)

2021-06-02 Hive课后实验5(一些小建议)

2021-06-02 Hive课后实验5(一些小建议)