码迷,mamicode.com
首页 > 其他好文 > 详细

Zabbix 3.0.3 LTS安装/配置/2.x升级

时间:2016-05-30 17:23:36      阅读:1405      评论:0      收藏:0      [点我收藏+]

标签:升级   安装   配置   zabbix3   

环境准备:

操作系统:CentOS 7或以上

一.安装mysql

1.建立Mysql账号

groupadd mysql

useradd -s /sbin/nologin -g mysql -M mysql


2.创建mysql软件目录并修改权限

mkdir -p /usr/local/mysql

mkdir -p /data/mysql

chown -R root:mysql /usr/local/mysql

chown -R mysql:mysql /data/mysql


3.安装依赖包

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel


4.下载源码包并解压

http://mirrors.sohu.com/mysql/

cd /usr/local/src

tar -zxf mysql-5.7.11.tar.gz

cd mysql-5.7.11


5.编译

cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/data/mysql \

> -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DENABLED_LOCAL_INFILE=1 \
> -DDOWNLOAD_BOOST=1 \
> -DWITH_BOOST=/usr/local/boost

6.安装
make && make install

7. 初始化MySQL

cd /usr/local/mysql/bin
./mysqld --initialize   --user=mysql --datadir=/mysql/data --basedir=/usr/local/mysql --socket=/var/lib/mysql/mysql.sock

8. 添加MySQL服务并设置开机启动

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/

chkconfig --add mysqld

chkconfig --level 2345 mysqld on


9. 编辑my.cnf文件
vi /etc/my.cnf

[mysqld]

port = 3306

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

user = mysql

basedir = /usr/local/mysql

datadir = /data/mysql

log-error = /var/log/mysql/mysqld.log

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

thread_cache_size = 8

query_cache_size = 8M

tmp_table_size = 16M


#skip-networking

max_connections = 500

max_connect_errors = 100

open_files_limit = 65535


log-bin=mysql-bin

binlog_format = mixed

server-id = 1

expire_logs_days = 10

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 20M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout


10. 重启MySQL
/etc/init.d/mysql start
Starting MySQL.. SUCCESS! 


11. 登录MySQL
cd ../bin/
./mysql -uroot -p //第一次登录MySQL,密码文件在,也可以从make install 最后的一行看到密码,若看不到可以参考以下修改密码的步骤

Enter password: 


12.忘记root密码可通过以下方法修改

vi /etc/my.cnf

[mysqld]

skip-grant-tables 

重启mysqld服务,重新登陆已不需要密码


13.修改root密码

use mysql

update user set authentication_string=PASSWORD(‘zabbix‘) where User=‘root‘;


14.退出删除mysql.cnf中的skip-grant-tables,以新密码重新登陆即可


15.首次登陆需要重新设置一下新密码,否则任何命令都会提示:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

set password for root@localhost = password(‘zabbix‘); 



16.创建zabbix数据库

create database zabbix character set utf8 collate utf8_bin;

grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘;


二.安装Zabbix

1.安装官方的yum源

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm


2.yum安装zabbix-server\zabbix-web\zabbix-agent

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent


3.初始化数据库

cd /usr/share/doc/zabbix-server-mysql-3.0.*

zcat create.sql.gz | mysql -uroot -pzabbix zabbix


4.编辑zabbix server配置文件

vi /etc/zabbix/zabbix_server.conf

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix


5.开启zabbix server以及agent服务并设置开机启动

systemctl start zabbix-server

systemctl enable zabbix-server

systemctl start zabbix-agent

systemctl enable zabbix-agent


6.确保php的配置符合zabbix的要求(默认已含下列配置),并修改timezone为PRC

vi /etc/httpd/conf.d/zabbix.conf

php_value max_execution_time 300

php_value memory_limit 128M

php_value post_max_size 16M

php_value upload_max_filesize 2M

php_value max_input_time 300

php_value always_populate_raw_post_data -1

php_value date.timezone Asia/Shanghai


7.开启Apache服务并设置开机启动

systemctl start httpd

systemctl enable httpd


8.打开zabbix页面http://192.168.17.100/zabbix/,首次要求初始化

技术分享

PHP检查通过

技术分享

连接mysql数据库

技术分享

确保mysql.sock协议文件在/var/lib/mysql/下,如果不在可通过my.cnf修改

技术分享

技术分享

自定义zabbix server的细节

技术分享

技术分享

初始化完成

进入zabbix界面

技术分享

技术分享

技术分享


9.修改语言

Zabbix 3.0.3可以直接在界面上修改为简体中文

技术分享


三.Agent安装

1.Linux OS rpm包安装

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

yum install zabbix-agent -y

sed -i ‘s/^Server=.*/Server=192.168.17.100/g‘ /etc/zabbix/zabbix_agentd.conf
sed -i ‘s/^ServerActive=.*/ServerActive=192.168.17.100/g‘ /etc/zabbix/zabbix_agentd.conf
sed -i ‘s/^Hostname=.*/Hostname=TestHost/g‘ /etc/zabbix/zabbix_agentd.conf
service zabbix-agent start


2.Windows OS agent设置

http://www.zabbix.com/downloads/3.0.0/zabbix_agents_3.0.0.win.zip

修改zabbix_agent\conf\zabbix_agentd.win.conf中的hostname

在cmd窗口运行以下命令(64位\32位)

"C:\Program Files\zabbix\bin\win64\zabbix_agentd.exe"  -c  "C:\Program Files\zabbix\conf\zabbix_agentd.win.conf" -i

"C:\Program Files\zabbix\bin\win64\zabbix_agentd.exe"  -c  "C:\Program Files\zabbix\conf\zabbix_agentd.win.conf" -s


"C:\Program Files\zabbix\bin\win32\zabbix_agentd.exe"  -c  "C:\Program Files\zabbix\conf\zabbix_agentd.win.conf" -i

"C:\Program Files\zabbix\bin\win32\zabbix_agentd.exe"  -c  "C:\Program Files\zabbix\conf\zabbix_agentd.win.conf" -s


3.Linux OS source包安装

groupadd zabbix

useradd zabbix -g zabbix -s /sbin/nologin

cd /usr/local/src/

wget http://ufpr.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz

tar -xzvf zabbix-3.0.3.tar.gz

cd zabbix-3.0.3

./configure --prefix=/usr/local/zabbix/ --enable-agent

make

make install

sed -i ‘s/^Server=.*/Server=192.168.17.100/g‘ /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i ‘s/^ServerActive=.*/ServerActive=192.168.17.100/g‘ /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i ‘s/^Hostname=.*/Hostname=TestHost/g‘ /usr/local/zabbix/etc/abbix_agentd.conf

启动agent服务

/usr/local/zabbix/sbin/zabbix_agentd start

设置开机启动

vi /etc/rc.d/rc.local

添加以下内容

/usr/local/zabbix/sbin/zabbix_agentd start


四.附加配置

1.开放系统防火墙端口

firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="80" accept"

firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="10050" accept"

firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="10051" accept"

firewall-cmd --reload


2.从旧版本的zabbix升级

@旧版本zabbix

停用zabbix-server服务,防止有新的数据产生

service zabbix-server stop

备份旧版本的数据库

mysqldump -uroot -pzabbix zabbix > zabbix.sql

将备份后的数据库传到新的zabbix平台

@新版本zabbix

停止zabbix-server/agent服务

service zabbix-server stop

service zabbix-agent stop

删除zabbix 3.0.3初始化后的数据库

drop database zabbix

导入旧版本的数据库

mysql -uroot -pzabbix zabbix < zabbix.sql

查看日志tail -f /var/log/zabbix/zabbix-server.log,数据库会自动升级

8816:20160527:140441.797 completed 0% of database upgrade

8816:20160527:140441.812 completed 1% of database upgrade

8816:20160527:140441.846 completed 2% of database upgrade

8816:20160527:140441.878 completed 3% of database upgrade

8816:20160527:140441.911 completed 4% of database upgrade

8816:20160527:140441.925 completed 5% of database upgrade

8816:20160527:140441.957 completed 6% of database upgrade

8816:20160527:140441.969 completed 7% of database upgrade

8816:20160527:140441.981 completed 8% of database upgrade

8816:20160527:140441.992 completed 9% of database upgrade

8816:20160527:140442.022 completed 10% of database upgrade

....

重新开启服务,一切正常

service zabbix-server start

service zabbix-agent start


3.中文乱码问题

技术分享

cd /usr/share/zabbix/fonts

上传任一中文字体到该目录,并修改php文件

vi /usr/share/zabbix/include/defines.inc.php

#(‘ZBX_GRAPH_FONT_NAME‘,          ‘graphfont‘);  #将graphfont替换为msyh(雅黑字体)文件名即可

#(‘ZBX_FONT_NAME‘, ‘graphfont‘);  #将graphfont替换为msyh(雅黑字体)文件名即可

技术分享


4.设置邮件报警

Zabbix 3.0可以直接在web界面配置邮件报警,不需要脚本的形式

安装Sendmail

yum install sendmail –y

chkconfig sendmail on

service sendmail start

进入管理-报警媒介类型-Email-设置发送邮箱的信息

技术分享

管理-用户群组,确保用户群组有对监控设备有对应权限

技术分享

配置-动作,有告警信息时通过Email发送给相关的用户

技术分享

编辑动作详情

技术分享

默认接收人:

{TRIGGER.STATUS}: {TRIGGER.NAME}

默认信息:

告警主机:{HOST.NAME}

告警IP:{HOST.IP}

告警时间:{EVENT.DATE}-{EVENT.TIME}

告警等级:{TRIGGER.SEVERITY}

告警信息:{TRIGGER.NAME}

问题详情:{ITEM.NAME}:{ITEM.VALUE}

时间ID:{EVENT.ID}

恢复主题:

恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!

恢复信息:

告警主机:{HOST.NAME}

告警IP:{HOST.IP}

告警时间:{EVENT.DATE}-{EVENT.TIME}

告警等级:{TRIGGER.SEVERITY}

告警信息:{TRIGGER.NAME}

问题详情:{ITEM.NAME}:{ITEM.VALUE}

时间ID:{EVENT.ID}

技术分享

注意:使用部分的邮箱无法正常发送邮件,日志报错:

11707:20160527:165712.955 Login denied: Authentication failed: 535

换成其它邮件就好了

管理-用户-报警媒介,设置接收告警的邮箱地址

技术分享

技术分享

关闭监控的zabbix-agent服务,可以收到告警邮件。

技术分享


5.配置默认主页为zabbix

vi /etc/httpd/conf.d/httpd.conf

修改以下内容:

DocumentRoot "/usr/share/zabbix"

重启服务即可

service httpd restart


本文出自 “Linux Oracle and future” 博客,请务必保留此出处http://childres.blog.51cto.com/11420270/1784476

Zabbix 3.0.3 LTS安装/配置/2.x升级

标签:升级   安装   配置   zabbix3   

原文地址:http://childres.blog.51cto.com/11420270/1784476

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!