本文主要是介绍linux系统ansible工具的剧本发布workpress剧本编写,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
发布workpress
整体剧本编写
准备环境
上传workpress压缩包到/root目录编写/root/nginx.conf文件,下面代码写入http模块的server中
vim /root/nginx.conflocation / {root /usr/share/nginx/html/wordpress/;index index.php index.html index.htm;}
location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/wordpress/$fastcgi_script_name;include fastcgi_params;}
剧本编写
vim workpress.yaml---
- hosts: 10.12.153.110remote_user: rootvars:tasks:- name: 安装数据库yum: name=mariadb-server,mariadb state=present- name: 安装phpyum: name=http://rpms.remirepo.net/enterprise/remi-release-7.rpm state=present - name: 安装phpyum: name=php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm state=present- name: 安装nginxyum: name=epel-release,nginx state=present- name: 启动环境service: name=nginx state=started enabled=yes- name: 启动环境service: name=php80-php-fpm state=started enabled=yes- name: 启动数据库service: name=mariadb state=started enabled=yes- name: 创建用户并授权shell: mysql -e "create database wordpress;grant all on wordpress.* to 'wordpress'@'localhost' identified by '0';grant all on wordpress.* to 'wordpress'@'%' identified by '0';flush privileges"- name: 拷贝nginx配置文件template: src=/root/nginx.conf dest=/etc/nginx/nginx.conf backup=yes- name: 安装解压工具yum: name=unzip state=present- name: 上传wordpress源码包unarchive: src=wordpress-6.2.2-zh_CN.tar.gz dest=/usr/share/nginx/html mode=777 owner=nginx group=nginx- name: 重启nginxservice: name=nginx state=restarted
浏览器安装workpress
数据库名字:workpress
用户名字:workpress
用户密码:0
数据库地址:数据库安装的服务器ip
角色剧本编写
ansible-galaxy init php
ansible-galaxy init mariadb
ansible-galaxy init nginx
ansible-galaxy init wordpress
touch roles.yaml
roles.yaml
vim roles.yaml---
- hosts: ipremote_user: rootroles:- nginx- php- mariadb- wordpress#如果需要数据库和web分离可以这样写
#---
#- hosts: web端ip
# remote_user: root
# roles:
# - nginx
# - php
# - wordpress
#- hosts: db端ip
# remote_user: root
# roles:
# - mariadb
php目录
vim php/tasks/main.yml ---
# tasks file for php
- name: 卸载phpyum: name=php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm state=absent- name: 安装php源yum: name=http://rpms.remirepo.net/enterprise/remi-release-7.rpm state=present- name: 安装phpyum: name=php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm state=present- name: 启动环境service: name=php80-php-fpm state=started enabled=yes
nginx目录
vim nginx/template/nginx.comfworker_processes 1;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name localhost;location / {root /usr/share/nginx/html/wordpress/;index index.php index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/wordpress/$fastcgi_script_name;include fastcgi_params;}}
}
vim nginx/tasks/main.yml ---
# tasks file for nginx
- name: 卸载nginxyum: name=nginx state=absent
- name: 安装nginxyum: name=epel-release,nginx state=present
- name: 拷贝nginx.conf文件template: src=nginx.conf dest=/etc/nginx/nginx.conf backup=yes
- name: 启动nginxservice: name=nginx state=started
mariadb目录
vim mariadb/tasks/main.yml ---
# tasks file for mariadb
- name: 卸载数据库yum: name=mariadb-server,mariadb state=absent
- name: 安装数据库yum: name=mariadb-server,mariadb state=present
- name: 启动数据库service: name=mariadb state=started enabled=yes
- name: 删除数据库shell: mysql -e "drop database wordpress;"
- name: 创建用户并授权shell: mysql -e "create database wordpress;grant all on wordpress.* to 'wordpress'@'localhost' identified by '0';grant all on wordpress.* to 'wordpress'@'%' identified by '0';flush privileges"
wordpress目录
上传wordpress压缩包到wordpress/files/
vim wordpress/tasks/main.yml ---
# tasks file for wordpress
- name: 安装工具yum: name=unzip state=present
- name: 上传wordpress源码包unarchive: src=wordpress-6.2.2-zh_CN.tar.gz dest=/usr/share/nginx/html mode=777 owner=nginx group=nginx
浏览器安装workpress
数据库名字:workpress
用户名字:workpress
用户密码:0
数据库地址:数据库安装的服务器ip
这篇关于linux系统ansible工具的剧本发布workpress剧本编写的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!