ansible - 安装 -【kodcloud教程】

本文档详细介绍了使用Ansible自动化部署Kodcloud的全过程,包括安装基础环境、设置webserver、部署nginx、安装php环境、配置lb-server、安装redis以及设置wordpress-proxy的步骤。每个阶段都包含了具体的tasks、handlers、templates和变量文件等内容,为Kodcloud的一键安装提供指导。
摘要由CSDN通过智能技术生成

目录

目录结构、主机清单

【1】安装基础环境

【2】webserver - 安装nginx

【3】安装php环境

【4】lb-server

【5】redis安装

【6】 kodcloud

【7】wordpress-proxy 


 

ansible 10.0.0.10
lb-server 10.0.0.11
web01 10.0.0.15
web02 10.0.0.16
redis 10.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"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦有一把琐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值