1.配置zabbix仓库
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
sed -i 's#repo.zabbix.com#mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo
2.安装 Zabbix 程序包,以及 MySQL、 Zabbix-agent以及作为依赖被安装的php
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server
systemctl start mariadb.service && systemctl enable mariadb.service
3、创建 Zabbix 数据库以及用户
[root@m01 ~]# mysql_secure_installation
[root@m01 ~]# mysql -uroot -p123456
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> flush privileges
zcat /usr/share/doc/zabbix-server-mysql-4.0.21/create.sql.gz | mysql -uzabbix -pzabbix zabbixileges;
4.导入 Zabbix 数据至数据库中
zcat /usr/share/doc/zabbix-server-mysql-4.0.21/create.sql.gz | mysql -uzabbix -pzabbix zabbix
注意4.0.21可能变化的,记得更改
5.编辑/etc/zabbix/zabbix_server.conf 文件,修改数据库配置
vim /etc/zabbix/zabbix_server.conf
更改为以下内容
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
6.启动 Zabbix 服务进程,并加入开机自启
[root@m01 ~]# systemctl start zabbix-server.service
[root@m01 ~]# systemctl enable zabbix-server.service
7.配置 Apache 的配置文件/etc/httpd/conf.d/zabbix.conf,修改时区
vim /etc/httpd/conf.d/zabbix.conf
更改为php_value date.timezone Asia/Shanghai
[root@m01 ~]# systemctl start httpd
[root@m01 ~]# systemctl enable httpd
zabbix客户端日志
tail -f /var/log/zabbix/zabbix_agentd.log
zabbix服务端日志
报错:1494:20200614:220325.718 [Z3005] query failed: [1061] Duplicate key name ‘lld_override_condition_1’ [create index lld_override_condition_1 on lld_override_condition (lld_overrideid)]
解决方案:删除zabbix数据库重新创建再覆盖zcat
MariaDB [(none)]> drop database zabbix;
Query OK, 156 rows affected (1.319 sec)
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
zcat /home/backup/zabbix_20200610_232635.sql.gz | mysql -u zabbix -pzabbix zabbix
tailf /var/log/zabbix/zabbix_server.log
安装不做赘述了,一路next有空白填zabbix,用户名Admin密码zabbix
升级5.0
https://www.zabbix.com/documentation/current/manual/installation/upgrade/packages/rhel_centos 升级php版本到7.2(zabbix5.0要求)
https://www.jianshu.com/p/d9a7f0be6e35 rpm -qa |grep php|xargs rpm -e
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum search php7
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded
php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
php -v
备份数据库
重要的事情说三遍,备份,备份,备份
备份数据库,如果升级顺利是不要实施备份还原的
mysqldump -u root -p --all-databases > alldb.sql
如果想保留自己的my.cof配置,则备份一下这个文件
cp /etc/my.cnf /etc/my.cnf.bak
停止数据库运行
systemctl stop mariadb
卸载MariaDB老版本
yum remove mariadb mariadb-server
添加 MariaDB Yum 库
建议使用MariaDB官方推荐的stable稳定版,
添加MariaDB官方源
vi /etc/yum.repos.d/MariaDB.repo
MariaDB 10.3 CentOS repository list
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
清除yum缓存
```bash
yum clean all
yum makecache
升级已有数据库
# 安装MariaDB新版本
```bash
```bash
yum install mariadb mariadb-server
# 启动新版MariaDB
```bash
systemctl start mariadb
升级已有数据库
mysql_upgrade -uroot -p
[root@sg-gop-10-71-12-89 tmp]# mysql_upgrade -uroot -p
Enter password:
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading from a version before MariaDB-10.1
Phase 2/7: Installing used storage engines
Checking for tables with unknown storage engine
Phase 3/7: Fixing views
Phase 4/7: Running ‘mysql_fix_privilege_tables’
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
performance_schema
zabbix
zabbix.acknowledges OK
zabbix.actions OK
zabbix.alerts OK
zabbix.application_discovery OK
zabbix.application_prototype OK
zabbix.application_template OK
zabbix.applications OK
zabbix.auditlog OK
zabbix.auditlog_details OK
zabbix.autoreg_host OK
zabbix.conditions OK
zabbix.config OK
zabbix.corr_condition OK
zabbix.corr_condition_group OK
zabbix.corr_condition_tag OK
zabbix.corr_condition_tagpair OK
zabbix.corr_condition_tagvalue OK
zabbix.corr_operation OK
zabbix.correlation OK
zabbix.dashboard OK
zabbix.dashboard_user OK
zabbix.dashboard_usrgrp OK
zabbix.dbversion OK
zabbix.dchecks OK
zabbix.dhosts OK
zabbix.drules OK
zabbix.dservices OK
zabbix.escalations OK
zabbix.event_recovery OK
zabbix.event_suppress OK
zabbix.event_tag OK
zabbix.events OK
zabbix.expressions OK
zabbix.functions OK
zabbix.globalmacro OK
zabbix.globalvars OK
zabbix.graph_discovery OK
zabbix.graph_theme OK
zabbix.graphs OK
zabbix.graphs_items OK
zabbix.group_discovery OK
zabbix.group_prototype OK
zabbix.history OK
zabbix.history_log OK
zabbix.history_str OK
zabbix.history_text OK
zabbix.history_uint OK
zabbix.host_discovery OK
zabbix.host_inventory OK
zabbix.hostmacro OK
zabbix.hosts OK
zabbix.hosts_groups OK
zabbix.hosts_templates OK
zabbix.housekeeper OK
zabbix.hstgrp OK
zabbix.httpstep OK
zabbix.httpstep_field OK
zabbix.httpstepitem OK
zabbix.httptest OK
zabbix.httptest_field OK
zabbix.httptestitem OK
zabbix.icon_map OK
zabbix.icon_mapping OK
zabbix.ids OK
zabbix.images OK
zabbix.interface OK
zabbix.interface_discovery OK
zabbix.item_application_prototype OK
zabbix.item_condition OK
zabbix.item_discovery OK
zabbix.item_preproc OK
zabbix.items OK
zabbix.items_applications OK
zabbix.maintenance_tag OK
zabbix.maintenances OK
zabbix.maintenances_groups OK
zabbix.maintenances_hosts OK
zabbix.maintenances_windows OK
zabbix.mappings OK
zabbix.media OK
zabbix.media_type OK
zabbix.opcommand OK
zabbix.opcommand_grp OK
zabbix.opcommand_hst OK
zabbix.opconditions OK
zabbix.operations OK
zabbix.opgroup OK
zabbix.opinventory OK
zabbix.opmessage OK
zabbix.opmessage_grp OK
zabbix.opmessage_usr OK
zabbix.optemplate OK
zabbix.problem OK
zabbix.problem_tag OK
zabbix.profiles OK
zabbix.proxy_autoreg_host OK
zabbix.proxy_dhistory OK
zabbix.proxy_history OK
zabbix.regexps OK
zabbix.rights OK
zabbix.screen_user OK
zabbix.screen_usrgrp OK
zabbix.screens OK
zabbix.screens_items OK
zabbix.scripts OK
zabbix.service_alarms OK
zabbix.services OK
zabbix.services_links OK
zabbix.services_times OK
zabbix.sessions OK
zabbix.slides OK
zabbix.slideshow_user OK
zabbix.slideshow_usrgrp OK
zabbix.slideshows OK
zabbix.sysmap_element_trigger OK
zabbix.sysmap_element_url OK
zabbix.sysmap_shape OK
zabbix.sysmap_url OK
zabbix.sysmap_user OK
zabbix.sysmap_usrgrp OK
zabbix.sysmaps OK
zabbix.sysmaps_elements OK
zabbix.sysmaps_link_triggers OK
zabbix.sysmaps_links OK
zabbix.tag_filter OK
zabbix.task OK
zabbix.task_acknowledge OK
zabbix.task_check_now OK
zabbix.task_close_problem OK
zabbix.task_remote_command OK
zabbix.task_remote_command_result OK
zabbix.timeperiods OK
zabbix.trends OK
zabbix.trends_uint OK
zabbix.trigger_depends OK
zabbix.trigger_discovery OK
zabbix.trigger_tag OK
zabbix.triggers OK
zabbix.users OK
zabbix.users_groups OK
zabbix.usrgrp OK
zabbix.valuemaps OK
zabbix.widget OK
zabbix.widget_field OK
Phase 7/7: Running ‘FLUSH PRIVILEGES’
OK
Zabbix备份操作
备份ZB配置文件
mkdir -p /home/backup/zabbix-backup
cp /etc/zabbix/zabbix_server.conf /home/backup/zabbix-backup
cp /etc/zabbix/zabbix_agentd.conf /home/backup/zabbix-backup
cp /etc/zabbix/web/zabbix.conf.php /home/backup/zabbix-backup
cp –R /usr/share/doc/zabbix-* /home/backup/zabbix-backup
数据库备份
mysql root@localhost:(none)> select count(8) tables,table_schema from information_schema.tables where table_schema = 'zabbix';
±-------±-------------+
| tables | table_schema |
±-------±-------------+
| 149 | zabbix |
±-------±-------------+
1 row in set
Time: 0.014s
mysqldump -uzabbix -pzabbix --opt --skip-lock-tables zabbix | gzip > /home/backup/zabbix_$(date +%Y%m%d_%H%M%S).sql.gz
[root@shvm01 doc]# ll /home/backup/
总用量 5120
-rw-r–r-- 1 root root 20 4月 23 10:48 zabbix_20200423_104832.sql.gz
-rw-r–r-- 1 root root 5233446 4月 23 10:48 zabbix_20200423_104849.sql.gz
drwxr-xr-x 3 root root 4096 4月 23 10:45 zabbix-backup
1.配置zabbix仓库
rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#repo.zabbix.com#mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo
yum install centos-release-scl scl-utils-build
yum -y install rh-php72*
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-deps-scl-5.0.0-1.el7.noarch.rpm
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.0-1.el7.noarch.rpm
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-mysql-scl-5.0.0-1.el7.noarch.rpm
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-apache-conf-scl-5.0.0-1.el7.noarch.rpm
[root@zabbix yum.repos.d]# rpm -qa|grep zabbix
zabbix-web-mysql-scl-5.0.0-1.el7.noarch
zabbix-release-5.0-1.el7.noarch
zabbix-server-mysql-5.0.1-1.el7.x86_64
zabbix-web-5.0.0-1.el7.noarch
zabbix-apache-conf-scl-5.0.0-1.el7.noarch
zabbix-get-4.0.21-2.el7.x86_64
zabbix-agent-5.0.1-1.el7.x86_64
zabbix-web-deps-scl-5.0.0-1.el7.noarch
拷贝以下内容到/etc/httpd/conf.d/zabbix.conf(记得先备份)
Alias /zabbix /usr/share/zabbix
<Directory “/usr/share/zabbix”>
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
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 max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
<Directory “/usr/share/zabbix/conf”>
Require all denied
<Directory “/usr/share/zabbix/app”>
Require all denied
<Directory “/usr/share/zabbix/include”>
Require all denied
<Directory “/usr/share/zabbix/local”>
Require all denied
zcat 报错
https://www.jianshu.com/p/2c96a7f1b8aa MYSQL Row size too large (> 8126) 的错误
报错500,tail -f /var/log/httpd/error_log报错
MYSQL Row size too large (> 8126) 的错误
错误1:
ERROR 1118
Row size too large (> 8126). Changing some columns to TEXT or
BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.
原因:字段太多,超过mysql默认配置的字段数量了,可以通过修改配置来扩大数量。
或者是错误2:
com.mysql.jdbc.PacketTooBigException: Packet for query is too large
原因:每次传输的包太大了,超过了配置文件里配置的最大包大小了。
解决步骤
步骤1:知道要修改哪些配置参数:
对于原因1,我自己是添加了3个配置参数:
innodb_log_file_size = 500M
innodb_log_buffer_size = 800M
innodb_strict_mode = 0
对于原因2,只需添加1个参数:
max_allowed_packet = 256M
前面3个参数是我参考这个得出来的:https://stackoverflow.com/questions/22637733/mysql-error-code-1118-row-size-too-large-8126-changing-some-columns-to-te
步骤2:编辑my.ini配置文件,将上面的参数输进去
linux下是:sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
编辑完my.ini之后,按Ctrl + X退出,按提示输入Y然后回车保存
windows下的my.ini所在位置:
(注: 如果已经配置了AAA=123,又想配置AAA=456,记得注释掉其中一个,否则mysql会以最后出现的为准。)
步骤3:重启mysql服务
linux下:
/etc/init.d/mysqld restart 或者 service mysqld restart 或者 service mysql restart,然后输入密码。如图:
解决方案
yum -y install php72w-bcmath php72w-mbstring
如果出现zabbix-server日志报错显示表767的
Index column size too large. The maximum column size is 767 bytes
http://blog.chinaunix.net/uid-30135788-id-5766194.html
mysql -uroot -p123456
update dbversion set mandatory=