天天看点

Zabbix server 环境部署(LNMP+ZABBIX)第1章 引言第2章 Zabbixbasic install第3章 Zabbix server basic install 第4章 Zabbix 管理 第5章 自动化部署脚本

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495397" target="_blank">... 16</a>

目录

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495379" target="_blank">第1章引言... 1</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495380" target="_blank">1.1 目的... 1</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495381" target="_blank">1.2 Zenoss 概述... 1</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495382" target="_blank">1.3 Zabbix由2部分构成(zabbixserver与Agent)1</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495383" target="_blank">1.4 Zabbix 功能与特点... 2</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495384" target="_blank">1.4.1 功能... 2</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495385" target="_blank">1.4.2 特点... 2</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495386" target="_blank">第2章 Zabbix basic install3</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495387" target="_blank">2.1 LNMP 环境部署(Linux+Nginx+MySQL+PHP)... 3</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495388" target="_blank">2.2 LNMP 服务的基本配置... 6</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495389" target="_blank">2.3 LNMP服务启动... 10</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495390" target="_blank">第3章 Zabbix server basic install11</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495391" target="_blank">3.1 Zabbix server 基本安装... 11</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495392" target="_blank">3.2 Zabbix 基本配置... 11</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495393" target="_blank">3.3 Zabbix server 启动... 13</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495394" target="_blank">第4章 Zabbix 管理... 15</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495395" target="_blank">4.1 主机群组... 15</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495396" target="_blank">第5章自动化部署脚本... 16</a>

<a href="http://swq499809608.blog.51cto.com/user_index.php?action=addblog_new#_Toc380495397" target="_blank">5.1 ZabbixAgent 部署脚本... 16</a>

实时监控系统服务,系统资源瓶颈,系统日志,达到预警措施!

lzabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案

lzabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题

a)Zabbix Server 

a) zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台上,服务监听端口是10051

b)Zabbix Agent 

a)zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。

b)zabbix agent可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD, OS X, Tru64/OSF1, WindowsNT4.0, Windows (2000/2003/XP/Vista)等系统之上,服务监听端口10050

c)other 

a)zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。

b)另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。

a)CPU负荷

b)内存使用

c)磁盘使用

d)网络状况

e)端口监视

f)日志监视

g)扩展监控(支持SHELL,PYTHON,PHP语音脚本)

a)安装与配置简单,学习成本低

b)支持多语言(包括中文)

c)免费开源自动发现服务器与网络设备

d)分布式监视以及WEB集中管理功能

e)可以无agent监视

f)用户安全认证和柔软的授权方式

g)通过WEB界面设置或查看监视结果

h)email等通知功能

1)tar xzvffreetype-2.3,9.tar.gz

# wgethttp://down1.chinaunix.net/distfiles/freetype-2.4.7.tar.bz2 

#t ar xzvffreetype-2.4.7.tar.bz2

# cd freetype-2.4.7

# ./configurage–prefix=/usr/local/freetype 

# make;makeinstall

2)#tar xjvflibxml2-2.9.1.tar.gz

# cd libxml2-2.9.1

# ./configure –prefix=/usr/local/libxml2 

# make;make install

#./configure–prefix=/usr/local/libpng

#make;make install

#./configure–prefix=/usr/local/iconv

# Mkdir /usr/local/jpeg

# Mkdir/usr/local/jpeg/include

# Mkdir/usr/local/jpeg/sibn

# Mkdir /usr/local/jpeg/lib

# Mkdir/usr/local/jpeg/man/man1 –p

#./configure–prefix=/usr/local/jpeg 

#make ;make install

6)#tar xzvflibmcrypt-2.5.8.tar.gz

#./configure 

#make;make install 

# ln -s/usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

# ln -s/usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

# ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

# ln -s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8

7)#tar xzvfmhash.0.9.9.9.tar.gz

# make;make install 

# ln -s /usr/local/lib/libmhash.a/usr/lib/libmhash.a

# ln -s/usr/local/lib/libmhash.so /usr/lib/libmhash.so

# ln -s/usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

# ln -s/usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

8)#tar xzvfmcrypt-2.6.8.tar.gz

#./configure ;

10)# tar –xzvf libgd-2.11.tar.gz

#./configure--prefix=/usr/local/gd --with-png=/usr/local/libpng/ --with-zlib--with-jpeg=/usr/local/jpeg/ --with-freetype=/usr/local/freetype/ --with-xpm

11)tar –xzvf pcre-8.32.tar.gz

# ./configure–prefix=/usr/local/pcre

12)tar –xzvf nginx-1.5.10.tar.gz

# groupadd www

# useradd –g www www

# ulimit -SHn 65535 

#./configure --user=www --group=www --prefix=/Data/apps/nginx--with-http_stub_status_module --with-http_ssl_module--with-pcre=/Data/tgz/pcre-8.32 --with-http_realip_module--with-http_image_filter_module

#make;makeinstall

13)#tar xjvfmysql-5.0.56.tar.bz

# groupadd mysql

# useradd –gmysql mysql 

# ./configure –prefix=/usr/local/mysql –enable-assembler–with-mysqld-ldflage=-all-static 

–with-client-ldflage=-all-static–with-unix-sock-path=/usr/local/mysql/tmp/mysql.sock 

–with-charset=gbk –with-extra-charsers=all --enable-client-safe-thread

# cp -fr support-files/my-medium.cnf/etc/my.cnf

# /usr/local/bin/mysqld_install–user=mysql

# chown –R root .

# chown –R mysql var

# chgrp –R mysql .

# usr/local/mysql/bin/mysqld_safe &amp; 

14)tar –xzvf php-5.5.9.tar.gz 

#./configure--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc 

--with-mysql=/usr/local/mysql/--with-mysqli=/usr/local/mysql/bin/mysql_config 

--with-iconv-dir=/usr/local/iconv/--with-freetype-dir=/usr/local/freetype/ 

--with-jpeg-dir=/usr/local/jpeg/--with-png-dir=/usr/local/libpng/ 

--with-zlib--with-libxml-dir=/usr/local/libxml2/--enable-xml --disable-rpath 

--enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization 

--with-curl--enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt 

--with-gd=/usr/local/gd--enable-gd-native-ttf--enable-gd-native-ttf --with-openssl 

--with-mhash--enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap

--with-pdo-mysql--enable-maintainer-zts --enable-opcache=no

注意:在编译时出现这样的错误:/usr/bin/ld: cannot find -lltdl

出现此错误大多是由于你的系统未安装libtool库导致,但即使你已安装了libtool库也可能会遇到。对此我们要做两件事情:

1,确认系统是否安装了libtool库;

2,为PHP编译作兼容性设置。

第一步很容做到:yum -y install libtool libtool-ltdl;

第二步由于PHP的configure指定的libltdl名为libltdl.so,为此我们只需添加一个名称连接:ln -s /usr/lib64/libltdl.so.3.1.4/usr/lib64/libltdl.so

1)MySQL my.conf 配置

#[[email protected] /]# cat /etc/my.cnf|grep -v '#'|grep -v '^$' 

[mysqld]

server-id= 2212433306 

port= 3306

log_error= /var/lib/mysql/error.log

log_warnings= 2

user= mysql

datadir=/var/lib/mysql

tmpdir=/var/lib/mysql

slave-load-tmpdir= /tmp 

socket=/var/lib/mysql/mysql.sock

pid-file=/var/lib/mysql/mysql.pid

bind-address= 0.0.0.0

character-set-server= utf8

innodb_data_home_dir= /var/lib/mysql

innodb_data_file_path= ibdata1:10M:autoextend

innodb_log_group_home_dir= /var/lib/mysql

innodb_log_files_in_group= 3

innodb_buffer_pool_size= 2G

transaction-isolation= READ-COMMITTED

innodb_log_file_size= 256M

innodb_log_buffer_size= 128M

innodb_additional_mem_pool_size= 48M

innodb_flush_log_at_trx_commit= 2

innodb_file_per_table= 1

innodb_lock_wait_timeout= 20

innodb_buffer_pool_instances= 4

innodb_flush_method= O_DIRECT

innodb_adaptive_hash_index_partitions= 4

innodb_lazy_drop_table= 1

innodb_read_io_threads= 8

innodb_write_io_threads= 8

innodb_io_capacity= 600

innodb_max_dirty_pages_pct= 70

innodb_sync_spin_loops= 10

innodb_fast_checksum= 1

innodb_file_format= Barracuda

innodb_file_format_max= Barracuda

expand_fast_index_creation= 1

back_log= 400

max_connections= 2048

max_connect_errors= 999999999

thread_cache_size= 64

table_open_cache= 2048

interactive_timeout= 3600

wait_timeout= 3600

sort_buffer_size= 16M

read_buffer_size= 16M

join_buffer_size= 8M

read_rnd_buffer_size= 24M

myisam_sort_buffer_size= 64M

key_buffer= 1024M

query_cache_size= 128M

query_cache_limit= 2M

query_cache_type= 1

max_tmp_tables= 64

tmp_table_size= 192M

max_heap_table_size= 192M

read_only= 1

expire_logs_days= 2

max_allowed_packet= 16M

skip-external-locking

skip-name-resolve

slow_query_log= 1

long_query_time= 1

slow_query_log_file= slow-queries.log 

log-bin=mysql-bin.log

relay-log= relay-bin.log

binlog_format= MIXED

log-slave-updates

skip-slave-start

replicate-same-server-id= 0 

delay_key_write= ALL

myisam_repair_threads= 1 

myisam-recover= BACKUP

2)Nginx nginx.conf 配置

[[email protected] conf]# cat nginx.conf|grep -v '#'|grep -v '^$'

userwww www;

worker_processes4;

events {

worker_connections1024;

}

http {

includemime.types;

default_typeapplication/octet-stream;

sendfileon;

keepalive_timeout65;

server {

listen80;

server_namelocalhost;

location / {

root/data1/www/;

indexindex.php index.html index.htm;

error_page500 502 503 504/50x.html;

location = /50x.html {

roothtml;

location ~ \.php$ {

root/data1/www;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;

includefastcgi.conf;

autoindex on;

3)Php php.ini配置

# sed -i 's/^\(.*\)date.timezone=.*$/date.timezone = Asia\/Shanghai/g' /usr/local/php/lib/php.ini

# sed -i's/^\(.*\)post_max_size =.*$/post_max_size = 16M/g' /usr/local/php/lib/php.ini

# sed -i's/^\(.*\)max_execution_time =.*$/max_execution_time = 300/g'/usr/local/php/lib/php.ini

# sed -i's/^\(.*\)max_input_time =.*$/max_input_time = 300/g' /usr/local/php/lib/php.ini

4)Php-fpm php-fpm.conf 配置

[[email protected] etc]#cat php-fpm.conf|grep -v ';'|grep -v '^$'

[global]

[www]

user = nobody

group = nobody

listen = 127.0.0.1:9000

pm = dynamic

pm.max_children = 5

pm.start_servers = 2

pm.min_spare_servers = 1

pm.max_spare_servers= 3

5)Net-snmp snmpd.conf 配置

[[email protected] etc]# cat/etc/snmp/snmpd.conf|grep -v '#'|grep -v '^$'

com2sec notConfigUserdefaultpublic

view mib2included.iso.org.dod.internet.mgmt.mib-2 fc

groupnotConfigGroup v2cnotConfigUser

viewinterface included.1.3.6.1.2.1.2

viewsystemviewincluded.1.3.6.1.2.1.1

viewsystemviewincluded.1.3.6.1.2.1.25.1.1

accessnotConfigGroup ""anynoauthexact mib2none none

groupnotConfigGroupv1notConfigUser

groupnotConfigGroupv2cnotConfigUser

viewroviewincluded.1

syslocation Unknown (edit/etc/snmp/snmpd.conf)

syscontact Root&lt;root@localhost&gt; (configure /etc/snmp/snmp.local.conf)

pass .1.3.6.1.4.1.4413.4.1/usr/bin/ucd5820stat

1)Cp –fr /usr/local/nginx/sbin/nginx/etc/init.d/

2)Cp –fr/usr/local/php/sbin/php-fpm /etc/init.d

3)/etc/init.d/php-fpm &amp;

4)/etc/init.d/nginx &amp; 

5)/usr/local/mysql/sbin/mysqld_safe–user=mysql &amp;

1)Net-snmp 安装(RPM)

#rpm -vihnet-snmp-devel-5.3.2.2-9.el5.x86_64.rpmbeecrypt-devel-4.1.2-10.1.1.x86_64.rpmelfutils-devel-0.137-3.el5.x86_64.rpmlm_sensors-devel-2.10.7-9.el5.x86_64.rpmbeecrypt-devel-4.1.2-10.1.1.x86_64.rpmelfutils-devel-static-0.137-3.el5.x86_64.rpmbeecrypt-4.1.2-10.1.1.x86_64.rpm

2)Tar –xzvf zabbix-2.2.2.tar.gz 

# cd zabbix-2.2.2

#./configure --prefix=/usr/local/zabbix --enable-server--enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config--enable-proxy--enable-ipv6--with-net-snmp --with-libcurl=/usr/local/curl/bin/curl-config

# make ;make install 

1)数据库创建,导入数据库信息(MySQL)

# mysql –uroot –p****

# create database zabbix character set utf8; 

# grant all on zabbix.* to ‘zabbix’@’localhost’ identifiedby ‘zabbix’ with grant option;

# grant all on zabbix.* to ‘zabbix’@’%’ identified by‘zabbix’ with grant option;

# flush privileges

2)导入数据库表结构

#cd /data1/lnmp/zabbix-2.2.2/database/mysql/

#mysql –uzabbix –pzabbix zabbix &lt; schema.sql

#mysql –uzabbix –pzabbix zabbix &lt; images.sql

#mysql –uzabbix –pzabbix zabbix &lt; data.sql

3)Copy zabbix 源代码

# cp -fr /data1/lnmp/zabbix-2.2.2/frontends/php//data1/www/zabbix/

# chmod 755 –R/data1/www/zabbix

#chown –R ww:www /data1/www/zabbix

4)打开动态链接库

# echo "/usr/local/mysql/lib/mysql/" &gt;&gt;/etc/ld.so.conf

# ldconfig #打开动态链接库,立即生效

5)Copy zabbix server agent 启动脚本并修改

# cp –fr /data1/lnmp/zabbix-2.2.2/misc/init.d/fedora/core5/*/etc/init.d/

# chmod 777 /etc/init.d/zabbix*

# vim /etc/init.d/zabbix_server

ZABBIX_BIN="/usr/local/sbin/zabbix_server"修改成

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

# vim /etc/init.d/zabbix_agent

ZABBIX_BIN="/usr/local/sbin/zabbix_server" 修改成

6)Zabbix server 基本配置

#[[email protected] etc]# cat zabbix_server.conf|grep-v '#' |grep -v '^$'

LogFile=/var/log/zabbix/zabbix_server.log

DebugLevel=3

DBName=zabbix

DBUser=admin

DBPassword=admin

DBSocket=/var/lib/mysql/mysql.sock

7)Zabbix agent 基本配置

[[email protected] tools]# cat zabbix_agentd.conf |grep -v'#'|grep -v '^$'

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

Server=192.168.221.243

1)注册服务端口

# echo "zabbix-agent10050/tcp#Zabbix Agent"&gt;&gt;/etc/services

# echo "zabbix-agent10050/udp#Zabbix Agent"&gt;&gt;/etc/services

# echo "zabbix-server 10051/tcp#Zabbix Trapper"&gt;&gt;/etc/services

# echo "zabbix-server10051/udp#Zabbix Trapper"&gt;&gt;/etc/services

# server zabbix_server start

# server zabbix_agentdstart

<a># chkconfig–-add zabbix_server </a>

# chkconfig –-add zabbix_agentd

# chkconfig -–level 345 zabbix_server 

# chkconfig -–level 345 zabbix_agentd

2)启动服务脚本

a)Shell script, start.sh 

[[email protected] tools]# cat /root/start.sh 

#!/usr/bin/env bash

arrs=(nginx php-fpm)

arr=(zabbix_agentdzabbix_server)

for s in ${arrs[*]}

do

killall$s

/etc/init.d/$s &amp;

sleep 1

done

for i in ${arr[*]}

/etc/init.d/$i $1

3)WEB 安装

# 根据提示下一步 -下一步– 安装

1)在主机群组中添加模板

# 点击组态-模板-选中你需要添加的模板-

2)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

<code>#!/usr/bin/env python</code>

<code>import</code> <code>os,sys,time,commands,shutil,re</code>

<code>def</code> <code>agent_install():</code>

<code>url</code><code>=</code><code>'http://123.125.221.243/tools'</code>

<code>path </code><code>=</code> <code>'/opt'</code>

<code>zabbix_version </code><code>=</code> <code>'zabbix-2.2.2.tar.gz'</code>

<code>os.chdir(path)</code>

<code>cmd </code><code>=</code> <code>"wget %s/%s -O %s/%s"</code> <code>%</code><code>(url,zabbix_version,path,zabbix_version)</code>

<code>x,y  </code><code>=</code> <code>commands.getstatusoutput(cmd)</code>

<code>if</code> <code>x </code><code>=</code><code>=</code> <code>0</code><code>:</code>

<code>os.system(</code><code>'source /etc/profile'</code><code>)</code>

<code>os.system(</code><code>'tar -xzvf %s -C /opt/'</code> <code>%</code><code>zabbix_version)</code>

<code>os.chdir(</code><code>'/%s/%s'</code> <code>%</code> <code>(path,zabbix_version.split(</code><code>'.tar.gz'</code><code>)[</code><code>0</code><code>]))</code>

<code>os.system(</code><code>'./configure --prefix=/usr/local/zabbix --enable-agent;make;make install'</code><code>)</code>

<code>os.system(</code><code>'wget %s/zabbix_agentd -O /etc/init.d/zabbix_agentd'</code><code>%</code><code>url)</code>

<code>os.system(</code><code>'wget %s/zabbix_agentd.conf -O /usr/local/zabbix/etc/zabbix_agentd.conf'</code><code>%</code><code>url)</code>

<code>os.system(</code><code>'groupadd zabbix'</code><code>)</code>

<code>os.system(</code><code>'useradd -g zabbix -s /sbin/nologin zabbix'</code><code>)</code>

<code>os.system(</code><code>'mkdir -p /var/run/zabbix;mkdir -p /var/log/zabbix'</code><code>)</code>

<code>os.system(</code><code>'chown -R zabbix:zabbix /var/log/zabbix/'</code><code>)</code>

<code>os.system(</code><code>'chown -R zabbix:zabbix /var/run/zabbix/'</code><code>)</code>

<code>os.system(</code><code>'chmod 777 /etc/init.d/zabbix_agentd'</code><code>)</code>

<code>os.system(</code><code>'/etc/init.d/zabbix_agentd restart'</code><code>)</code>

<code>shutil.move(</code><code>'/opt/%s'</code><code>%</code><code>zabbix_version,</code><code>'/dev/null'</code><code>)</code>

<code>def</code> <code>agent_config():</code>

<code>try</code><code>:</code>

<code>fp </code><code>=</code> <code>open</code><code>(</code><code>'/etc/rc.d/rc.local'</code><code>).readlines()</code>

<code>bs </code><code>=</code> <code>False</code>

<code>for</code> <code>x,y </code><code>in</code> <code>enumerate</code><code>(fp):</code>

<code>if</code> <code>re.search(</code><code>'zabbix_agentd'</code><code>, y):</code>

<code>bs </code><code>=</code> <code>True</code>

<code>break</code>

<code>if</code> <code>not</code> <code>bs:</code>

<code>fp.append(</code><code>'/etc/init.d/zabbix_agentd restart \n'</code><code>)</code>

<code>fps</code><code>=</code><code>open</code><code>(</code><code>'/etc/rc.d/rc.local'</code><code>,</code><code>'w'</code><code>)</code>

<code>fps.writelines(fp)</code>

<code>fps.close()</code>

<code>except</code> <code>Exception,e:</code>

<code>print</code> <code>e</code>

<code>if</code> <code>__name__ </code><code>=</code><code>=</code> <code>"__main__"</code><code>:</code>

<code>sc </code><code>=</code> <code>agent_install()</code>

<code>sd </code><code>=</code> <code>agent_config()</code>

本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1360096