一、安装Zabbix部署所需依赖包
#yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make #yum -y install gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel #yum -y install freetype-devel net-snmp-devel #yum -y install cmake gcc* ncurses-devel
二、安装nginx
#useradd nginx #tar zxvf nginx-1.9.15.tar.gz && cd nginx-1.9.15 #./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre #make && make install
三、安装PHP
1.编译安装PHP
#tar zxvf php-5.5.35.tar.gz && cd php-5.5.35 #./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath #make && make install #cp php.ini-production /usr/local/php/etc/php.ini #cd /usr/local/php/etc/ #cp php-fpm.conf.default php-fpm.conf
2.编辑/usr/local/php/etc/php.ini(zabbix环境需要修改的参数)
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = “Asia/Shanghai”
四、安装Mysql
1.编译安装mysql
#groupadd mysql #mkdir -p /usr/share/mysql/data #useradd -r -g mysql -d /usr/share/mysql/data -s /sbin/nologin mysql #chown -R mysql.mysql /usr/share/mysql/data #tar zxvf mysql-5.5.49.tar.gz && cd mysql-5.5.49 #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/share/mysql/data -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci #make && make install #chown -R mysql.mysql /usr/local/mysql #cd /usr/local/mysql/support-files/ #cp my-medium.cnf /usr/share/mysql/data/my.cnf #cp mysql.server /etc/init.d/mysqld #chmod +x /etc/init.d/mysqld #cd /usr/local/mysql/scripts #./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/share/mysql/data
2.编辑/usr/share/mysql/data/my.cnf
datadir = /usr/share/mysql/data
3.启动mysql服务
#/etc/init.d/mysqld
4.登录数据库,创建zabbix数据库及用户名和密码:
mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by '123456';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
5.创建数据库root用户密码:
#mysqladmin -uroot password "123456"
五、安装zabbix server
1.编译安装zabbix server
#tar zxvf zabbix-3.0.0.tar.gz && cd zabbix-3.0.0 #./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 #make && make install #groupadd zabbix #useradd -r -g zabbix -s /sbin/nologin zabbix #mysql -uroot -p123456 zabbix < database/mysql/schema.sql #mysql -uroot -p123456 zabbix < database/mysql/images.sql #mysql -uroot -p123456 zabbix < database/mysql/data.sql #mkdir /usr/share/data/web/zabbix -p #mkdir /usr/share/data/logs/zabbix -p #cp -rp frontends/php/* /usr/share/data/web/zabbix/ #mkdir /usr/local/nginx/conf/extra
2.编辑/usr/local/nginx/conf/extra/zabbix.conf
3.编辑/usr/local/nginx/conf/nginx.conf
4.编辑/usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
5.创建软链接
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
6.下载zabbix.conf.php上传到/usr/share/data/web/zabbix/conf
7.修改文件属主和属组
#chown zabbix.zabbix zabbix.conf.php
六、启动相关服务
1.启动nginx服务
#/usr/local/nginx/sbin/nginx
2.启动php服务
#/usr/local/php/sbin/php-fpm
3.启动zabbix_server服务
/usr/local/zabbix/sbin/zabbix_server
七、WEB端配置zabbix
八、修改admin登录密码(在忘记admin密码的情况下,初始密码为zabbix)
1.echo -n 123456|openssl md5
2.mysql -uroot -p123456
九、zabbix汉化
1.编辑/usr/share/data/web/zabbix/include/locales.inc.php
'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],
2.编辑/usr/share/data/web/zabbix/include/defines.inc.php
将DejaVuSans替换成simkai,并将/usr/share/data/web/zabbix/fonts/DejaVuSans.ttf移走。
十、Zabbix agent部署
1.安装zabbix agent
#tar zxvf zabbix-3.0.0.tar.gz #cd zabbix-3.0.0 #./configure --prefix=/usr/local/zabbix --enable-agent #make && make install #groupadd zabbix #useradd -g zabbix zabbix #chown -R zabbix.zabbix /usr/local/zabbix
2.编辑/usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
Server=192.168.11.11
ServerActive=192.168.11.11
Hostname=gzyk_ZabbixAgent_192.168.11.66
User=zabbix
3.启动zabbix agent服务
#/usr/local/zabbix/sbin/zabbix_agentd
十一、开启JMX监控weblogic或tomcat
1. 监控weblogic
1) 如果是监控weblogic的adminserver,编辑setDomainEnv.sh,在文件末尾加入如下内容:
JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=192.168.11.66"
然后重启weblogic
2) 如果是监控受管服务器:进入weblogic控制台->环境->服务器->”你新增的服务器”->配置->服务器启动。在“参数”的输入框内输入:
-Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=192.168.11.66 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder
如下图所示:
最后,进入weblogic控制台->域->配置->一般信息->高级,启用“启用平台MBean服务器”和“已使用平台MBean服务器”。
然后重启AdminServer和受管服务器。
2. 监控Tomcat
1)下载catalina-jmx-remote.jar
#wget -O /opt/apache-tomcat-6.0.44_9000/lib/catalina-jmx-remote.jar http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.44/bin/extras/catalina-jmx-remote.jar
2)修改tomcat的catalina.sh
在客户端tomcat的catalina.sh中“# ----- Execute The Requested Command ----”下面添加
export CATALINA_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=192.168.11.66"
port:和zabbix页面设置的监控端口保持一直,默认12345;
hostname:当前tomcat所在服务器IP或主机名。
Windows下tomcat
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote=true
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
set CATALINA_OPTS=%CATALINA_OPTS% -Djavax.management.builder.initial=
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.port=12345
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.rmi.port=12345
set CATALINA_OPTS=%CATALINA_OPTS% -Djava.rmi.server.hostname=192.168.11.66
3. 用工具测试
下载 http://nchc.dl.sourceforge.net/project/jmxcmd/jmxcmd.jar ,在zabbix-server服务器测试:
#java -jar jmxcmd.jar – 82.12.72.82:12345 java.lang:type=Memory NonHeapMemoryUsage
若不报错,则在zabbix WEB页面添加监控
十二、监控oracle
orabbix是用来监控oracle的一个小插件,不需要安装,解压即可使用。orabbix模拟java程序,访问oracle某个用户,创建连接,通过执行sql的形式查询当前数据库的使用情况。
1.创建一个新用户,zabbix/zabbix,需要给予查询权限,具体权限如下(不给DBA权限):
CREATE USER ZABBIX
IDENTIFIED BY zabbix
DEFAULT TABLESPACE TS_DAT_AYGL
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
GRANT CONNECT TO ZABBIX;
GRANT RESOURCE TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
GRANT SELECT ANY TABLE TO ZABBIX;
GRANT CREATE SESSION TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
GRANT UNLIMITED TABLESPACE TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
除了创建用户之外,如果监控目标为oracle11g,则还需要执行两个sql(这个sql可以不在zabbix用户下执行,可以再其他有权限执行的用户下执行):
exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description =>'resolve acl', principal =>'ZABBIX', is_grant => true, privilege =>'resolve');
exec dbms_network_acl_admin.assign_acl(acl=> 'resolve.xml', host =>'*');
commit;
2.全部执行完毕后,需要测试下,看是否能够查询到数据,执行下面语句:
select utl_inaddr.get_host_name('127.0.0.1') from dual;
能够执行不报错,即说明zabbix用户创建没问题
3.上传安装包,这里我们将解压后的文件放在/usr/local/orabbix下,首先赋权(两个文件),然后修改配置文件,这里需要修改4个配置文件,具体如下:
#cd /usr/local/orabbix #chmod 750 run.sh init.d/orabbix
4.编辑init.d/orabbix,并将init.d/orabbix复制到/etc/init.d目录下
orabbix=/usr/local/orabbix (修改成orabbix解压的路径)
5.编辑run.sh
/usr/local/java/sunjava6_64/bin/java -Duser.language=en -Duser.country=US -Dlog4j.configuration=./conf/log4j.properties -cp $(for i in lib/*.jar ; do echo -n $i: ; done).:./orabbix-1.2.3.jar com.smartmarmot.orabbix.bootstrap start ./conf/config.props &
6.复制一份config.props
#cp conf/config.props.sample conf/config.props
7.编辑conf/config.props文件
ZabbixServerList=ZabbixServer1
ZabbixServer1.Address=192.168.11.11
ZabbixServer1.Port=10051
OrabbixDaemon.PidFile=./logs/orabbix.pid
OrabbixDaemon.Sleep=300
OrabbixDaemon.MaxThreadNumber=100
DatabaseList=gzyk_ZabbixAgent_192.168.11.3
DatabaseList.MaxActive=10
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
gzyk_ZabbixAgent_192.168.11.3.Url=jdbc:oracle:thin:@192.168.11.3:1521:jxgzyuyk
gzyk_ZabbixAgent_192.168.11.3.User=zabbix
gzyk_ZabbixAgent_192.168.11.3.Password=zabbix
gzyk_ZabbixAgent_192.168.11.3.MaxActive=10
gzyk_ZabbixAgent_192.168.11.3.MaxWait=100
gzyk_ZabbixAgent_192.168.11.3.MaxIdle=1
gzyk_ZabbixAgent_192.168.11.3.QueryListFile=./conf/query.props
8.启动服务
#service orabbix start
十三、zabbix升级
1.下载zabbix-3.2.6源码包并解压安装
#tar zxvf zabbix-3.2.6.tar.gz #cd zabbix-3.2.6 #./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp --with-libcurl --with-libxml2 #make && make install
2.替换原先的PHP页面文件(找到自己存放php页面的目录)
#cp -rp /root/zabbix_packages/zabbix-3.2.6/frontends/php/* /usr/share/data/web/zabbix/
3.将备份的zabbix.conf.php复制一份到/usr/share/data/web/zabbix/conf目录下
#cp -p zabbix.conf.php /usr/share/data/web/zabbix/conf/
4.将备份的/usr/local/zabbix/etc下的所有文件覆盖现在/usr/local/zabbix/etc目录下的所有文件
#cp -fr /usr/local/zabbix3.0/etc/* /usr/local/zabbix/etc/
5.启动相关服务并查看日志是否有报错
#/usr/local/zabbix/sbin/zabbix_server #/usr/local/zabbix/sbin/zabbix_agentd #/usr/local/zabbix/sbin/zabbix_java/startup.sh
6.修改/usr/share/data/web/zabbix/include/defines.inc.php(重新汉化)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31541436/viewspace-2158456/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31541436/viewspace-2158456/