您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程

ansible部署lnmp和wordpress的步骤方法

尔岚2025-03-29WordPress教程已有人查阅

导读如上,是项目的目录结构。common: 获取阿里云的yum源mysql: 二进制安装mysqlnginx: 编译安装nginxphp-fpm:编译安装php-fpmwordpress: 获取wordpress源码,更改部分值。

如上,是项目的目录结构。
common: 获取阿里云的yum源
mysql: 二进制安装mysql
nginx: 编译安装nginx
php-fpm:编译安装php-fpm
wordpress: 获取wordpress源码,更改部分值。
1,首先查看入口文件。
---
- name: Install WordPress, MySQL, Nginx, and PHP-FPM
hosts: all
remote_user: root
# remote_user: user
# become: yes
# become_method: sudo
roles:
- role: common
- role: mysql
tags: ["mysql"]
- role: nginx
tags: ["nginx"]
- role: php-fpm
tags: ["php-fpm"]
- role: wordpress
tags: ["wordpress"]
2,查看hosts
[wordpress]
192.168.1.137
3, 查看group_vars下的变量
---
# Mysql version
mysql_version: 5.5.60
basedir: /usr/local/mysql
datadir: /data/mysql
#Nginx var
tarball_name: nginx-1.10.3.tar.gz
nginx_dir: nginx-1.10.3
http_port: 80
server_name:.linsir.cn
# Which version of WordPress to deploy
wp_version: 4.2.4
wp_sha256sum: 42ca594afc709cbef8528a6096f5a1efe96dcf3164e7ce321e87d57ae015cc82
# These are the WordPress database settings
wp_db_name: wordpress
wp_db_user: wordpress
wp_db_password: secret
# You shouldn't need to change this.
mysql_port: 3306
# This is used for the nginx server configuration, but access to the
# WordPress site is not restricted by a named host.
# Disable All Updates
# By default automatic updates are enabled, set this value to true to disable all automatic updates
auto_up_disable: false
#Define Core Update Level
#true = Development, minor, and major updates are all enabled
#false = Development, minor, and major updates are all disabled
#minor = Minor updates are enabled, development, and major updates are disabled
core_update_level: true
4,查看roles下的各个角色,根据site.yml文件中的顺序展开
1, common主要是获取repo源用的
---
- name: Del repo for system
shell:
rm -f /etc/yum.repos.d/Cento-Base.repo && rm -f /etc/yum.repos.d/epel.repo
- name: Get repo centos6 for alibaba
get_url:
url: http://mirrors.aliyun.com/repo/Centos-6.repo
dest: /etc/yum.repos.d/CentOS-Base.repo
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
- name: Get repo centos7 for alibaba
get_url:
url: http://mirrors.aliyun.com/repo/Centos-7.repo
dest: /etc/yum.repos.d/CentOS-Base.repo
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
- name: Get epel repo cenots6 for alibaba
get_url:
url: http://mirrors.aliyun.com/repo/epel-6.repo
dest: /etc/yum.repos.d/epel.repo
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
- name: Get epel repo cenots7 for alibaba
get_url:
url: http://mirrors.aliyun.com/repo/epel-7.repo
dest: /etc/yum.repos.d/epel.repo
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
2,查看mysql角色
---
- name: Create mysql user
user:
name: mysql
- name: Download mysql
get_url:
url:
dest: /usr/local/src
- name: Unzip mysql
unarchive:
src: /usr/local/src/mysql-{{mysql_version}}-linux-glibc2.12-x86_64.tar.gz
dest: /usr/local/src/
copy: no
- name: Rename mysql
shell:
mv /usr/local/src/mysql-{{mysql_version}}-linux-glibc2.12-x86_64 /usr/local/mysql && chown -R mysql:mysql {{basedir}}
- name: Create data storage
file:
path: /data/mysql
state: directory
owner: mysql
group: mysql
- name: Init mysql
shell:
./scripts/mysql_install_db --user=mysql --basedir={{basedir}} --datadir={{datadir}}
args:
chdir: "{{basedir}}"
- name: Create mysql script for centos6
shell:
cp "{{basedir}}/support-files/mysql.server" /etc/init.d/mysqld && chmod 755 /etc/init.d/mysqld
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
- name: Create mysql script for centos7
copy:
src: mysqld.service
dest: /usr/lib/systemd/system/mysqld.service
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
notify:
- Reload service
- meta: flush_handlers
- name: Copy mysql config
template:
src: my.cnf.j2
dest: /etc/my.cnf
- name: Restart mysqld
service:
name: mysqld
state: restarted
register: result
#根据服务器配置不同,mysql启动速度有所区别。
- name: sleep 10s
shell:
sleep 20
- name: Copy root password file
shell:
/usr/local/mysql/bin/mysqladmin -uroot password linlin

本文标签:

很赞哦! ()

相关源码

  • (自适应)刷卡pos机数据移动支付设备电子科技pbootcms模板下载本模板为POS机设备制造商、移动支付终端服务商和科技企业设计,基于PbootCMS系统开发,提供完整的在线展示平台解决方案,满足支付设备行业特有的展示需求。查看源码
  • (自适应)调节阀门气动球阀控制阀网站模板源码下载为调节阀门、气动球阀等工业设备企业打造的响应式网站模板,基于PbootCMS系统开发。突出产品参数展示与技术文档管理功能,通过专业化的布局设计有效呈现工业设备特性,适配各类终端访问需求。查看源码
  • 帝国cms自适应古诗词古籍名句网站整站带数据基于帝国CMS打造的专业古诗词文化网站模板,专注于古典文学内容的展示与传播。模板设计蕴含传统文化韵味,支持诗词鉴赏、名句赏析、古籍整理等特色功能,为诗词爱好者提供优质的在线阅读体验。查看源码
  • 帝国cms7.5大型游戏资讯门户网站源码免费下载本模板基于帝国CMS7.5内核开发,为大型游戏资讯门户网站设计。模板自带响应式手机版,适配多种终端设备。内容架构针对游戏行业特点优化,支持游戏资讯、评测、攻略等内容类型的发布与管理。查看源码
  • 自适应黑色建筑装饰设计公司个人工作室pbootcms模板基于PbootCMS内核开发的黑金风格模板,为建筑装饰、工程设计类企业打造,采用‌开源架构‌,支持跨行业快速适配,核心优势如下: 查看源码
  • (自适应多语言)WordPress开源主题MirageV资讯个人博客源码MirageV资讯类个人博客主题源码/WordPress主题/全开源MirageV 是一款开源的 WordPress 主题,支持自适应、暗黑模式、多语言等功能,查看源码
分享笔记 (共有 篇笔记)
验证码: