1. 业务环境部署

  • wordpress-base:用于设置WEB集群的网络基础环境,包括所有节点网关指向出口路由器,添加DNS;
  • wordpress-web:用来增加nginx的虚拟主机节点,PHP-FPM连接redis,nfs挂载;
  • wordpress-proxy:用于添加nginx负载均衡的虚拟主机节点,LVS后端RS网络部署;
  • wordpress-mysql:用于创建wordpress的数据库和相关用户;

1.1 wordpress-base编写

  • 创建wordpress-base模块的目录结构:

    [root@xuzhichao cluster-roles]# mkdir wordpress-base/{tasks,meta,files,tamplates,handlers} -p
  • 编写主任务文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-base/tasks/main.yml
    #1.把所有节点的网关指向192.168.20.17,增加DNS地址192.168.20.70
    - name: Modify Gateway And Dns
    lineinfile:
    path: /etc/sysconfig/network-scripts/ifcfg-eth1-static
    line: "GATEWAY=192.168.20.17\nDNS1=192.168.20.70" #2.重启网络
    - name: Restart Network
    systemd:
    name: network
    state: restarted
  • playbook文件修改如下:

    [root@xuzhichao cluster-roles]# cat wordpress_site.yml
    - hosts: all
    roles:
    - role: base-module
    - role: wordpress-base
    tags: base-module
    ......

1.2 wordpress-web编写

  • 创建wordpress-web的目录结构:

    [root@xuzhichao cluster-roles]# mkdir wordpress-web/{tasks,meta,files,templates,handlers} -p
  • nginx 虚拟主机任务文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-web/tasks/nginx_web_vhost.yml
    - name: Copy Nginx Vhosts Configure File
    template:
    src: "wordpress.conf.j2"
    dest: "{{ nginx_install_directory }}/nginx/conf/conf.d/wordpress.conf"
    notify: Restart Nginx Server - name: Check Nginx Configure File
    shell: "{{ nginx_install_directory }}/nginx/sbin/nginx -t"
    register: Check_Nginx_Status
    changed_when:
    - Check_Nginx_Status.stdout.find('successful')
    - false
  • wordpress的代码部署如下:

    [root@xuzhichao cluster-roles]# cat wordpress-web/tasks/wordpress_code.yml
    #1.拷贝解压wordpress代码
    - name: Unarchive Wordpress Code
    unarchive:
    src: wordpress-5.7.2-zh_CN.tar.gz
    dest: "{{ wordpress_unarchive_directory }}"
    owner: "{{ web_user }}"
    group: "{{ web_group }}"
    mode: "0755" #2.创建图片上传目录,默认wordpress没有创建
    - name: Create wp-content/uploads directory
    file:
    path: "{{ wordpress_code_directory }}/wp-content/uploads"
    state: directory
    owner: "{{ web_user }}"
    group: "{{ web_group }}"
    mode: "0755"
    changed_when: false #3.挂载NFS
    - name: Mount NFS Point
    mount:
    src: "nfs01.xuzhichao.com:{{ nfs_share_path }}"
    path: "{{ wordpress_code_directory }}/wp-content/uploads"
    fstype: nfs
    opts: defaults
    state: mounted
  • php连接redis编译部署如下:

    [root@xuzhichao cluster-roles]# cat wordpress-web/tasks/php_connect_redis.yml
    #1.安装php-pecl-redis软件包
    - name: Install php-pecl-redis
    yum:
    name: php-pecl-redis
    state: present #2.拷贝解压redis扩展包
    - name: Unarchive php-Redis
    unarchive:
    src: redis-4.2.0.tgz
    dest: /root #3.生成配置文件
    - name: phpize
    shell:
    cmd: "{{ PHP_install_directory }}/php/bin/phpize"
    chdir: "/root/redis-4.2.0"
    changed_when: false #4.configure预编译
    - name: Configure
    shell:
    cmd: "./configure --with-php-config={{ PHP_install_directory }}/php/bin/php-config"
    chdir: "/root/redis-4.2.0"
    changed_when: false #5.编译安装
    - name: Make And Make Install
    shell:
    cmd: make && make install
    chdir: "/root/redis-4.2.0"
    changed_when: false
  • 主任务文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-web/tasks/main.yml
    - include: wordpress_code.yml
    - include: nginx_web_vhost.yml
    - include: php_connect_redis.yml
  • nginx虚拟主机模板文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-web/templates/wordpress.conf.j2
    log_format access_json '{ "@timestamp": "$time_iso8601", '
    '"remote_addr": "X-Forwarded_For", '
    '"referer": "$http_referer", '
    '"request": "$request", '
    '"status": $status, '
    '"bytes":$body_bytes_sent, '
    '"agent": "$http_user_agent", '
    '"x_forwarded": "$http_x_forwarded_for", '
    '"upstr_addr": "$upstream_addr",'
    '"upstr_host": "$upstream_http_host",'
    '"upstreamtime": "$upstream_response_time" }'; server {
    listen 80;
    server_name {{ wordpress_server_name }};
    access_log {{ nginx_install_directory }}/nginx/logs/access_wordpress.log access_json;
    charset utf-8,gbk; #防盗链
    valid_referers none blocked server_names *.b.com b.* ~\.baidu\. ~\.google\.; if ( $invalid_referer ) {
    return 403;
    } client_max_body_size 10m; location / {
    root {{ wordpress_code_directory }};
    index index.html index.php;
    } location ~ \.php$ {
    root {{ wordpress_code_directory }}; #fastcgi反向代理
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTPS on; <==此指令加上会导致http向https跳转,此处不能加。
    fastcgi_hide_header X-Powered-By;
    include fastcgi_params;
    } location ~ ^/(ping|pm_status)$ {
    access_log off;
    allow 192.168.20.0/24;
    allow 192.168.50.0/24;
    deny all;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    include fastcgi_params;
    } location = /nginx_status {
    access_log off;
    allow 192.168.20.0/24;
    allow 192.168.50.0/24;
    deny all;
    stub_status;
    }
    }
  • wordpress-web的依赖的role如下,表示需要先执行依赖的角色,才可以执行本角色:

    [root@xuzhichao cluster-roles]# cat wordpress-web/meta/main.yml
    dependencies:
    - { role: nginx }
    - { role: php-fpm }
  • 新增的变量文件如下:

    [root@xuzhichao cluster-roles]# cat group_vars/all
    ......
    #wordpress相关变量
    wordpress_unarchive_directory: /data/nginx
    wordpress_code_directory: /data/nginx/wordpress
    wordpress_server_name: wordpress.xuzhichao.com
  • wordpress-web整体目录结构如下:

    [root@xuzhichao cluster-roles]# tree wordpress-web/
    wordpress-web/
    ├── files
    │   ├── redis-4.2.0.tgz
    │   └── wordpress-5.7.2-zh_CN.tar.gz
    ├── handlers
    │   └── main.yml
    ├── meta
    │   └── main.yml
    ├── tasks
    │   ├── main.yml
    │   ├── nginx_web_vhost.yml
    │   ├── php_connect_redis.yml
    │   └── wordpress_code.yml
    └── templates
    └── wordpress.conf.j2 5 directories, 9 files
  • playbook文件修改如下:

    [root@xuzhichao cluster-roles]# cat wordpress_site.yml
    - hosts: all
    roles:
    - role: base-module
    - role: wordpress-base
    tags: base-module - hosts: webservers
    roles:
    - role: wordpress-web
    tags:
    - wordpress-web - hosts: lbservers
    roles:
    - role: nginx
    tags: nginx - hosts: mysql
    roles:
    - role: mariadb
    tags: mysql - hosts: redis
    roles:
    - role: redis
    tags: redis - hosts: nfs
    roles:
    - role: nfs
    tags: nfs - hosts: lvs
    roles:
    - role: keepalived
    tags: keepalived - hosts: dns
    roles:
    - role: dns
    tags: dns
  • 运行palybook文件:

    [root@xuzhichao cluster-roles]# ansible-playbook  -t wordpress-web wordpress_site.yml
  • 检测web节点的虚拟主机配置文件如下:

    [root@web01 ~]# cat /soft/nginx/conf/conf.d/wordpress.conf
    log_format access_json '{ "@timestamp": "$time_iso8601", '
    '"remote_addr": "X-Forwarded_For", '
    '"referer": "$http_referer", '
    '"request": "$request", '
    '"status": $status, '
    '"bytes":$body_bytes_sent, '
    '"agent": "$http_user_agent", '
    '"x_forwarded": "$http_x_forwarded_for", '
    '"upstr_addr": "$upstream_addr",'
    '"upstr_host": "$upstream_http_host",'
    '"upstreamtime": "$upstream_response_time" }'; server {
    listen 80;
    server_name wordpress.xuzhichao.com;
    access_log /soft/nginx/logs/access_wordpress.log access_json;
    charset utf-8,gbk; #防盗链
    valid_referers none blocked server_names *.b.com b.* ~\.baidu\. ~\.google\.; if ( $invalid_referer ) {
    return 403;
    } client_max_body_size 10m; location / {
    root /data/nginx/wordpress;
    index index.html index.php;
    } location ~ \.php$ {
    root /data/nginx/wordpress; #fastcgi反向代理
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_hide_header X-Powered-By;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    } location ~ ^/(ping|pm_status)$ {
    access_log off;
    allow 192.168.20.0/24;
    allow 192.168.50.0/24;
    deny all;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    include fastcgi_params;
    } location = /nginx_status {
    access_log off;
    allow 192.168.20.0/24;
    allow 192.168.50.0/24;
    deny all;
    stub_status;
    }
    }
  • 查看web节点服务启动情况:

    [root@web01 ~]# ss -ntl
    State Recv-Q Send-Q Local Address:Port Peer Address:Port ......
    LISTEN 0 128 127.0.0.1:9000 *:*
    LISTEN 0 128 *:80 *:* [root@web01 ~]# df
    Filesystem 1K-blocks Used Available Use% Mounted on
    ......
    nfs01.xuzhichao.com:/data/nfs 154057344 33664 154023680 1% /data/nginx/wordpress/wp-content/uploads

1.3 wordpress-mysql编写

注意:数据库建议使用新的数据库部署,若使用之前的数据库会存在问题,因为之前的数据库存储了wordpress的会话信息,对新的站点会造成影响。

  • 创建wordpress-mysql目录结构:

    [root@xuzhichao cluster-roles]# mkdir wordpress-mysql/{tasks,handlers,meta,files,templates} -p
  • 主任务文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-mysql/tasks/main.yml
    #1.创建数据库wordpress
    - name: Create Wordpress Database
    mysql_db:
    login_host: "localhost"
    login_user: "root"
    login_password: "123456"
    #login_password: "123456"
    login_port: "3306"
    name: "{{ wordpress_mysql_database }}"
    state: present #2.授权远程连接的数据库
    - name: Grant Wordpress Database User
    mysql_user:
    login_host: "localhost"
    login_user: "root"
    login_password: "123456"
    #login_port: "3306"
    name: "{{ wordpress_mysql_user }}"
    password: "{{ wordpress_mysql_password }}"
    host: "{{ wordpress_mysql_host }}"
    priv: "{{ wordpress_mysql_user }}.*:ALL"
    state: present
  • 依赖文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-mysql/meta/main.yml
    dependencies:
    - { role: mariadb }
  • 变量文件如下:

    [root@xuzhichao cluster-roles]# vim group_vars/all
    #wordpress相关变量
    wordpress_unarchive_directory: /data/nginx
    wordpress_code_directory: /data/nginx/wordpress
    wordpress_server_name: wordpress.xuzhichao.com wordpress_mysql_database: wordpress
    wordpress_mysql_user: wordpress
    wordpress_mysql_password: 123456
    wordpress_mysql_host: 192.168.20.%
  • playbook文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress_site.yml
    - hosts: all
    roles:
    - role: base-module
    - role: wordpress-base
    tags: base-module - hosts: webservers
    roles:
    - role: wordpress-web
    tags:
    - wordpress-web - hosts: lbservers
    roles:
    - role: nginx
    tags: nginx - hosts: mysql
    roles:
    - role: wordpress-mysql
    tags: wordpress-mysql - hosts: redis
    roles:
    - role: redis
    tags: redis - hosts: nfs
    roles:
    - role: nfs
    tags: nfs - hosts: lvs
    roles:
    - role: keepalived
    tags: keepalived - hosts: dns
    roles:
    - role: dns
    tags: dns
  • 运行playbook:

    [root@xuzhichao cluster-roles]# ansible-playbook -t wordpress-mysql wordpress_site.yml
  • 查看mysql是否成功创建:

    [root@web02 ~]# mysql -uwordpress -p123456 -h192.168.20.50
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 36
    Server version: 10.5.2-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | test |
    | wordpress |
    +--------------------+
    3 rows in set (0.00 sec)

1.4 wordpress-proxy编写

  • 创建wordpress-proxy的目录结构:

    [root@xuzhichao cluster-roles]# mkdir wordpress-proxy/{tasks,templates,files,meta,handlers} -p
  • 主任务文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-proxy/tasks/main.yml
    #创建证书存放目录
    - name: Create Cert directory
    file:
    path: "{{ nginx_install_directory }}/nginx/certs"
    state: directory #拷贝证书文件
    - name: Copy SSL Cer File
    copy:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    loop:
    - { src: "xuzhichao.key", dest: "{{ nginx_install_directory }}/nginx/certs/xuzhichao.key" }
    - { src: "xuzhichao.crt", dest: "{{ nginx_install_directory }}/nginx/certs/xuzhichao.crt" } #拷贝虚拟主机配置文件
    - name: Copy Nginx-LB Vhosts Configure
    template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    loop:
    - { src: "wordpress.conf.j2", dest: "{{ nginx_install_directory }}/nginx/conf/conf.d/wordpress.conf" }
    - { src: "proxy_params.j2", dest: "{{ nginx_install_directory }}/nginx/conf/proxy_params" }
    notify: Restart Nginx Server #检查nginx配置文件
    - name: Check Nginx Configure File
    shell: "{{ nginx_install_directory }}/nginx/sbin/nginx -t"
    register: Check_Nginx_Status
    changed_when:
    - Check_Nginx_Status.stdout.find('successful')
    - false #LVS的DR模型设置虚IP,一致arp
    - name: LVS DR RS Scripts
    script: ../files/lvs_rs.sh start
  • handlers文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-proxy/handlers/main.yml
    - name: Restart Nginx Server
    systemd:
    name: nginx
    state: reloaded
  • nginx负载均衡虚拟主机文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-proxy/templates/wordpress.conf.j2
    upstream webservers {
    {% for host in groups["webservers"] %}
    server {{ host }}:80 weight=1 fail_timeout=5s max_fails=3;
    {% endfor %}
    } log_format access_json '{ "@timestamp": "$time_iso8601", '
    '"remote_addr": "X-Forwarded_For", '
    '"referer": "$http_referer", '
    '"request": "$request", '
    '"status": $status, '
    '"bytes":$body_bytes_sent, '
    '"agent": "$http_user_agent", '
    '"x_forwarded": "$http_x_forwarded_for", '
    '"upstr_addr": "$upstream_addr",'
    '"upstr_host": "$upstream_http_host",'
    '"upstreamtime": "$upstream_response_time" }'; server {
    listen 443 ssl;
    listen 80;
    server_name {{ wordpress_server_name }};
    access_log {{ nginx_install_directory }}/nginx/logs/access_wordpress.log access_json; ssl_certificate {{ nginx_install_directory }}/nginx/certs/xuzhichao.crt;
    ssl_certificate_key {{ nginx_install_directory }}/nginx/certs/xuzhichao.key;
    ssl_session_cache shared:ssl_cache:30m;
    ssl_session_timeout 10m; valid_referers none blocked server_names *.b.com b.* ~\.baidu\. ~\.google\.; if ( $invalid_referer ) {
    return 403;
    } location / { if ( $scheme = http ) {
    rewrite /(.*) https://{{ wordpress_server_name }}/$1 permanent;
    } proxy_pass http://webservers;
    include proxy_params;
    }
    } [root@xuzhichao cluster-roles]# cat wordpress-proxy/templates/proxy_params.j2
    proxy_set_header host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30;
    proxy_send_timeout 60;
    proxy_read_timeout 60; proxy_buffering on;
    proxy_buffer_size 64k;
    proxy_buffers 4 64k;
  • lvs的rs脚本文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-proxy/files/lvs_rs.sh
    #!/usr/bin/bash VIP1=192.168.20.200
    VIP2=192.168.20.201
    DEV1=lo:0
    DEV2=lo:1 case $1 in
    start)
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "1" >/proc/sys/net/ipv4/conf/default/arp_ignore
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
    echo "2" >/proc/sys/net/ipv4/conf/default/arp_announce
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce cat >/etc/sysconfig/network-scripts/ifcfg-${DEV1} <<-EOF
    DEVICE=${DEV1}
    IPADDR=${VIP1}
    NETMASK=255.255.255.255
    ONBOOT=yes
    NAME=loopback1
    EOF cat >/etc/sysconfig/network-scripts/ifcfg-${DEV2} <<-EOF
    DEVICE=${DEV2}
    IPADDR=${VIP2}
    NETMASK=255.255.255.255
    ONBOOT=yes
    NAME=loopback2
    EOF
    ifup ${DEV1} # 启动网卡
    ifup ${DEV2}
    systemctl start nginx
    ;;
    stop)
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/default/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    echo "0" >/proc/sys/net/ipv4/conf/default/arp_announce
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce ifdown ${DEV1} # 停止网卡
    ifdown ${DEV2}
    rm -f /etc/sysconfig/network-scripts/ifcfg-${DEV1}
    rm -f /etc/sysconfig/network-scripts/ifcfg-${DEV2}
    systemctl stop nginx
    ;;
    *)
    echo "Usage: sh $0 { start | stop }"
    esac
  • meta依赖文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress-proxy/meta/main.yml
    dependencies:
    - { role: nginx }
  • wordpress-proxy整体目录结构如下:

    [root@xuzhichao cluster-roles]# tree wordpress-proxy/
    wordpress-proxy/
    ├── files
    │   ├── lvs_rs.sh
    │   ├── xuzhichao.crt
    │   └── xuzhichao.key
    ├── handlers
    │   └── main.yml
    ├── meta
    │   └── main.yml
    ├── tasks
    │   └── main.yml
    └── templates
    ├── proxy_params.j2
    └── wordpress.conf.j2
  • 变量文件如下:

    [root@xuzhichao cluster-roles]# cat group_vars/all
    #创建基础环境变量
    web_group: nginx
    web_gid: 887
    web_user: nginx
    web_uid: 887 #nginx相关变量
    nginx_install_directory: /soft
    nginx_filename_tar: nginx-1.20.1.tar.gz
    nginx_version: nginx-1.20.1
    nginx_configure_options: --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_dav_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --with-file-aio
    gzip_contorl: "on"
    keepalive_timeout: 65
    worker_connections_num: 35566
    nginx_path: /soft/nginx/sbin/nginx #PHP相关变量
    PHP_install_directory: /soft
    PHP_tar_packages: php-7.3.16.tar.xz
    PHP_version: php-7.3.16 PHP_configure_options: --enable-fpm --with-pear --with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-curl --with-freetype-dir --with-iconv --disable-debug --with-mhash --with-xmlrpc --with-xsl --enable-soap --enable-exif --enable-wddx --enable-bcmath --enable-calendar --enable-shmop --enable-sysvsem --enable-sysvshm --enable-syssvmsg php_fpm_listen_address: 127.0.0.1
    php_fpm_listen_port: 9000
    pm_max_children_num: 50
    php_path: /soft/php/sbin/php-fpm #Mysql相关变量
    mysql_user: mysql
    mysql_group: mysql
    mysql_base_directory: /usr/local/mysql
    mysql_data_directory: /data/mysql
    mysql_tar_ball: mariadb-10.5.2-linux-x86_64.tar.gz
    mysql_version: mariadb-10.5.2-linux-x86_64
    mysql_link_file_path: /usr/local/mysql
    mysqld_file: /etc/init.d/mysqld #NFS相关变量
    nfs_share_path: /data/nfs
    nfs_share_iprange: 192.168.20.0/24 #keepalived相关变量
    vrrp_interface: eth1
    virtual_router_id1: 51
    auth_pass: 1111
    virtual_ipaddress1: 192.168.20.200/24
    virtual_router_id2: 52
    virtual_ipaddress2: 192.168.20.201/24
    vips:
    - 192.168.20.200
    - 192.168.20.201
    track_ports:
    - 443
    - 80
    lb_algo: rr
    lb_kind: DR
    protocol: TCP #wordpress相关变量
    wordpress_unarchive_directory: /data/nginx
    wordpress_code_directory: /data/nginx/wordpress
    wordpress_server_name: wordpress.xuzhichao.com wordpress_mysql_database: wordpress
    wordpress_mysql_user: worpdress
    wordpress_mysql_password: 123456
    wordpress_mysql_host: 192.168.20.%
  • 最终playbook文件如下:

    [root@xuzhichao cluster-roles]# cat wordpress_site.yml
    - hosts: all
    roles:
    - role: base-module
    - role: wordpress-base
    tags: base-module - hosts: webservers
    roles:
    - role: wordpress-web
    tags:
    - wordpress-web - hosts: lbservers
    roles:
    - role: wordpress-proxy
    tags: wordpress-proxy - hosts: mysql
    roles:
    - role: wordpress-mysql
    tags: wordpress-mysql - hosts: redis
    roles:
    - role: redis
    tags: redis - hosts: nfs
    roles:
    - role: nfs
    tags: nfs - hosts: lvs
    roles:
    - role: keepalived
    tags: keepalived - hosts: dns
    roles:
    - role: dns
    tags: dns
  • 运行palybook:

    [root@xuzhichao cluster-roles]# ansible-playbook -t wordpress-proxy wordpress_site.yml
  • 查看nginx负载均衡的状态:

    #nginx虚拟主机配置文件:
    [root@lb01 ~]# cat /soft/nginx/conf/conf.d/wordpress.conf
    upstream webservers {
    server 192.168.20.22:80 weight=1 fail_timeout=5s max_fails=3;
    server 192.168.20.23:80 weight=1 fail_timeout=5s max_fails=3;
    } log_format access_json '{ "@timestamp": "$time_iso8601", '
    '"remote_addr": "X-Forwarded_For", '
    '"referer": "$http_referer", '
    '"request": "$request", '
    '"status": $status, '
    '"bytes":$body_bytes_sent, '
    '"agent": "$http_user_agent", '
    '"x_forwarded": "$http_x_forwarded_for", '
    '"upstr_addr": "$upstream_addr",'
    '"upstr_host": "$upstream_http_host",'
    '"upstreamtime": "$upstream_response_time" }'; server {
    listen 443 ssl;
    listen 80;
    server_name wordpress.xuzhichao.com;
    access_log /soft/nginx/logs/access_wordpress.log access_json; ssl_certificate /soft/nginx/certs/xuzhichao.crt;
    ssl_certificate_key /soft/nginx/certs/xuzhichao.key;
    ssl_session_cache shared:ssl_cache:30m;
    ssl_session_timeout 10m; valid_referers none blocked server_names *.b.com b.* ~\.baidu\. ~\.google\.; if ( $invalid_referer ) {
    return 403;
    } location / { if ( $scheme = http ) {
    rewrite /(.*) https://wordpress.xuzhichao.com/$1 permanent;
    } proxy_pass http://webservers;
    include proxy_params;
    }
    } #虚IP情况:
    [root@lb01 ~]# ip add show lo
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet 192.168.20.200/32 brd 192.168.20.200 scope global lo:0
    valid_lft forever preferred_lft forever
    inet 192.168.20.201/32 brd 192.168.20.201 scope global lo:1
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever #服务监听情况:
    [root@lb01 ~]# ss -ntl
    State Recv-Q Send-Q Local Address:Port Peer Address:Port
    LISTEN 0 128 *:443 *:*
    LISTEN 0 128 *:80 *:*

ansible系列(34)--ansible实战之部署WEB集群架构(4)的更多相关文章

  1. Linux Web集群架构详细(亲测可用!!!)

    注意:WEB服务器和数据库需要分离,同时WEB服务器也需要编译安装MySQL. 做集群架构的重要思想就是找到主干,从主干区域向外延展. WEB服务器: apache nginx  本地做三个产品 de ...

  2. CentOS7-自动化部署web集群

    一.项目要求 1.创建role,通过role完成项目(可能需要多个role) 2.部署nginx调度器(node2主机) 3.部署2台lnmp服务器(node3,node4主机) 4.部署mariad ...

  3. Centos 7 部署lnmp集群架构

    前言介绍 lnmp的全程是 linux + nginx + mysql + php; lnmp就是上述系统及应用程序的简写组合: lnmp其实已经代表了一个用户正常对一个页面请求的流程,nginx接收 ...

  4. (二)Kubernetes kubeadm部署k8s集群

    kubeadm介绍 kubeadm是Kubernetes项目自带的及集群构建工具,负责执行构建一个最小化的可用集群以及将其启动等的必要基本步骤,kubeadm是Kubernetes集群全生命周期的管理 ...

  5. Ansible自动化部署K8S集群

    Ansible自动化部署K8S集群 1.1 Ansible介绍 Ansible是一种IT自动化工具.它可以配置系统,部署软件以及协调更高级的IT任务,例如持续部署,滚动更新.Ansible适用于管理企 ...

  6. 003 ansible部署ceph集群

    介绍:在上一次的deploy部署ceph,虽然出了结果,最后的结果并没有满足最初的目的,现在尝试使用ansible部署一遍,看是否会有问题 一.环境准备 ceph1充当部署节点,ceph2,ceph3 ...

  7. ansible playbook部署ELK集群系统

    一.介绍 总共4台机器,分别为 192.168.1.99 192.168.1.100 192.168.1.210 192.168.1.211 服务所在机器为: redis:192.168.1.211 ...

  8. kubernetes系列03—kubeadm安装部署K8S集群

    本文收录在容器技术学习系列文章总目录 1.kubernetes安装介绍 1.1 K8S架构图 1.2 K8S搭建安装示意图 1.3 安装kubernetes方法 1.3.1 方法1:使用kubeadm ...

  9. 实战Centos系统部署Codis集群服务

    导读 Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可 ...

  10. 《跟老男孩学Linux运维:Web集群实战》读书笔记

    Linux 介绍 Linux 安装 Linux 调优 Web 基础 Nginx 应用 LNMP 应用 PHP 缓存加速 Nginx 调优 MySQL 应用 NFS 网络文件共享 Nginx 反向代理与 ...

随机推荐

  1. 14 JavaScript神奇的windows

    14 神奇的windows window对象是一个很神奇的东西. 你可以把这东西理解成javascript的全局. 如果我们默认不用任何东西访问一个标识符. 那么默认认为是在用window对象. 例如 ...

  2. 你真的了解java class name吗?

    在面向对象的世界,Class是java的基础.java.lang.Class实际上是继承自java.lang.Object. class有一个方法叫做getName,该方法会返回(class, int ...

  3. OpenHarmony社区运营报告(2022年11月)

    本月快讯 • 11月24日,第二十届中日韩三国IT局长OSS会议暨东北亚开源软件推进论坛以在线形式成功召开.经审核评选认定,OpenAtom OpenHarmony(以下简称"OpenHar ...

  4. 8. Linear Transformations

    8.1 Linear Requires Keys: A linear transformation T takes vectors v to vectors T(v). Linearity requi ...

  5. PMF源解析技术在大气颗粒物与VOCs研究中的创新应用

    目前,大气颗粒物和臭氧污染成为我国亟待解决的环境问题.颗粒物和臭氧污染不仅对气候和环境有重要影响,而且对人体健康有严重损害.而臭氧的前体物之一为挥发性有机物(VOCs).为了高效.精准地治理区域大气颗 ...

  6. Linux之openssl实现私有CA

    一.简介 Centos7.9通过openssl工具构建一个私有的CA,用于颁发证书. 验证私有CA为httpd应用签署证书 二.构建私有CA 1.编辑CA的配置文件 [root@HLWHOST tls ...

  7. Win7 局域网服务器 - FTP 服务器搭建指南

    1. 打开 "开始" 菜单,找到控制面板 2. 选择 "程序" 3. 选择 "打开或关闭 Windows 功能" 4. 选择 "I ...

  8. Harbor高可用集群设计及部署(基于离线安装方式)

    原文转自:Harbor高可用集群设计及部署(基于离线安装方式) 架构至美 2022-09-05 09:28 发表于北京 编者荐语: 纯干货.实用,推荐系数5颗星. 以下文章来源于Harbor进阶实战  ...

  9. android 关于插件包内的依赖版本不一致问题得解决

    前言 今天使用一个插件包的时候,依赖包冲突了,在此记录一下. 正文 在引用一个: debugImplementation 'com.squareup.leakcanary:leakcanary-and ...

  10. ActiveMQ c# 系列——进阶实例(三)

    前言 前面介绍了基本的消费者和生产者,那么看下他们之间有什么其他的api. 正文 消费者设置等待时间 生产者生产了5条消息 改一下消费者. static void Main(string[] args ...