ansible自动化部署50-100台规模企业级架构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible自动化部署50-100台规模企业级架构相关的知识,希望对你有一定的参考价值。

1、项目规划:搭建50-100台规模的集群实战设计方案

2、利用多台服务器进行cobbler无人值守装机

3、管理机(yum,rpm,ntp,pptp,jumpserver,ssh key,ansible,saltstack)

4、搭建backup(rsync 这个集群定时备份)

5、共享存储nfs01(nfs服务、实时同步(sersync+rsync)

6、独立的mysql数据库服务

7、LNMP web服务(nginx+php,用户文件挂到存储,文本数据放到DB,优化)

8、NGINX 反向代理负载均衡(nginx)

9、利用keepalive实现负载均衡集群高可用

10、搭建yum仓库,定制rpm软件包,提供整个集群中所需软件

11、利用zabbix进行全网监控


这里是在虚拟机上进行试验,受限制没办法开那么多机器,但是思路和具体的方法就是这样

至于多少台服务器,那只是一个数字!

- hosts: daya

  tasks:

  - name: yum client

    script: /server/scripts/yum_client.sh    这个脚本就具体内容如下:

  - name: hosts copy

    copy: src=/etc/hosts dest=/etc/hosts force=yes

[[email protected] ansible-playbook]# cat /server/scripts/yum_client.sh   修改所有机器yum源指向管理机

#!/bin/bash

#by daya at 2018


mkdir /yum_bak

cd /etc/yum.repos.d/

mv *.repo /yum_bak

cat >/etc/yum.repos.d/local.repo<<EOF

[local]

name=Server

baseurl=http://10.0.0.61

enabled=1

gpgcheck=0

EOF

yum clean all

##################web集群###############

- hosts: 172.16.1.17

  tasks:

  - name: nginx

    yum: name=nginx,php state=installed

  - name: conf

    copy: src=/server/scripts/nginx.conf dest=/application/nginx/conf/ force=yes

  - name: key

    copy: src=/tmp/key dest=/application/nginx/conf/ mode=push force=yes

###################mysql数据库#################

- hosts: 172.16.1.51

  tasks:

  - name: install

    yum: name=mariadb-server state=installed

  - name: start

    service: name=mariadb state=restarted

##################nfs共享存储#################

- hosts: 172.16.1.31

  tasks:

  - name: install software

    yum: name=nfs-utils,rpcbind state=installed

  - name: put profile

    copy: src=/tmp/exports dest=/etc/exports

  - name: mkdir /data/

    file: dest=/data/ state=directory owner=nfsnobody group=nfsnobody

  - name: mkdir /data/

    file: dest=/data/www state=directory owner=nfsnobody group=nfsnobody

  - name: mkdir /data/

    file: dest=/data/bbs state=directory owner=nfsnobody group=nfsnobody

  - name: mkdir /data/

    file: dest=/data/blog state=directory owner=nfsnobody group=nfsnobody

  - name: start server

    service: name=rpcbind state=restarted

  - name: service nfs

    service: name=nfs state=restarted

  - name: www

    copy: src=/server/tools/html/ dest=/data/

###################web集群######################

- hosts: 172.16.1.17

  tasks:

  - name: yum

    yum: name=rpcbind,nfs-utils state=installed

  - name: mount

    mount: src=172.16.1.31:/data/www path=/application/nginx/html/www fstype=nfs state=mounted

  - name: mount

    mount: src=172.16.1.31:/data/bbs path=/application/nginx/html/bbs fstype=nfs state=mounted

  - name: mount

    mount: src=172.16.1.31:/data/blog path=/application/nginx/html/blog fstype=nfs state=mounted

  - name: start nginx

    shell: /application/nginx/sbin/nginx

  - name: start php

    shell: /application/php/sbin/php-fpm

#################unzip www.bbs.blog站点目录###########

- hosts: 172.16.1.31

  tasks:

  - name: unzip

    unarchive: src=/data/www.tar.gz dest=/data/www/ copy=no

  - name: unzip

    unarchive: src=/data/bbs.tar.gz dest=/data/bbs/ copy=no

  - name: unzip

    unarchive: src=/data/blog.tar.gz dest=/data/blog/ copy=no

#################lb负载均衡集群#######################

- hosts: 172.16.1.5

  tasks:

  - name: yum

    yum: name=nginx,keepalived state=installed

  - name: conf

    copy: src=/tmp/nginx.conf dest=/application/nginx/conf/

  - name: key

    copy: src=/tmp/key dest=/application/nginx/conf/

  - name: start nginx

    shell: /application/nginx/sbin/nginx

#################keepalived.con高可用配置文件#####f########

- hosts: 172.16.1.5

  tasks:

  - name: conf

    copy: src=/tmp/keepalived.conf dest=/etc/keepalived/ force=yes

- hosts: 172.16.1.6

  tasks:

  - name: conf

    copy: src=/server/scripts/keepalived.conf dest=/etc/keepalived/ force=yes

- hosts: 172.16.1.5

  tasks:

  - name: jiankong.sh

    copy: src=/server/scripts/jiankong.sh dest=/server/scripts/ force=yes mode=0755

  - name: start

    service: name=keepalived state=started

##################backup备份服务器##################

- hosts: 172.16.1.41

  tasks:

  - name: install rsync

    yum: name=rsync state=installed

  - name: useradd rsync

    user: name=rsync shell=/sbin/nologin

  - name: mkdir /backup

    file: dest=/backup/ state=directory owner=rsync group=rsync

  - name: touch passswd 

    copy: content=rsync_backup:123456 dest=/etc/rsync.passwd mode=0600

  - name: copy profile

    copy: src=/server/scripts/rsyncd.conf dest=/etc/rsyncd.conf 

  - name: start rsync

    command: rsync --daemon

##################install sersyncd实时同步软件###########

- hosts: 172.16.1.31

  tasks:

  - name: install rsync

    yum: name=rsync,sersyncd state=installed

  - name: copy profile

    copy: src=/server/scripts/rsyncd.conf dest=/etc/rsyncd.conf 

  - name: touch passswd

    copy: content=123456 dest=/etc/rsync.passwd mode=0600

  - name: start rsync

    command: rsync --daemon


以上是关于ansible自动化部署50-100台规模企业级架构的主要内容,如果未能解决你的问题,请参考以下文章

Ansible 的安装及部署

自动化运维之Ansible服务部署

ansible的使用和安装

saltstack小试牛刀

自动化运维利器 Ansible 和企业级 Ansible 应用解读

ansible-playbook实现MySQL的二进制部署