Install Zabbix server-side and client with fabric automation with installation scripts

Source: Internet
Author: User
Tags snmp

The previous paragraph is a company project environment, from the previous single-node environment to the current cluster environment, and the server are in the same room, consider the deployment of a set of Zabbix monitoring system, because the first deployment of the server a bit more, so the installation process is written as a script mode, Server-side and client-side, respectively, are easy to install, using the Python fabric module written script, share, hope for the first batch deployment monitoring of friends to help.


Scripting considerations:

(1. Virtual host path, preferably using Nginx or Apache default path, the installation succeeds in manual modification;

(2.php parameters need to be adjusted manually, there will be a warning message after the installation is not adjusted;

1.sed-i ' s/post_max_size = 8m/post_max_size = 16m/'/usr/local/php/etc/php.ini

2.sed-i ' s/max_execution_time = 30/max_execution_time = 300/'/usr/local/php/etc/php.ini

3.sed-i ' s/max_input_time = 60/max_input_time = 300/'/usr/local/php/etc/php.ini

4.sed-i ' s/;d ate.timezone =/date.timezone = asia\/shanghai/'/usr/local/php/etc/php.ini

(3.mysql root password, manually changed to their own MySQL password, empty password does not need to specify-p parameter ;

(4. Need to specify the full path of the MySQL socket and the MySQL port, if the non-default port needs to specify the port;

(5. The script is a key installation , after installation does not need to be set up, you can directly login;

(6. Scripting Benefits:

1. Only need to run in Zabbix server, you can install the client in bulk;

2. Support can install both server and client;

3. You can choose whether to install only the server or client;

(5. Scripting Disadvantages:

1. Single thread installation, the efficiency is a bit slow;

2. If there are 20 servers, it can only be installed on one machine;

3. Using the Python multithreaded module, you can solve this problem, if there are 20 servers, can be installed at the same time, improve efficiency.


Code content [in centos-5.8| CentOS-6.5 test pass ]:

# -*- coding: utf-8 -*#! /usr/bin/env pythonfrom fabric.api import  *from fabric.colors import *from fabric.context_managers import *from  fabric.contrib.console import confirm#client ipenv.port= ' 9577 ' env.user= ' root ' env.hosts=[' 192.168.64.129 ', ' 192.168.64.130 ', ' 192.168.64.131 ']env.password= ' root#@!~ ' #zabbix  informationenv.software_ down_path  =  '/root/src ' env.software_make_path  =  '/usr/local/zabbix ' env.software_zabbix_url =  ' http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/ 2.4.5/zabbix-2.4.5.tar.gz ' #mysql  informationenv.version_mysql_port =  ' 3306 ' Env.version_mysql_ user =  ' Zabbix ' env.version_mysql_pass =  ' zabbix2015 ' env.version_mysql_sock =  '/ Tmp/mysql_3306.sock ' #vhost  informationenv.project_html_path =  '/usr/local/nginx/html ' @task @runs _oncedef server ():    print yellow ("start install zabbix server service ... ")      local ("Yum -y install gcc gcc-c++ openssl-devel net-snmp-devel  curl-devel ntpdate wget ")     local (" useradd -m -s /sbin/ Nologin zabbix ; ntpdate pool.ntp.org ")     local (" wget -P %s  %s " %  (Env.software_down_path,env.software_zabbix_url)) &NBSP;&NBSP;&NBSP;&NBSP;WITH&NBSP;LCD ( Env.software_down_path):         local ("tar fx %s"  %  env.software_zabbix_url.split ('/') [-1]) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;WITH&NBSP;LCD ( Env.software_zabbix_url.split ('/') [ -1][0:-7]):             local ("./configure --prefix=%s --enable-server --enable-agent --with-mysql              --with-net-snmp --with-libcurl "% env.software_make_ Path)             local ("make &&  Make install ")              #使用nginx的默认路径, You can modify the             local yourself ("Cp -r frontends /php/ %s/zabbix "% env.project_html_path)              local ("cp misc/init.d/fedora/core/* /etc/init.d/")              local ("chmod +x /etc/init.d/zabbix_* &&  Chkconfig --add zabbix_server ")              local ("chkconfig --add zabbix_agentd && chkconfig zabbix_agentd   on ")    &Nbsp;        local ("Chkconfig zabbix_server on")               #创建zabbix用户              local ("Mysql -uroot -pmysql2015 -p %s -e \" Grant all privileges on zabbix.* to %[email protected] identified  by              '%s ' \ ' ""  % ( Env.version_mysql_port,env.version_mysql_user,env.version_mysql_pass))              local ("mysql -uroot -pmysql2015 -p %s -e " Create database zabbix ' "% env.version_mysql_port)               #导入zabbix数据库              local ("Mysql -uroot -pmySql2015 -p %s zabbix < database/mysql/schema.sql "% env.version_mysql_port)             local ("mysql -uroot - Pmysql2015 -p %s zabbix < database/mysql/images.sql "% env.version_mysql_port)             local ("mysql -uroot - Pmysql2015 -p %s zabbix < database/mysql/data.sql "% env.version_mysql_port)     local ("sed -i  ' s/\/usr\/local/%s/'  /etc/init.d/zabbix_server"%  Env.software_make_path.replace ('/', ' \ \ ')     local ("sed -i  ' s/\/usr\/local/%s/')  /etc/init.d/zabbix_agentd "% env.software_make_path.replace ('/', ' \ \ '))     with &NBSP;LCD (Env.software_make_path):         #创建日志文件并赋予权限          locAl ("Touch /var/log/zabbix_server.log")         local ("touch / Var/log/zabbix_agentd.log ")         local (" Chown -R zabbix: Zabbix /var/log/zabbix_* ")         local (" sed -i  ' s/\/ tmp\/zabbix_server.log/\/var\/log\/zabbix_server.log/'  etc/zabbix_server.conf ')          local ("sed -i  ' s/dbuser=root/dbuser=%s/'  etc/zabbix_server.conf"%  Env.version_mysql_user)         local ("sed -i  ' s/#  dbpassword=/dbpassword=%s/'  etc/zabbix_server.conf "% env.version_mysql_pass)          local ("sed -i  ' s/# dbsocket=\/tmp\/mysql.sock/dbsocket=%s/'           etc/zabbix_server.conf " % env.version_mysql_sock.replace (' /', ' \ \ ')         local ("sed -i  ' s/\/tmp\/zabbix_agentd.log/\/var\/log\/zabbix_ agentd.log/'  etc/zabbix_agentd.conf ")     with lcd (env.project_html_path+ '/zabbix /conf '):         local ("cp zabbix.conf.php.example   Zabbix.conf.php ")         local (" sed -i  ' s/zabbix_password/%s /'  zabbix.conf.php '% env.version_mysql_pass)         local (" Sed -i \ "s/' 0 '/'%s '/\"  zabbix.conf.php "% env.version_mysql_port)          local ("Service zabbix_server start && service zabbix_ Agentd start ")     print green (" zabbix server installation  successful ...  ")      @taskdef  client ():    print  Yellow ("Start install zabbix client service ...  ")     run (" Yum -y install  gcc gcc-c++ openssl-devel net-snmp-devel curl-devel ntpdate wget ")      run ("useradd -m -s /sbin/nologin zabbix ; ntpdate  Pool.ntp.org ")     run (" wget -p %s %s " %  (Env.software_down_path, Env.software_zabbix_url)) &NBSP;&NBSP;&NBSP;&NBSP;WITH&NBSP;CD (Env.software_down_path):         run ("tar fx %s"  % env.software_zabbix_url.split ('/') [-1])   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;WITH&NBSP;CD (Env.software_zabbix_url.split ('/') [ -1][0:-7]):             run ("./configure --prefix=%s -- Enable-agent " % env.software_make_path)              run ("Make &&amP; make install ")             run (" CP  misc/init.d/fedora/core/* /etc/init.d/")              run ("Chmod +x /etc/init.d/zabbix_agentd")              run ("chkconfig --add zabbix_agentd &&  Chkconfig zabbix_agentd  on ")      #获取server端ip   [ Fabric toughness points out that local commands and remote commands can be executed at any time]    server_ip = local ("ifconfig eth0|grep  bcast|awk  ' {print $2} ' |sed  ' s/addr://')     run ("sed -i " s/\/usr\ /local/%s/'  /etc/init.d/zabbix_agentd '% env.software_make_path.replace ('/', ' \ \ '))     &NBSP;WITH&NBSP;CD (Env.software_make_path):         #创建日志文件并赋予权限          run ("ToucH /var/log/zabbix_agentd.log ")         run (" chown -R  Zabbix:zabbix /var/log/zabbix_agentd.log ")           #日志存放在/ Var/log directory         run ("sed -i  ' s/\/tmp\/zabbix_agentd.log/\/ var\/log\/zabbix_agentd.log/'  etc/zabbix_agentd.conf ")         run ("sed -i  ' s/server=127.0.0.1/server=%s/'  etc/zabbix_agentd.conf"% server_ip)          run ("sed -i  ' s/serveractive=127.0.0.1/serveractive=%s/'  etc /zabbix_agentd.conf "% server_ip)         run (" Service zabbix_ Agentd start ")     print green (" zabbix client installation  successful ...  ") @task         def start ():     server ()     client () 

Install the Python fabric module

Wget-p/soft Https://bootstrap.pypa.io/ez_setup.py-O-| Pythoneasy_install Fabric

Run the command [need to install Python's fabric module]:

#只安装server端 [If the script name is called zabbix_install.py]fab-f zabbix_install.py server# only install client side [if the script name is zabbix_install.py]fab-f Zab bix_install.py Client#server End and client side installation [if script name is zabbix_install.py]fab-f zabbix_install.py start

Test effect, to be added ...

This article is from the "ˉt, Stand Wentao ┃﹎" blog, please be sure to keep this source http://hypocritical.blog.51cto.com/3388028/1679989

Install Zabbix server-side and client with fabric automation with installation scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.