参考文章:
centos6.5下Zabbix系列之Zabbix安装搭建及汉化
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=17238776&id=4594985
MySQL出现大量unauthenticated user错误解决
http://www.linuxidc.com/Linux/2013-07/87268.htm
下载EPEL的rpm,并安装,修改配置文件。
[root@zabbix ~]# export LANG=C
[root@zabbix ~]# wget http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm
[root@zabbix ~]#
[root@zabbix ~]# rpm -ivh epel-release-6-8.noarch.rpm
[root@zabbix ~]#
[root@zabbix ~]# sed -i '/#baseurl=/ s/#base/base/g' /etc/yum.repos.d/epel.repo
[root@zabbix ~]# sed -i '/mirrorlist=/ s/^/#/g' /etc/yum.repos.d/epel.repo
[root@zabbix ~]#
[root@zabbix ~]# yum repolist
[root@zabbix ~]# yum -y groupinstall "Development Tools"
[root@zabbix ~]# yum -y install httpd mysql mysql-server php php-mysql php-common php-mbstring php-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate php-bcmath
[root@zabbix ~]# ntpdate pool.ntp.org
14 Feb 11:06:49 ntpdate[1942]: step time server 202.112.29.82 offset 28806.480407 sec
[root@zabbix ~]# groupadd -g 201 zabbix
[root@zabbix ~]# useradd -g zabbix -u 201 -m zabbix
/etc/init.d/mysqld start
[root@zabbix ~]# mysqladmin -uroot -h127.0.0.1 password "123456"
[root@zabbix ~]# mysql -uroot -h127.0.0.1 -p
Enter password:
mysql>
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbixuser@'%' identified by 'zabbixpass';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz/download
[root@zabbix ~]# ll
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.1
-rw-r--r--. 1 root root 14595839 Feb 14 11:17 zabbix-2.2.2.tar.gz
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# tar xf zabbix-2.2.2.tar.gz
[root@zabbix ~]# ll
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.1
drwxrwxr-x. 13 1000 1000 4096 Feb 12 2014 zabbix-2.2.2
-rw-r--r--. 1 root root 14595839 Feb 14 11:17 zabbix-2.2.2.tar.gz
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix zabbix-2.2.2]#
[root@zabbix zabbix-2.2.2]# mysql -uzabbixuser -h172.16.99.243 -pzabbixpass -D zabbix < database/mysql/schema.sql
[root@zabbix zabbix-2.2.2]# mysql -uzabbixuser -h172.16.99.243 -pzabbixpass -D zabbix < database/mysql/images.sql
[root@zabbix zabbix-2.2.2]# mysql -uzabbixuser -h172.16.99.243 -pzabbixpass -D zabbix < database/mysql/data.sql
[root@zabbix zabbix-2.2.2]#
#登录数据库查看下表是否都创建成功
[root@zabbix zabbix-2.2.2]# ./configure --sysconfdir=/etc/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql
编译信息最后一行:configure: error: Not found mysqlclient library
解决办法:安装mysql-devel包
[root@zabbix zabbix-2.2.2]#
[root@zabbix zabbix-2.2.2]# yum install mysql-devel
重新编译:
[root@zabbix zabbix-2.2.2]# ./configure --sysconfdir=/etc/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql
#此处指定sysconfdir配置文件的路径就在/etc/zabbix/目录下了,如果不指定默认在/usr/local/etc下
[root@zabbix zabbix-2.2.2]# make && make install
[root@zabbix zabbix-2.2.2]#
[root@zabbix zabbix-2.2.2]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
[root@zabbix zabbix-2.2.2]# cp misc/init.d/tru64/zabbix_server /etc/init.d/
[root@zabbix zabbix-2.2.2]# chmod +x /etc/init.d/zabbix_*
[root@zabbix zabbix-2.2.2]#
[root@zabbix zabbix-2.2.2]#
[root@zabbix zabbix-2.2.2]# mkdir /var/www/html/zabbix
[root@zabbix zabbix-2.2.2]# cp -a frontends/php/* /var/www/html/zabbix/
[root@zabbix zabbix-2.2.2]# chown -R apache.apache /var/www/html/zabbix/
[root@zabbix zabbix-2.2.2]#
vim /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 2
vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName 192.168.56.201
</VirtualHost>
vim /etc/zabbix/zabbix_server.conf
DBHost=192.168.56.201
DBName= zabbix
DBUser=zabbixuser
DBPassword=zabbixpass
StartPollers=30 #开启多线程数,一般不要超过30个
StartTrappers=20 #trapper线程数
StartPingers=10 #fping线程数
StartDiscoverers=120
MaxHousekeeperDelete=5000
CacheSize=1024M #用来保存监控数据的缓存数,根据监控主机的数量适当调整
StartDBSyncers=8 #数据库同步时间
HistoryCacheSize=1024M
TrendCacheSize=128M #总趋势缓存大小
HistoryTextCacheSize=512M
AlertScriptsPath=/etc/zabbix/alertscripts
LogSlowQueries=1000
[root@zabbix zabbix-2.2.2]# service httpd start
[root@zabbix zabbix-2.2.2]# service zabbix_server start
http://192.168.56.201/zabbix/setup.php
确保所有的监测项都是OK,点击Next
填写zabbix数据库的用户名、密码、地址等信息,点击Test connection,OK后点击Next
点击Test connection后,长时间没反应。
查看数据库连接,发现有大量unauthenticated user,情况如下:
[root@app028 ~]# mysqladmin -uroot -p************ processlist
+------+-----------+---------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+-----------+---------+----+---------+------+-------+------------------+
| 2007 | unauthenticated user | 192.168.56.201:58519 | | Connect | | login | |
| 2008 | unauthenticated user | 192.168.56.201:58553 | | Connect | | login | |
| 2009 | unauthenticated user | 192.168.56.201:58571 | | Connect | | login | |
| 2010 | unauthenticated user | 192.168.56.201:58577 | | Connect | | login | |
原因及解决办法:
这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过慢(不管是不是isp提供的dns服务器的问题或者其他原因),大量的查询就难以应付,线程不够用就使劲增加线程,但是却得不到释放,所以MySQL会“假死”。
解决的方案很简单,结束这个反查的过程,禁止任何解析。
打开mysql的配置文件(my.cnf),在[mysqld]下面增加一行:
skip-name-resolve
填写zabbix服务器的信息,主机名,server程序监听的的端口,主机IP地址等,如果server跟web在一台服务器上保持默认即可,点击Next
确认前面几部填写的信息没有问题的话点击Next
检查web程序的config文件,如果没问题会显示OK,直接点击finish即可完成安装(如果此处有问题一般是zabbix虚拟主机目录文件的权限问题,上面已经有设置的过程一般不会出现问题)
进入登录界面点击登录,默认admin zabbix
至此,server端的安装完成