您现在的位置是:首页 > 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

本文标签:

很赞哦! ()

相关源码

  • (PC+WAP)蓝色五金机械设备营销型网站源码下载基于PbootCMS内核开发的营销型企业网站模板,为五金机械设备类企业打造,通过标准化数字展示提升客户转化率。模板采用模块化设计,可快速适配机床工具、建筑五金、阀门管件等细分领域。查看源码
  • pbootcms源码宠物类网站源码下载(自适应多端)为宠物装备商店、宠物食品及用品企业打造的营销型模板,基于PbootCMS内核深度开发。采用响应式设计实现PC与移动端适配,PHP7.0+高性能架构支持MySQL/SQLite双数据库查看源码
  • (自适应响应式)蓝色律师事务所法务团队网站pbootcms模板为律师事务所和法律服务机构打造的专业网站模板,展现法律专业性与权威性,手工编写标准DIV+CSS代码,结构清晰优化,确保高效运行,自动适配电脑、平板和手机等各类设备,提供更好浏览体验查看源码
  • 自适应LED照明外贸灯具灯泡灯具英文网站模板该外贸灯具网站模板专为LED照明、灯具出口企业定制,采用PbootCMS内核开发,提供高效建站方案。通过响应式设计和SEO优化能力,帮助企业低成本构建专业外贸展示平台。查看源码
  • (自适应)中英双语配线器材扎带线卡网站pbootcms模板免费下载为线缆管理、电气配线领域打造的响应式网站模板,采用PbootCMS内核开发,可快速搭建企业级产品展示平台,数据实时同步管理。查看源码
  • (自适应响应式)英文外贸汽车零配件五金机械网站模板为汽车零部件制造商与五金机械出口企业打造的响应式网站模板,内置多语言切换功能,支持产品参数表、OEM能力展示等外贸场景需求。通过结构化数据展示帮助海外买家快速理解产品规格。查看源码
分享笔记 (共有 篇笔记)
验证码: