热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ansible一键部署lnvamp

lnvamp的意思是Linux(centos7.2),Nginx,varnish,Apache,MySQL,PHP。我在这个平台之上构建的discuz论坛,我写了一个roles来实

     lnvamp的意思是Linux(centos7.2),Nginx,varnish,Apache,MySQL,PHP。我在这个平台之上构建的discuz论坛,我写了一个roles来实现,这个脚本很不健壮幂等性不足,需要大量的判断继续完善,由于时间原因我就不继续完善了,先把草稿贴出来。同时这个脚本的复用性也不好,基本上没有使用变量,后期会慢慢改善。

     架构图如下

技术分享技术分享

nginx提供反向代理,安装nginx

varnish提供缓存,安装varnish

server提供页面处理,安装httpd,php,php-mysql,nfs-utils

file提供数据库和网页文件,安装mysql-server,mysql-python,nfs-utils


file的ansible内容写法

注意

    因为手头没有主机了,这里file主机我使用的是centos6

     mysql-python没有对应的rpm包,由于考虑幂等性的原因这里我没有使用ansible来完成,我在宿主机上执行的,这里我们只好手动编译,手动编译脚本如下

yum install python-devel mysql-devel zlib-devel openssl-devel -y
yum groupinstall development tools -y
wget https://pypi.python.org/packages/9a/81/924d6799494cf7fb24370335c2f782088d6ac4f79e4137d4df94cea3582c/MySQL-python-1.2.3.tar.gz
tar xf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py install

vim roles/filesystem/tasks/main.yml

- name: copy wordpress files
  copy: src=Discuz_X3.2_SC_UTF8.zip dest=/
- name: unzip wordpress files
  command: unzip /Discuz_X3.2_SC_UTF8.zip -d /
- name: chmod wordpress files
  command: chown -R apache:apache /wordpress
- name: copy nfs file
#- name: share wordpress files
#  file: dest=/wordpress mode=766 owner=root group=root state=directory
- name: copy wordpress files
  copy: src=Discuz_X3.2_SC_UTF8.zip dest=/
- name: unzip wordpress files
  command: unzip /Discuz_X3.2_SC_UTF8.zip -d /
- name: chmod wordpress files
  command: chown -R apache:apache /wordpress
- name: copy nfs file
  copy: src=exports dest=/etc/exports
- name: install nfs-utils
  yum: name=nfs-utils state=present
- name: start nfs server
  service: name=nfs state=started enabled=true
- name: install mysql-server
  yum: name=mysql-server state=present
- name: start mysql server
  service: name=mysqld state=started enabled=true
#- name: install mysql-python
#  yum: name=mysql-server state=present
- name: Create a new database with name ‘wpdb‘
  mysql_db: name=wpdb state=present
- name: Copy database sqlfile
  copy: src=grant.sql dest=/tmp
- name: Restore database
  mysql_db:
    name: wpdb
    state: import
    target: /tmp/grant.sql

vim roles/filesystem/files/exports

/wordpress 172.16.0.0/16(rw,no_root_squash)

vim roles/filesystem/files/grant.sql

grant all privileges on wpdb.* to wpuser@‘172.16.29.%‘identified by "wpprass";

server的ansible内容写法

vim roles/amp/tasks/main.yml

- name: install httpd
  yum: name=httpd state=present
- name: install php
  yum: name=php state=present
- name: install php-mysql
  yum: name=php-mysql state=present
- name: install nfs-utils
  yum: name=nfs-utils state=present
- file:
    path: /wordpress
    owner: apache
    group: apache
    state: directory
    mode: 0750
- name: copy fstab file
  copy: src=fstab dest=/etc/fstab
- name: copy http file
  copy: src=httpd.conf dest=/etc/httpd/conf/httpd.conf
- name: mount wordpress files
  command: mount -a
- name: start httpd server
  service: name=httpd state=started enabled=true

vim roles/amp/files/httpd.conf

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

    AllowOverride none
    Require all denied

DocumentRoot "/wordpress/upload"

    AllowOverride None
    Require all granted


    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted


    DirectoryIndex index.php index.html


    Require all denied

ErrorLog "logs/error_log"
LogLevel warn

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    
    CustomLog "logs/access_log" combined


    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"


    AllowOverride None
    Options None
    Require all granted


    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8

    MIMEMagicFile conf/magic

EnableSendfile on
IncludeOptional conf.d/*.conf

vim roles/amp/files/fstab

UUID=098eb04e-16b2-4c66-8a02-943994f669cb /                       xfs     defaults        0 0
UUID=ddf83638-3fbf-48a6-8633-05e869a5dad1 /boot                   xfs     defaults        0 0
/dev/sda3   swap swap defaults 0 0
172.16.29.1:/wordpress /wordpress nfs defaults 0 0

nginx的ansible内容写法


vim roles/nginx/tasks/main.yml

- name: install nginx
  yum: name=nginx state=present
- name: copy nignx.conf file
  copy: src=nginx.conf dest=/etc/nginx/nginx.conf
- name: start nginx server
  service: name=nginx state=started enabled=true

 

vim roles/nginx/files/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    upstream websrvs {
        server 172.16.29.10:80;
        server 172.16.29.20:80;
        ip_hash;
    }
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            proxy_pass http://172.16.29.30;
            proxy_set_header Host $host;
            proxy_set_header   X-Real-IP    $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}


varnish的ansible内容写法


vim roles/varnish/tasks/main.yml

- name: install varnish
  yum: name=varnish state=present
- name: copy varnish.params file
  copy: src=varnish.params dest=/etc/varnish/varnish.params
- name: copy default.vcl file
  copy: src=default.vcl dest=/etc/varnish/default.vcl
- name: start varnish server
  service: name=varnish state=started enabled=true
vim roles/varnish/files/varnish.params
RELOAD_VCL=1
VARNISH_VCL_COnF=/etc/varnish/default.vcl
VARNISH_LISTEN_PORT=80
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_STORAGE="malloc,512m"
VARNISH_TTL=120
VARNISH_USER=varnish
VARNISH_GROUP=varnish
vim roles/varnish/files/default.vcl

vcl 4.0;
import directors;
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}
probe check {
    .url = "/robots.txt";
    .window = 5;
    .threshold = 3;
    .interval = 2s;
    .timeout = 1s;
}
backend server1 {
    .host = "172.16.29.10";
    .port = "80";
    .probe = check;
}
backend server2 {
    .host = "172.16.29.20";
    .port = "80";
    .probe = check;
}
sub vcl_init {
    new static = directors.round_robin();
    static.add_backend(server1);
    static.add_backend(server2);
}
sub vcl_recv {
    set req.backend_hint = static.backend();
}
sub vcl_backend_response {
}
sub vcl_deliver {
}



调用roles的ansible内容写法


file主机的ansible调用方法

vim file.yml
---
- hosts: file
  roles:
    - filesystem

server主机的ansible调用方法

vim amp.yml
---
- hosts: lamp
  roles:
    - amp

nginx主机的ansible调用方法

vim nginx.yml
---
- hosts: nginx
  roles:
    - nginx

varnish主机的ansible调用方法

vim varnish.yml
---
- hosts: varnish
  roles:
    - varnish



总结

     这个实验基本上没有说原理和操作步骤,只是简单罗列文件,最后我把我编写的完整roles的下载路径过一天补上,已经上传等待审核

技术分享


本文出自 “老王linux旅程” 博客,请务必保留此出处http://oldking.blog.51cto.com/10402759/1896183

ansible一键部署lnvamp


推荐阅读
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了关于apache、phpmyadmin、mysql、php、emacs、path等知识点,以及如何搭建php环境。文章提供了详细的安装步骤和所需软件列表,希望能帮助读者解决与LAMP相关的技术问题。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
author-avatar
统计小屋_321
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有