首页 > 其他分享 >Ansible+LAMP+Zabbix

Ansible+LAMP+Zabbix

时间:2022-11-19 11:07:02浏览次数:39  
标签:Zabbix httpd name LAMP server1 zabbix Ansible server root


Ansible+LAMP+Zabbix

Server1:172.25.254.1

Server2:172.25.254.2

安装ansible

ansible-2.7.8-1.el7.noarch.rpm

libtomcrypt-1.17-25.el7.x86_64.rpm

libtommath-0.42.0-5.el7.x86_64.rpm

python2-crypto-2.6.1-13.el7.x86_64.rpm

python2-jmespath-0.9.0-1.el7.noarch.rpm

python-httplib2-0.9.2-0.1.el7.noarch.rpm

python-keyczar-0.71c-2.el7.noarch.rpm

python-paramiko-2.1.1-0.9.el7.noarch.rpm

sshpass-1.06-1.el7.x86_64.rpm

 

server1和server2配置免密:

[root@server1 ansible]# ssh-keygen

[root@server1 ansible]# ssh-copy-id server1

[root@server1 ansible]# ssh-copy-id server2

vim /etc/ansible/hosts

[web]

server1

server2

 

[db]

server2

配置ansible普通用户

ansible all -m user -a "name=syf password=westos"

Ansible+LAMP+Zabbix_php

Role-httpd:

[root@server1 roles]# mkdir httpd

[root@server1 roles]# cd httpd/

[root@server1 httpd]#

mkdir {files,templates,tasks,handlers,vars,meta,defaults}

[root@server1 httpd]# ls

defaults  files  handlers  meta  tasks  templates  vars

vim tasks/main.yml

- name: install httpd

  yum: name=httpd state=present

- name: config httpd

  copy: src=httpd.conf dest=/etc/httpd/conf/httpd.conf

  notify: restart httpd

- name: start httpd

  service: name=httpd state=started

 

vim handlers/main.yml

- name: restart httpd

  service: name=httpd state=restarted

 

将httpd配置文件模版复制到files/下

修改监听端口: Listen 172.25.254.2:80

 

Role-mariadb:

[root@server1 roles]# mkdir mariadb

[root@server1 roles]# cd mariadb/

[root@server1 mariadb]#

mkdir {files,templates,tasks,handlers,vars,meta,defaults}

[root@server1 mariadb]# ls

defaults  files  handlers  meta  tasks  templates  vars

 

vim tasks/main.yml

- name: install mariadb server

  yum: name={{ item }} state=present

  with_items:

    - mariadb-server

    - mariadb-devel

    - MySQL-python

- name: config mariadb

  copy: src=my.cnf dest=/etc/my.cnf

  notify: restart mariadb

- name: start mariadb server

  service: name=mariadb state=started

 

vim handlers/main.yml

- name: restart mariadb

  service: name=mariadb state=restarted

 

cp /etc/my.cnf /etc/ansible/roles/mariadb/files

添加:character-set-server=utf8

 

Role-php:

[root@server1 roles]# mkdir php

[root@server1 roles]# cd php/

[root@server1 php]# mkdir {files,templates,tasks,handlers,vars,meta,defaults}

[root@server1 php]# ls

defaults  files  handlers  meta  tasks  templates  vars

 

vim tasks/main.yml

- name: install php

  yum: name={{ item }} state=present

  with_items:

    - php

  notify: restart httpd

 

vim handlers/main.yml

- name: restart httpd

  service: name=httpd state=restarted

 

Role-zabbix

[root@server1 roles]# mkdir zabbix

[root@server1 roles]# cd zabbix/

[root@server1 zabbix]#

mkdir {files,templates,tasks,handlers,vars,meta,defaults}

[root@server1 zabbix]# ls

defaults  files  handlers  meta  tasks  templates  vars

vim tasks/main.yml

- name: copy zabbix.repo

  copy: src=zabbix.repo dest=/etc/yum.repos.d/zabbix.repo

- name: install zabbix-server

  yum: name=zabbix-server,zabbix-agent state=present

  notify: "init zabbix db"

- name: config zabbix server

  copy: src=zabbix_server.conf dest=/etc/zabbix/zabbix_server.conf

  notify: restart zabbix server

- name: start zabbix server

  service: name={{ item }} state=started

  with_items:

    - zabbix-server

    - zabbix-agent

 

vim handlers/main.yml

- name: create database

  mysql_db: name=zabbix state=present

  listen: "init zabbix db"

 

- name: create zabbix user

  mysql_user: name=zabbix password=zabbix priv=zabbix.*:ALL state=present

  listen: "init zabbix db"

 

- name: import create.sql.gz

  mysql_db: name=zabbix

state=import target=/usr/share/doc/zabbix-server-mysql-4.0.5/create.sql.gz

  listen: "init zabbix db"

 

- name: restart zabbix server

  service: name=zabbix-server state=restarted

 

vim files/zabbix.repo

[zabbix]

name=zabbix4.0

baseurl=file:///root/4.0

gpgcheck=0

将zabbix_server.conf文件复制到files/

vim files/zabbix_server.conf

DBPassord=zabbix

 

vim /etc/ansible/lamp.yml

---

- hosts: server2

  roles:

    - mariadb

    - zabbix

    - httpd

- php

[root@server1 ansible]# ansible-playbook lamp.yml

Ansible+LAMP+Zabbix_vim_02

[root@server1 ~]# vim index.html

[root@server1 ~]# ansible server2 -u syf -b -m copy -a "src=index.html dest=/var/www/html/index.html"

server2 | CHANGED => {

    "changed": true,

    "checksum": "b097c51bbb5bac74fdaeca37e340e8132f0e4c69",

    "dest": "/var/www/html/index.html",

    "gid": 0,

    "group": "root",

    "md5sum": "f49bb5c10abb2f48802ed1d00a8feebc",

    "mode": "0644",

    "owner": "root",

    "size": 15,

    "src": "/home/syf/.ansible/tmp/ansible-tmp-1553494549.84-176136904469032/source",

    "state": "file",

    "uid": 0

}

 

Ansible+LAMP+Zabbix_vim_03

 

 

[root@server1 ~]# vim index.php

[root@server1 ~]# ansible server2 -u syf -b -m copy -a "src=index.php dest=/var/www/html/index.php"

server2 | CHANGED => {

    "changed": true,

    "checksum": "26af88945e23289d15e128606a29932b3d78787c",

    "dest": "/var/www/html/index.php",

    "gid": 0,

    "group": "root",

    "md5sum": "62210a938d0199092c2d3976a45bf86d",

    "mode": "0644",

    "owner": "root",

    "size": 22,

    "src": "/home/syf/.ansible/tmp/ansible-tmp-1553494588.69-144347487690584/source",

    "state": "file",

    "uid": 0

}

Ansible+LAMP+Zabbix_php_04

 

Ansible+LAMP+Zabbix_php_05

标签:Zabbix,httpd,name,LAMP,server1,zabbix,Ansible,server,root
From: https://blog.51cto.com/u_15883840/5870328

相关文章

  • 针对zabbix二次开发的监控脚本执行timeout时,zabbix-server性能消耗增大问题,开发处理ti
    脚本内容:#!/bin/sh####################################################Scripttohandleexecutiontimeoutstates#scriptbyshell#writedbyDeliver#huchangx......
  • ZABBIX开发自定义进程关键字监控
    脚本内容:#!/bin/sh####################################################Usedtomonitorthenumberofprocesskeywords#scriptbyshell#writedbyDeliver#20......
  • Ansible ad-hoc模式及常用模块
    Ansibleadhoc模式基本语法:ansible{主机名/主机地址/主机组}[-m模块名][-a模块参数]-m模块名指定使用的模块名称-a模块参数列表指定模块执行操作时的参数,参......
  • zabbix监控kafka消费
    目录一、Kafka监控的几个指标二、查看zookeeper配置三、查看kafka配置四、查看kafka的groupname五、查看kafka的topic_name六、修改zabbix配置文件......
  • Ansible安装和基本使用
    一、安装ansible1、dnf安装ansible首先得安装EPEL源,然后才能安装ansible。EPEL是一个软件仓库项目,为RHEL和Centos提供软件包信息dnf-yinstallepel-releasednf-yin......
  • LAMP源码编译安装
       一、什么是LAMP?1、LAMP平台概述2、构建LAMP平台顺序3、编译安装的优点4、各组件的主要作用二、LAMP架构流向三、编译安装Apache服务1、先关闭防火墙2、将......
  • 厉害了!不懂自动化运维ansible你就out啦!批量部署web服务及mysql
    理论讲解step1为什么用它?提高效率。ansible可为多台服务器进行管理,自动部署服务,专为Unix系统开发的自由开源的配置和自动化工具。step2温馨提示:优点太多,就不一一介绍完啦......
  • Ansible介绍
    ansible是一种由Python开发的自动化运维工具,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansi......
  • Ansible-Playbook
    playbooks是一个不同于使用Ansible命令行执行方式的模式,其功能更强大灵活。简单来说,playbook是一个非常简单的配置管理和多主机部署系统,不同于任何已经存在的模式,可作为一......
  • CentOS 7 安装 Ansible
    ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。......