ansible - 安装 -【kodcloud教程】

news2024/11/18 18:13:18

目录

目录结构、主机清单

【1】安装基础环境

【2】webserver - 安装nginx

【3】安装php环境

【4】lb-server

【5】redis安装

【6】 kodcloud

【7】wordpress-proxy 


 

ansible10.0.0.10
lb-server10.0.0.11
web0110.0.0.15
web0210.0.0.16
redis10.0.0.20

目录结构、主机清单

[root@ansible ~]# mkdir -p ansible/roles/
[root@ansible ~]# cd ansible/roles/
[root@ansible roles]# mkdir -p {nginx,php-fpm,redis}/{tasks,templates,handlers,file

[root@ansible roles]# mkdir -p basic/{tasks,templates,handlers,files}
[root@ansible roles]# mkdir group_vars


[root@ansible roles]#  egrep "^[a-Z]" ansible.cfg 
inventory      = ./hosts
forks          = 5

[root@ansible roles]# grep  "^[^#]" hosts 
[lb-server]
10.0.0.11
[webserver]
10.0.0.15
10.0.0.16
[redis]
10.0.0.20

【1】安装基础环境

[root@ansible roles]# cat basic/tasks/main.yml 
- name: Install Nginx Repo
  yum_repository:
    name: ansible_nginx
    description: ansible_nginx_repo
    baseurl: http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck: no
    gpgkey: https://nginx.org/keys/nginx_signing.key
  when: ( ansible_hostname is match ("web*") or ansible_hostname is match ("lb*") )

- name: PHP Reop
  yum_repository:
    name:  ansible_php
    description: ansible_php_repo
    baseurl: http://us-east.repo.webtatic.com/yum/el7/x86_64/
    gpgcheck: no
  when: ( ansible_hostname is match ("web*") )

- name: epel
  yum:
    name: epel-release.noarch
    state: present

- name: Install Basices
  yum:
    name: "{{ item }}"
    state: present
  loop:
    - vim
    - wget
    - make
    - automake
    - lrzsz
    - tree
    - net-tools
    - nfs-utils
    - rsync
    - ntpdate
    - unzip
    - zip

- name: Disabled Firewall
  systemd:
    name: firewalld
    state: stopped
    enabled: no

- name: Disabled Selinux
  selinux:
    state: disabled

- name: Create Group
  group:
    name: "{{ group }}"
    gid: "{{ id }}"

- name: Create User
  user:
    name: "{{ user }}"
    uid: "{{ id }}"
    group: "{{ id }}"
    shell: /sbin/nologin
    create_home: no

- name: Code Dir
  file:
    path: "{{ Code_path }}"
    owner: "{{ user }}"
    group: "{{ group }}"
    state: directory
    mode: '0755'
    recurse: yes
[root@ansible roles]# cat kod.yml 
- hosts: all
  roles:
    - role: basic

【2】webserver - 安装nginx

  • tasks任务
- name: Install Nginx
  yum:
    name: nginx
    state: present

- name: MV Default
  shell:
    cmd: mv /etc/nginx/conf.d/default.conf{,.bak}
    creates: /etc/nginx/conf.d/default.conf.bak

- name: Configure Nginx-conf
  template:
    src: "{{ item.src }}"
    dest:  "{{ item.dest }}"
  loop:
    - { src: 'nginx.conf.j2', dest: '/etc/nginx/nginx.conf' }
  notify: Restart Nginx

- name: Start Nginx
  systemd:
    name: nginx
    state: started
    enabled: yes
  •  触发器
[root@ansible roles]# cat nginx/handlers/main.yml 
- name: Restart Nginx
  systemd:
    name: nginx
    state: restarted
  • 变量文件
[root@ansible roles]# cat group_vars/all 
## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"
  •  nginx配置文件
[root@ansible roles]# ls nginx/templates/
nginx.conf.j2

[root@ansible roles]# cat nginx/templates/nginx.conf.j2 
user  {{ user }};
worker_processes  {{ ansible_processor_vcpus }};

error_log  {{ ng_log }}/error.log notice;
pid        {{ ng_pid }}/nginx.pid;

events {
    worker_connections  {{ work_conn }};
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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  {{ ng_log }}/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
  • 主机清单
[root@ansible roles]# cat kod.yml 
#- hosts: all
#  roles:
#    - role: basic

- hosts: webserver
  roles:
    - role: nginx

【3】安装php环境

  • tasks
[root@ansible roles]# cat php-fpm/tasks/main.yml 
- name: Install PHP
  yum:
    name: "{{ item }}"
    state: present
  loop:
    - php71w
    - php71w-cli
    - php71w-common
    - php71w-devel
    - php71w-embedded
    - php71w-gd
    - php71w-mcrypt
    - php71w-mbstring
    - php71w-pdo
    - php71w-xml
    - php71w-fpm
    - php71w-mysqlnd
    - php71w-opcache
    - php71w-pecl-memcached
    - php71w-pecl-redis
    - php71w-pecl-mongodb

- name: Configure 
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: "{{ item.owner }}"
    group: "{{ item.group }}"
    mode: "{{ item.mode }}"
  loop:
    - { src: 'www.conf.j2', dest: '/etc/php-fpm.d/www.conf', mode: '0644', owner: 'root', group: 'root' }
    - { src: 'php.ini.j2', dest: '/etc/php.ini', mode: '0644', owner: 'root', group: 'root' }
  notify: Restart PHP-FPM

- name: Start PHP
  systemd:
    name: php-fpm
    state: started
    enabled: yes
  • handlers
[root@ansible roles]# cat php-fpm/handlers/main.yml 
- name: Restart PHP-FPM
  systemd:
    name: php-fpm
    state: restarted
  • templates
[root@ansible roles]# ls php-fpm/templates/
php.ini.j2   www.conf.j2

[root@ansible roles]# cat php-fpm/templates/www.conf.j2 
[www]
user = {{ user }}
group = {{ group }}
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache

[root@ansible roles]# grep "redis" php-fpm/templates/php.ini.j2 
session.save_handler = redis
session.save_path = "tcp://{{ redis_ip }}:{{ redis_port }}?&weight=1&timeout=2.5"
  • 变量文件
[root@ansible roles]# cat group_vars/all 
## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"

## redis
redis_ip: "10.0.0.20"
redis_port: "6379"
  • 主机清单
[root@ansible roles]# cat kod.yml 
#- hosts: all
#  roles:
#    - role: basic

- hosts: webserver
  roles:
#    - role: nginx
    - role: php-fpm

【4】lb-server

[root@ansible roles]# mkdir -p lb-server/{tasks,templates,handlers}

[root@ansible roles]# cat lb-server/tasks/main.yml 
- name: Install Nginx
  yum:
    name: nginx
    state: present

- name: MV Default
  shell:
    cmd: mv /etc/nginx/conf.d/default.conf{,.bak}
    creates: /etc/nginx/conf.d/default.conf.bak

- name: Configure Nginx-conf
  template:
    src: "{{ item.src }}"
    dest:  "{{ item.dest }}"
  loop:
    - { src: 'nginx.conf.j2', dest: '/etc/nginx/nginx.conf' }
  notify: Restart Nginx

- name: Start Nginx
  systemd:
    name: nginx
    state: started
    enabled: yes
  • handlers 
[root@ansible roles]# cat lb-server/handlers/main.yml 
- name: Restart Nginx
  systemd:
    name: nginx
    state: restarted
  •  templates
[root@ansible roles]# cat lb-server/templates/nginx.conf.j2 
user  {{ user }};
worker_processes  {{ ansible_processor_vcpus }};

error_log  {{ ng_log }}/error.log notice;
pid        {{ ng_pid }}/nginx.pid;

events {
    worker_connections  {{ work_conn }};
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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  {{ ng_log }}/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
  • 变量文件
[root@ansible roles]# cat group_vars/all 
## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"

## redis
redis_ip: "10.0.0.20"
redis_port: "6379"
  • 主机清单
[root@ansible roles]# cat kod.yml 
#- hosts: all
#  roles:
#    - role: basic

#- hosts: webserver
#  roles:
#    - role: nginx
#    - role: php-fpm

- hosts: lb-server
  roles:
    - role: lb-server

【5】redis安装

  • tasks
[root@ansible roles]# cat redis/tasks/main.yml 
- name: Install Redis
  yum:
    name: redis
    state: present

- name: Configure Redis
  template:
    src: redis.conf.j2
    dest: /etc/redis.conf
    owner: redis
    group: root
    mode: '0640'
  notify: Restart Redis

- name: Start Redis
  systemd:
    name: redis
    state: started
    enabled: yes
  • handlers
[root@ansible roles]# cat redis/handlers/maim.yml 
- name: Restart Redis
  systemd:
    name: redis
    state: restarte
  • templates
[root@ansible roles]# grep "^bind" redis/templates/redis.conf.j2 
bind 127.0.0.1 {{ ansible_eth0.ipv4.address }}
  • 变量文件
[root@ansible roles]# cat group_vars/all 
## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"

## redis
redis_ip: "10.0.0.20"
redis_port: "6379"
  • 主机清单
[root@ansible roles]# cat kod.yml 
#- hosts: all
#  roles:
#    - role: basic

#- hosts: webserver
#  roles:
#    - role: nginx
#    - role: php-fpm

#- hosts: lb-server
#  roles:
#    - role: lb-server

- hosts: redis
  roles:
    - role: redis

【6】 kodcloud

  • tasks
[root@ansible roles]# mkdir -p kod/{tasks,handlers,templates,meta,files}

[root@ansible roles]# vim kod/tasks/main.yml
- name: Copy {{ url }} Nginx
  template:
    src: kod.conf.j2
    dest: /etc/nginx/conf.d/kod.conf
  notify: Restart Nginx

- name: Kodcloud Code
  unarchive:
    src: kodbox.1.31.zip
    dest:  "{{ Code_path }}"
    owner: "{{ user }}"
    group: "{{ group }}"
    creates: "{{ Code_path }}/index.php"
  •  meta依赖
dependencies:
  - { role: nginx }
  - { role: php-fpm }
  • template
[root@ansible roles]# vim kod/templates/kod.conf.j2 
server {
  listen 80;
  server_name {{ kod_url }};
    root {{ Code_path }};
  location / {
    index index.php;
  }
  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}
  • handlers
[root@ansible roles]# vim kod/handlers/main.yml
- name: Restart Nginx
  systemd:
    name: nginx
    state: restarte
  • 变量文件
[root@ansible roles]# vim group_vars/all 

## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"

## redis
redis_ip: "10.0.0.20"
redis_port: "6379"
  • 主机清单
[root@ansible roles]# cat kod.yml 
#- hosts: all
#  roles:
#    - role: basic

- hosts: webserver
  roles:
#    - role: nginx
#    - role: php-fpm
    - role: kod

#- hosts: lb-server
#  roles:
#    - role: lb-server

#- hosts: redis
#  roles:
#    - role: redis

【7】wordpress-proxy 

tasks

[root@ansible roles]# mkdir -p kod-proxy/{tasks,files,templates,handlers,meta}

[root@ansible roles]# vim kod-proxy/tasks/main.yml 
- name: Proxy Configure
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
  loop:
    - { src: 'lb-kod.conf.j2', dest: '/etc/nginx/conf.d/lb-kod.conf' }
    - { src: 'proxy_params.j2', dest: '/etc/nginx/proxy_params' }
  notify: Restart Nginx

 handlers

[root@ansible roles]# cat kod-proxy/handlers/main.yml 
- name: Restart Nginx
  systemd:
    name: nginx
    state: restarted

templates

[root@ansible roles]# cat kod-proxy/templates/
lb-kod.conf.j2   proxy_params.j2

[root@ansible roles]# cat kod-proxy/templates/lb-kod.conf.j2 
upstream kod {
{% for host in groups['webserver'] %}
  server {{ host }};
{%endfor%}
}
server {
  listen 80;
  server_name {{ kod_url }};
  location / {
    proxy_pass http://kod;
    include proxy_params;
  }
}

[root@ansible roles]# cat kod-proxy/templates/proxy_params.j2 
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_connect_timeout 60s;      # nginx连接后端的超时时间
proxy_read_timeout 60s;         # 响应头部超时时间
proxy_send_timeout 60s;         # 响应数据主体的超时时间
proxy_buffering on;             # 开启缓冲区
proxy_buffer_size 8k;           # 缓冲区Header大小
proxy_buffers 4 64k;            # 缓冲区数量 * 大小 = 最大接收

meta

[root@ansible roles]# cat kod-proxy/meta/main.yml 
dependencies:
  - { role: nginx }

变量文件

[root@ansible roles]# vim group_vars/all
## Basices
group: "www"
id: "666"
user: "www"


## Code Dir
Code_path: "/code/kod"

## webserver
ng_log: "/var/log/nginx"
ng_pid: "/var/run"
work_conn: "1024"
kod_url: "www.kod-test.org"

## redis
redis_ip: "10.0.0.20"
redis_port: "6379"

主机清单

[root@ansible roles]# vim kod.yml 
#- hosts: all
#  roles:
#    - role: basic

#- hosts: webserver
#  roles:
#    - role: nginx
#    - role: php-fpm
#    - role: kod
#    - role: kod-proxy

- hosts: lb-server
  roles:
#    - role: lb-server
    - role: kod-proxy

#- hosts: redis
#  roles:
#    - role: redis

 

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/694712.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[python][yolov7][深度学习]将yolov7实例分割成一个类几句代码完成实例分割任务

大家都知道,yolov7目前支持图像分类、目标检测和实例分割,而实例分割一般都是用predict.py去预测图片这个如果要引入pyqt5或着嵌入其他python模块有点麻烦,因此需要封装一个类去预测图像,这样我们可以轻松完成各种实例分割任务,封…

virtualbox安装已有的虚拟硬盘文件

按照网上安装virtualbox虚拟机操作,我是安装已有的虚拟硬盘文件。 名称是虚拟机的名称,文件夹是虚拟机安装的文件夹建议大一点。 分配内存: 对于第一次安装已有的vdi虚拟硬盘文件,这里并没有任何显示(我下面已经添…

EA代码逆向工程

下载安装 链接:https://pan.baidu.com/s/1xQ2q-_cSt_DTI3zIDvxkFw 提取码:wq83 使用教程: 构建类图 打开EA,点击左上角的图标新建项目。 起一个项目名称,"逆向工程测试"。 新建好后的页面: …

Bootstrap 网格系统

文章目录 Bootstrap 网格系统什么是网格(Grid)?什么是 Bootstrap 网格系统(Grid System)?移动设备优先策略内容布局渐进增强 Bootstrap 网格系统(Grid System)的工作原理媒体查询网格…

自学黑客(网络安全),一般人我劝你还是算了吧(自学网络安全学习路线--第十一章 网络安全技术下)【建议收藏】

文章目录 一、自学网络安全学习的误区和陷阱二、学习网络安全的一些前期准备三、自学网络安全学习路线一、入侵检测系统1、入侵检测系统模型2、入侵检测系统分类3、入侵检测系统部署 二、VPN1、VPN工作原理2、VPN的优点3、VPN的分类4、VPN的工作原理5、VPN的主要技术 一、自学网…

使用OpenXML库替换docx文档(Word文档)中的特定字段

在批量生成Word文档的应用中,最常见的需求莫过于替换掉文档中的特定字段以生成新的文档。利用OpenXML库可轻松实现这一需求。 不完善版本 首先放出最简单然而有bug的版本: using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wor…

第6讲:使用ajax技术实现模拟百度搜索功能(xml数据)

使用ajax技术实现模拟百度搜索功能,本案例使用原生态xmlhttprequest对象,GET方法通讯,后台使用map保存搜索数据,查询到对应数据后,返回xml格式数据,前端使用responseXML属性返回xml格式数据,结合…

6.安卓移动端开发

开发概览 Android官网 提供了开发环境,也就是android平台,即android SDK,即android版本 SDK版本和API版本的关系(安卓的版本是个位数和小数形式增长,API版本是以个位数正则,所以API版本号和android版本号不…

图像梯度——Sobel、Scharr、Laplacian

图像梯度-Sobel算子 dst cv2.Sobel(src, ddepth, dx, dy, ksize) src: 图像数组变量ddepth: 图像的深度,一般填-1,表示与原始图像深度一致; cv2.CV_64F表示每一个像素点值为64位浮点数,是OpenCV定义的数据类型dx和dy分别表示水平…

车端服务器架构「升级」

过去几年,随着整车电子架构从分布式向集中式升级,域控制器(通常分为五大域:动力域、底盘域、座舱域、智驾域、车身域)带动供应链进入增值周期,背后隐藏的则是供应商的洗牌。 以座舱为例,从传统的…

远程桌面发生身份验证错误,要求的函数不受支持

windows10专业版: 解决方法: 使用微软官方建议修改本地组策略: winr弹出运行窗口,输入gpedit.msc,打开本地组策略 计算机配置>管理模板>系统>凭据分配>加密Oracle修正 选择启用并选择易受攻击。 windows10家庭版&a…

Bug - 为什么不能打开Tmocat官网

今天在敲代码的时候碰到一个bug,登录不上Tmocat官网,后来查了查是不能使用代理模式进行连接网站: 解决方法,换成手机WIFE热点: 登录成功: 小开心^_^

445端口是啥?445端口怎么关闭?

445端口是Windows系统中的SMB协议,用于文件共享和网络打印功能。然而,这个端口也是黑客攻击的重要入口之一。那么,如何关闭445端口,保护自己的计算机安全呢? 关闭445端口的方法 1.在“控制面板”中打开“管理员工具”…

用华为云低代码Astro Zero10分钟搭建 “图书馆数据可视化大屏” 应用

作者:福州司马懿 原文链接:使用Astro Zero带你从零开始,10分钟搭建一套 “图书馆数据可视化大屏” 应用【华为云Astro低代码体验季】-云社区-华为云 产品介绍 点击下方链接进入工具页:https://auth.huaweicloud.com/authui/logi…

移远通信定位定向GNSS模组LC02H正式发布,提供可靠的航向、姿态、位置等信息

6月26日,全球领先的物联网整体解决方案供应商移远通信宣布,正式推出其自主研发的双天线定位定向GNSS模组LC02H,进一步丰富其GNSS产品线。 LC02H具有高性能、高稳定性、低功耗的特点,可为基站通信天线、工程机械姿态控制、舰船定位…

【方法】想把PDF文档转换成PPT,如何操作?

很多小伙伴在工作中,会使用PDF或者PPT来展示内容。那如果需要把PDF转换成PPT,要如何操作呢? 我们知道,PPT转换成PDF很容易操作,只需通过PPT的【导出】选项,就可以直接转换成PDF;还可以通过“另…

【UE Cesium】01-在虚幻5中使用Cesium

UE版本:5.1 步骤 1. 首先我们新建一个空白的工程 2. 在虚幻商城中搜索“Cesium for Unreal”,然后点击“安装到引擎” 3. 在虚幻编辑器中搜索插件“cesium”,勾选如下插件,然后重启编辑器 4. 重启后我们新建一个空白关卡 保存关卡…

DAY31——贪心

1.分发饼干 class Solution {public int findContentChildren(int[] g, int[] s) {Arrays.sort(g);Arrays.sort(s);int start 0;int count 0;for (int i 0; i < s.length && start < g.length; i) {if (s[i] > g[start]) {start;count;}}return count;} } …

软测实验室质量手册中结构要求部分如何满足

根据cnas官方指定的文件中要求&#xff0c;cnas软件检测机构应是一个能够承担法律责任的实体。 实验室所从事检测和校准工作应符合本准则的要求&#xff0c;并能满足客户、法定管理机构或对其提供承认的组织的需求。管理体系应覆盖实验室固定设施、离开固定设施的场所或相关的临…

谷歌浏览器(chrome)安装crx插件

1、下载crx插件 2、插件扩展名改名为zip 3、解压zip文件 4、打开谷歌浏览器扩展程序 chrome://extensions/ 5、打开开发者模式&#xff0c;加载已解压的扩展程序&#xff0c;安装成功即如图展示