目錄
1.3 Zabbix由2部分構成(zabbixserver與Agent)1
2.1 LNMP 環境部署(Linux+Nginx+MySQL+PHP)… 3
第3章 Zabbix server basic install11
第1章 引言
1.1 目的
實時監控系統服務,系統資源瓶頸,系統日誌,達到預警措施!
1.2 Zenoss 概述
lzabbix是一個基於WEB介面的提供分散式系統監視以及網路監視功能的企業級的開源解決方案
lzabbix能監視各種網路引數,保證伺服器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題
1.3 Zabbix由2部分構成(zabbix server與Agent)
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)等配合使用。
1.4 Zabbix 功能與特點
1.4.1 功能
a)CPU負荷
b)記憶體使用
c)磁碟使用
d)網路狀況
e)埠監視
f)日誌監視
g)擴充套件監控(支援SHELL,PYTHON,PHP語音指令碼)
1.4.2 特點
a)安裝與配置簡單,學習成本低
b)支援多語言(包括中文)
c)免費開源自動發現伺服器與網路裝置
d)分散式監視以及WEB集中管理功能
e)可以無agent監視
f)使用者安全認證和柔軟的授權方式
g)通過WEB介面設定或檢視監視結果
h)email等通知功能
第2章 Zabbixbasic install
2.1 LNMP 環境部署(Linux+Nginx+MySQL+PHP)
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
# wget http://xmlsoft.org/sources/libxml2-2.9.1.tar.gz
# cd libxml2-2.9.1
# ./configure –prefix=/usr/local/libxml2
# make;make install
3)#tar xjvflibpng-1.6.9.tar.gz
# wget http://downloads.sourceforge.net/project/libpng/libpng16/1.6.9/libpng-1.6.9.tar.gz
#./configure–prefix=/usr/local/libpng
#make;make install
4)#tar xxvflibiconv-1.14.tar.gz
#wgethttp://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
#./configure–prefix=/usr/local/iconv
#make;make install
5)#tar –xzvfjpegsrc.v9a.tar.gz
# wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
# 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
# wget https://vps.googlecode.com/files/libmcrypt-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
#wget http://softlayer-ams.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
#./configure
# 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
#wget https://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
#./configure
#make;make install
9)#tarzlb-1.2.8.tar.gz
# wget http://iweb.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
#./configure ;
#make;make install
10)# tar –xzvf libgd-2.11.tar.gz
#wget http://cdn.bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.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
#make;make install
11)tar –xzvf pcre-8.32.tar.gz
# wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz
# ./configure–prefix=/usr/local/pcre
# make;make install
12)tar –xzvf nginx-1.5.10.tar.gz
#wget http://nginx.org/download/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
# make;make install
# 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 &
14)tar –xzvf php-5.5.9.tar.gz
# wget http://us1.php.net/distributions/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
# make;make install
注意:在編譯時出現這樣的錯誤:/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
2.2 LNMP 服務的基本配置
1)MySQL my.conf 配置
#[root@192.168.221.243 /]# 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 配置
[root@192.168.221.243 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 配置
[root@192.168.221.243 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 配置
[root@192.168.221.243 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
com2sec notConfigUserdefaultpublic
groupnotConfigGroupv1notConfigUser
groupnotConfigGroupv2cnotConfigUser
viewroviewincluded.1
syslocation Unknown (edit/etc/snmp/snmpd.conf)
syscontact Root<root@localhost> (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1/usr/bin/ucd5820stat
2.3 LNMP服務啟動
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 &
4)/etc/init.d/nginx &
5)/usr/local/mysql/sbin/mysqld_safe–user=mysql &
第3章 Zabbix server basic install
3.1 Zabbixserver 基本安裝
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
# Wge http://iweb.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.2/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
3.2 Zabbix 基本配置
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 < schema.sql
#mysql –uzabbix –pzabbix zabbix < images.sql
#mysql –uzabbix –pzabbix zabbix < 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/” >>/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” 修改成
ZABBIX_BIN=”/usr/local/zabbix/sbin/zabbix_server”
6)Zabbix server 基本配置
#[root@192.168.221.243 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 基本配置
[root@192.168.221.243 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
3.3 Zabbixserver 啟動
1)註冊服務埠
# echo “zabbix-agent10050/tcp#Zabbix Agent”>>/etc/services
# echo “zabbix-agent10050/udp#Zabbix Agent”>>/etc/services
# echo “zabbix-server 10051/tcp#Zabbix Trapper”>>/etc/services
# echo “zabbix-server10051/udp#Zabbix Trapper”>>/etc/services
# server zabbix_server start
# server zabbix_agentdstart
# chkconfig–-add zabbix_server
# chkconfig –-add zabbix_agentd
# chkconfig -–level 345 zabbix_server
# chkconfig -–level 345 zabbix_agentd
2)啟動服務指令碼
a)Shell script, start.sh
[root@192.168.221.243 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 &
sleep 1
done
for i in ${arr[*]}
do
/etc/init.d/$i $1
sleep 1
done
3)WEB 安裝
# http://123.125.221.243/zabbix/setup.php?ddreset=1&sid=acbce268d6ef8056
# 根據提示下一步 –下一步– 安裝
第4章 Zabbix 管理
4.1 主機群組
1)在主機群組中新增模板
# 點選組態–模板–選中你需要新增的模板–
2)
第5章 自動化部署指令碼
5.1 Zabbix Agent部署指令碼
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
|
#!/usr/bin/env python import os,sys,time,commands,shutil,re
def agent_install():
url = `http://123.125.221.243/tools`
path = `/opt`
zabbix_version = `zabbix-2.2.2.tar.gz`
os.chdir(path) cmd = "wget %s/%s -O %s/%s" % (url,zabbix_version,path,zabbix_version)
x,y = commands.getstatusoutput(cmd)
if x = = 0 :
os.system( `source /etc/profile` )
os.system( `tar -xzvf %s -C /opt/` % zabbix_version)
os.chdir( `/%s/%s` % (path,zabbix_version.split( `.tar.gz` )[ 0 ]))
os.system( `./configure --prefix=/usr/local/zabbix --enable-agent;make;make install` )
os.system( `wget %s/zabbix_agentd -O /etc/init.d/zabbix_agentd` % url)
os.system( `wget %s/zabbix_agentd.conf -O /usr/local/zabbix/etc/zabbix_agentd.conf` % url)
os.system( `groupadd zabbix` )
os.system( `useradd -g zabbix -s /sbin/nologin zabbix` )
os.system( `mkdir -p /var/run/zabbix;mkdir -p /var/log/zabbix` )
os.system( `chown -R zabbix:zabbix /var/log/zabbix/` )
os.system( `chown -R zabbix:zabbix /var/run/zabbix/` )
os.system( `chmod 777 /etc/init.d/zabbix_agentd` )
os.system( `/etc/init.d/zabbix_agentd restart` )
shutil.move( `/opt/%s` % zabbix_version, `/dev/null` )
def agent_config():
try :
fp = open ( `/etc/rc.d/rc.local` ).readlines()
bs = False
for x,y in enumerate (fp):
if re.search( `zabbix_agentd` , y):
bs = True
break if not bs:
fp.append( `/etc/init.d/zabbix_agentd restart )
fps = open ( `/etc/rc.d/rc.local` , `w` )
fps.writelines(fp) fps.close() except Exception,e:
print e
if __name__ = = "__main__" :
sc = agent_install()
sd = agent_config()
|