Centos7.2 安装 zabbix server 3.4
一、安装 zabbix server 3.4
参考连接:
https://www.zabbix.com/download?zabbix=3.4&os_distribution=centos&os_version=7&db=MySQL
关闭防火墙
#systemctlstopfirewalld.service#关闭防火墙 #systemctldisablefirewalld.service#开机不启动防火墙
关闭selinux
#sed-i's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config#在/etc/selinux/config把SELNUX=enforcing换成SELINUX=disabled #grepSELINUX=disabled/etc/selinux/config#过滤刚刚换的disabled SELINUX=disabled #setenforce0#清空selinux的配置
tarxvfMysqL-5.7.20-1.el7.x86_64.rpm-bundle.tar rpm-e--nodepsmariadb-libs rpm-ivhMysqL-community-client-5.7.20-1.el7.x86_64 rpm-ivhMysqL-community-libs-5.7.20-1.el7.x86_64 rpm-ivhMysqL-community-server-5.7.20-1.el7.x86_64 rpm-ivhMysqL-community-common-5.7.20-1.el7.x86_64 rpm-ivhMysqL-community-libs-compat-5.7.20-1.el7.x86_64 systemctlstartMysqLd#修改密码 cat/var/log/MysqLd.log|greppasswordsystemctlenableMysqLd alteruserroot@'localhost'identifiedby'';
Zabbix Server 3.4安装及配置
wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
安装163的yum源,zabbix必须的PHP两个所需模块bcmath和mbstring epel yum 源没有, 只有网易163源中有
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
# cat /etc/yum.repos.d/CentOS7-Base-163.repo
#CentOS-Base.repo # #ThemirrorsystemusestheconnectingIPaddressoftheclientandthe #updatestatusofeachmirrortopickmirrorsthatareupdatedtoand #geographicallyclosetotheclient.YoushouldusethisforCentOSupdates #unlessyouaremanuallypickingothermirrors. # #Ifthemirrorlist=doesnotworkforyou,asafallbackyoucantrythe #remarkedoutbaseurl=lineinstead. # # [base] name=CentOS-7-Base-163.com #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os baseurl=http://mirrors.163.com/centos/7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #releasedupdates [updates] name=CentOS-7-Updates-163.com #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additionalpackagesthatmaybeuseful [extras] name=CentOS-7-Extras-163.com #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additionalpackagesthatextendfunctionalityofexistingpackages [centosplus] name=CentOS-7-Plus-163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
# yum install zabbix-server-MysqL zabbix-web-MysqL zabbix-agent
# MysqL -uroot -p
# password
MysqL> create database zabbix character set utf8 collate utf8_bin;
MysqL> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
MysqL> quit;
# zcat /usr/share/doc/zabbix-server-MysqL*/create.sql.gz | MysqL -uzabbix -D zabbix -p
配置zabbix数据库
# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password
# systemctl start zabbix-server zabbix-agent httpd
# systemctl enable zabbix-server zabbix-agent httpd
vim /etc/httpd/conf.d/zabbix.conf
# PHP_value date.timezone Europe/Riga
替换为:
PHP_value date.timezone Asia/Shanghai
配置 zabbix前台
Connect to your newly installed Zabbix frontend: http://server_ip_or_name/zabbix
Follow steps described in Zabbix documentation: Installing frontend
zabbix 帮助文档
https://www.zabbix.com/documentation/3.4/manual/quickstart/login
二、zabbix agent 安装
wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
yum install zabbix-agent
systemctl start zabbix-agent
systemctl enable zabbix-agent
客户端配置:
# cat /etc/zabbix/zabbix_agentd.conf | grep -v "^#"| grep -v '^$'
PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=192.168.1.51 ServerActive=192.168.1.51:10051 HostnameItem=system.run[ifconfig|grep"inet"|grep-E-o"(2[0-4][0-9]|25[0-5]|1[0-9][0-9]|[1-9]?[0-9])(.(2[0-4][0-9]|25[0-5]|1[0-9][0-9]|[1-9]?[0-9])){3}"|grep"192.168.1"|head-1] RefreshActiveChecks=120 Include=/etc/zabbix/zabbix_agentd.d/*.conf
三、zabbix做分区
MysqL>usezabbix; MysqL>altertabletrendsrenametrends_bak; QueryOK,0rowsaffected(0.04sec) MysqL>CREATETABLE`trends`( `itemid`bigint(20)unsignedNOTNULL,`clock`int(11)NOTNULLDEFAULT'0',`num`int(11)NOTNULLDEFAULT'0',`value_min`double(16,4)NOTNULLDEFAULT'0.0000',`value_avg`double(16,`value_max`double(16,PRIMARYKEY(`itemid`,`clock`) )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_bin PARTITIONBYRANGE(clock) ( PARTITIONp2018_02VALUESLESSTHAN(UNIX_TIMESTAMP("2018-03-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_03VALUESLESSTHAN(UNIX_TIMESTAMP("2018-04-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_04VALUESLESSTHAN(UNIX_TIMESTAMP("2018-05-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_05VALUESLESSTHAN(UNIX_TIMESTAMP("2018-06-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_06VALUESLESSTHAN(UNIX_TIMESTAMP("2018-07-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_07VALUESLESSTHAN(UNIX_TIMESTAMP("2018-08-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_08VALUESLESSTHAN(UNIX_TIMESTAMP("2018-09-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_09VALUESLESSTHAN(UNIX_TIMESTAMP("2018-10-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_10VALUESLESSTHAN(UNIX_TIMESTAMP("2018-11-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_11VALUESLESSTHAN(UNIX_TIMESTAMP("2018-12-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_12VALUESLESSTHAN(UNIX_TIMESTAMP("2019-01-0100:00:00"))ENGINE=InnoDB); QueryOK,0rowsaffected(0.11sec) MysqL>altertabletrends_uintrenametrends_uint_bak; QueryOK,0rowsaffected(0.02sec) MysqL>CREATETABLE`trends_uint`( `itemid`bigint(20)unsignedNOTNULL,`value_min`bigint(20)unsignedNOTNULLDEFAULT'0',`value_avg`bigint(20)unsignedNOTNULLDEFAULT'0',`value_max`bigint(20)unsignedNOTNULLDEFAULT'0',`clock`) )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_bin PARTITIONBYRANGE(clock) (PARTITIONp2017_11VALUESLESSTHAN(UNIX_TIMESTAMP("2017-12-0100:00:00"))ENGINE=InnoDB,PARTITIONp2017_12VALUESLESSTHAN(UNIX_TIMESTAMP("2018-01-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_01VALUESLESSTHAN(UNIX_TIMESTAMP("2018-02-0100:00:00"))ENGINE=InnoDB,PARTITIONp2018_02VALUESLESSTHAN(UNIX_TIMESTAMP("2018-03-0100:00:00"))ENGINE=InnoDB,0rowsaffected(0.13sec) MysqL>altertablehistoryrenamehistory_bak; QueryOK,0rowsaffected(0.02sec) MysqL>altertablehistory_uintrenamehistory_uint_bak; QueryOK,0rowsaffected(0.00sec) MysqL>altertablehistory_textrenamehistory_text_bak; QueryOK,0rowsaffected(0.01sec) MysqL>altertablehistory_strrenamehistory_str_bak; QueryOK,0rowsaffected(0.01sec) MysqL>altertablehistory_logrenamehistory_log_bak; QueryOK,0rowsaffected(0.01sec) MysqL>CREATETABLE`history`( `itemid`bigint(20)unsignedNOTNULL,`value`double(16,`ns`int(11)NOTNULLDEFAULT'0',KEY`history_index`(`itemid`,`clock`,`value`,`ns`) )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_bin PARTITIONBYRANGE(clock) (PARTITIONp2018_02_01VALUESLESSTHAN(1517500800)ENGINE=InnoDB,PARTITIONp2018_02_02VALUESLESSTHAN(1517587200)ENGINE=InnoDB,PARTITIONp2018_02_03VALUESLESSTHAN(1517673600)ENGINE=InnoDB,PARTITIONp2018_02_04VALUESLESSTHAN(1517760000)ENGINE=InnoDB,PARTITIONp2018_02_05VALUESLESSTHAN(1517846400)ENGINE=InnoDB,PARTITIONp2018_02_06VALUESLESSTHAN(1517932800)ENGINE=InnoDB,PARTITIONp2018_02_07VALUESLESSTHAN(1518019200)ENGINE=InnoDB,PARTITIONp2018_02_08VALUESLESSTHAN(1518105600)ENGINE=InnoDB,PARTITIONp2018_02_09VALUESLESSTHAN(1518192000)ENGINE=InnoDB,PARTITIONp2018_02_10VALUESLESSTHAN(1518278400)ENGINE=InnoDB,PARTITIONp2018_02_11VALUESLESSTHAN(1518364800)ENGINE=InnoDB,PARTITIONp2018_02_12VALUESLESSTHAN(1518451200)ENGINE=InnoDB,PARTITIONp2018_02_13VALUESLESSTHAN(1518537600)ENGINE=InnoDB,PARTITIONp2018_02_14VALUESLESSTHAN(1518624000)ENGINE=InnoDB,PARTITIONp2018_02_15VALUESLESSTHAN(1518710400)ENGINE=InnoDB,PARTITIONp2018_02_16VALUESLESSTHAN(1518796800)ENGINE=InnoDB,PARTITIONp2018_02_17VALUESLESSTHAN(1518883200)ENGINE=InnoDB,PARTITIONp2018_02_18VALUESLESSTHAN(1518969600)ENGINE=InnoDB,PARTITIONp2018_02_19VALUESLESSTHAN(1519056000)ENGINE=InnoDB,PARTITIONp2018_02_20VALUESLESSTHAN(1519142400)ENGINE=InnoDB,PARTITIONp2018_02_21VALUESLESSTHAN(1519228800)ENGINE=InnoDB,PARTITIONp2018_02_22VALUESLESSTHAN(1519315200)ENGINE=InnoDB,PARTITIONp2018_02_23VALUESLESSTHAN(1519401600)ENGINE=InnoDB,PARTITIONp2018_02_24VALUESLESSTHAN(1519488000)ENGINE=InnoDB,PARTITIONp2018_02_25VALUESLESSTHAN(1519574400)ENGINE=InnoDB,PARTITIONp2018_02_26VALUESLESSTHAN(1519660800)ENGINE=InnoDB,PARTITIONp2018_02_27VALUESLESSTHAN(1519747200)ENGINE=InnoDB,PARTITIONp2018_02_28VALUESLESSTHAN(1519833600)ENGINE=InnoDB,PARTITIONp2018_03_01VALUESLESSTHAN(1519920000)ENGINE=InnoDB,PARTITIONp2018_03_02VALUESLESSTHAN(1520006400)ENGINE=InnoDB,PARTITIONp2018_03_03VALUESLESSTHAN(1520092800)ENGINE=InnoDB,PARTITIONp2018_03_04VALUESLESSTHAN(1520179200)ENGINE=InnoDB,PARTITIONp2018_03_05VALUESLESSTHAN(1520265600)ENGINE=InnoDB,PARTITIONp2018_03_06VALUESLESSTHAN(1520352000)ENGINE=InnoDB,PARTITIONp2018_03_07VALUESLESSTHAN(1520438400)ENGINE=InnoDB,PARTITIONp2018_03_08VALUESLESSTHAN(1520524800)ENGINE=InnoDB,PARTITIONp2018_03_09VALUESLESSTHAN(1520611200)ENGINE=InnoDB,PARTITIONp2018_03_10VALUESLESSTHAN(1520697600)ENGINE=InnoDB,PARTITIONp2018_03_11VALUESLESSTHAN(1520784000)ENGINE=InnoDB,PARTITIONp2018_03_12VALUESLESSTHAN(1520870400)ENGINE=InnoDB,PARTITIONp2018_03_13VALUESLESSTHAN(1520956800)ENGINE=InnoDB,PARTITIONp2018_03_14VALUESLESSTHAN(1521043200)ENGINE=InnoDB,PARTITIONp2018_03_15VALUESLESSTHAN(1521129600)ENGINE=InnoDB,PARTITIONp2018_03_16VALUESLESSTHAN(1521216000)ENGINE=InnoDB,PARTITIONp2018_03_17VALUESLESSTHAN(1521302400)ENGINE=InnoDB,PARTITIONp2018_03_18VALUESLESSTHAN(1521388800)ENGINE=InnoDB,PARTITIONp2018_03_19VALUESLESSTHAN(1521475200)ENGINE=InnoDB,PARTITIONp2018_03_20VALUESLESSTHAN(1521561600)ENGINE=InnoDB,PARTITIONp2018_03_21VALUESLESSTHAN(1521648000)ENGINE=InnoDB,PARTITIONp2018_03_22VALUESLESSTHAN(1521734400)ENGINE=InnoDB,PARTITIONp2018_03_23VALUESLESSTHAN(1521820800)ENGINE=InnoDB,PARTITIONp2018_03_24VALUESLESSTHAN(1521907200)ENGINE=InnoDB,PARTITIONp2018_03_25VALUESLESSTHAN(1521993600)ENGINE=InnoDB,PARTITIONp2018_03_26VALUESLESSTHAN(1522080000)ENGINE=InnoDB,PARTITIONp2018_03_27VALUESLESSTHAN(1522166400)ENGINE=InnoDB,PARTITIONp2018_03_28VALUESLESSTHAN(1522252800)ENGINE=InnoDB); QueryOK,0rowsaffected(0.67sec) MysqL>CREATETABLE`history_uint`( `itemid`bigint(20)unsignedNOTNULL,`value`bigint(20)unsignedNOTNULLDEFAULT'0',KEY`history_uint_index`(`itemid`,0rowsaffected(0.60sec) MysqL>CREATETABLE`history_str`( `itemid`bigint(20)unsignedNOTNULL,`value`varchar(255)COLLATEutf8_binNOTNULLDEFAULT'',KEY`history_str_1`(`itemid`,`clock`) )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_bin PARTITIONBYRANGE(clock) (PARTITIONp2018_02_01VALUESLESSTHAN(1517500800)ENGINE=InnoDB,0rowsaffected(0.60sec) MysqL>CREATETABLE`history_log`( `itemid`bigint(20)unsignedNOTNULL,`timestamp`int(11)NOTNULLDEFAULT'0',`source`varchar(64)COLLATEutf8_binNOTNULLDEFAULT'',`severity`int(11)NOTNULLDEFAULT'0',`value`textCOLLATEutf8_binNOTNULL,`logeventid`int(11)NOTNULLDEFAULT'0',KEY`history_log_1`(`itemid`,0rowsaffected(0.62sec) MysqL>CREATETABLE`history_text`( `itemid`bigint(20)unsignedNOTNULL,KEY`history_text_1`(`itemid`,0rowsaffected(0.62sec)
配置分区策略,采用外部分区的方式
yum install perl-Sys-Syslog
yum install per-DateTime
yum install perl-DateTime
yum install perl-DBD-MysqL
vim /etc/rsyslog.conf
local6.*/var/log/zabbix-partition.log
systemctl restart rsyslog
cat /var/lib/MysqL/MysqL_partition.pl
#!/usr/bin/perl usestrict; useData::Dumper; useDBI; useSys::Syslogqw(:standard:macros); useDateTime; usePOSIXqw(strftime); openlog("MysqL_zbx_part","ndelay,pid",LOG_LOCAL6); my$db_schema='zabbix'; my$dsn='DBI:MysqL:'.$db_schema.':MysqL_socket=/data/MysqL/MysqL.sock'; my$db_user_name='zabbix'; my$db_password='i5$4)Ci10(sn'; my$tables={'history'=>{'period'=>'day','keep_history'=>'60'},'history_log'=>{'period'=>'day','history_str'=>{'period'=>'day','history_text'=>{'period'=>'day','history_uint'=>{'period'=>'day','trends'=>{'period'=>'month','keep_history'=>'3'},'trends_uint'=>{'period'=>'month',#commentnext5linesifyoupartitionzabbixdatabasestartingfrom2.2 #theyusuallyusedforzabbixdatabasebefore2.2 #'acknowledges'=>{'period'=>'month','keep_history'=>'23'},#'alerts'=>{'period'=>'month','keep_history'=>'6'},#'auditlog'=>{'period'=>'month','keep_history'=>'24'},#'events'=>{'period'=>'month','keep_history'=>'12'},#'service_alarms'=>{'period'=>'month',}; my$amount_partitions=30; my$curr_tz='Asia/Shanghai'; my$part_tables; my$dbh=DBI->connect($dsn,$db_user_name,$db_password); unless(check_have_partition()){ print"YourinstallationofMysqLdoesnotsupporttablepartitioning.\n"; syslog(LOG_CRIT,'YourinstallationofMysqLdoesnotsupporttablepartitioning.'); exit1; } my$sth=$dbh->prepare(qq{SELECTtable_name,partition_name,lower(partition_method)aspartition_method,rtrim(ltrim(partition_expression))aspartition_expression,partition_description,table_rows FROMinformation_schema.partitions WHEREpartition_nameISNOTNULLANDtable_schema=?}); $sth->execute($db_schema); while(my$row=$sth->fetchrow_hashref()){ $part_tables->{$row->{'table_name'}}->{$row->{'partition_name'}}=$row; } $sth->finish(); foreachmy$key(sortkeys%{$tables}){ unless(defined($part_tables->{$key})){ syslog(LOG_ERR,'Partitioningfor"'.$key.'"isnotfound!Thetablemightbenotpartitioned.'); next; } create_next_partition($key,$part_tables->{$key},$tables->{$key}->{'period'}); remove_old_partitions($key,$tables->{$key}->{'period'},$tables->{$key}->{'keep_history'}) } delete_old_data(); $dbh->disconnect(); subcheck_have_partition{ my$result=0; #MysqL5.5 #my$sth=$dbh->prepare(qq{SELECTvariable_valueFROMinformation_schema.global_variablesWHEREvariable_name='have_partitioning'}); #MysqL5.6 my$sth=$dbh->prepare(qq{SELECTplugin_statusFROMinformation_schema.pluginsWHEREplugin_name='partition'}); $sth->execute(); my$row=$sth->fetchrow_array(); $sth->finish(); #MysqL5.5 #return1if$roweq'YES'; #MysqL5.6 return1if$roweq'ACTIVE'; } subcreate_next_partition{ my$table_name=shift; my$table_part=shift; my$period=shift; for(my$curr_part=0;$curr_part<$amount_partitions;$curr_part++){ my$next_name=name_next_part($tables->{$table_name}->{'period'},$curr_part); my$found=0; foreachmy$partition(sortkeys%{$table_part}){ if($next_nameeq$partition){ syslog(LOG_INFO,"Nextpartitionfor$table_naMetablehasalreadybeencreated.Itis$next_name"); $found=1; } } if($found==0){ syslog(LOG_INFO,"Creatingapartitionfor$table_naMetable($next_name)"); my$query='ALTERTABLE'."$db_schema.$table_name".'ADDPARTITION(PARTITION'.$next_name. 'VALUESlessthan(UNIX_TIMESTAMP("'.date_next_part($tables->{$table_name}->{'period'},$curr_part).'")div1))'; syslog(LOG_DEBUG,$query); $dbh->do($query); } } } subremove_old_partitions{ my$table_name=shift; my$table_part=shift; my$period=shift; my$keep_history=shift; my$curr_date=DateTime->now; $curr_date->set_time_zone($curr_tz); if($periodeq'day'){ $curr_date->add(days=>-$keep_history); $curr_date->add(hours=>-$curr_date->strftime('%H')); $curr_date->add(minutes=>-$curr_date->strftime('%M')); $curr_date->add(seconds=>-$curr_date->strftime('%S')); } elsif($periodeq'week'){ } elsif($periodeq'month'){ $curr_date->add(months=>-$keep_history); $curr_date->add(days=>-$curr_date->strftime('%d')+1); $curr_date->add(hours=>-$curr_date->strftime('%H')); $curr_date->add(minutes=>-$curr_date->strftime('%M')); $curr_date->add(seconds=>-$curr_date->strftime('%S')); } foreachmy$partition(sortkeys%{$table_part}){ if($table_part->{$partition}->{'partition_description'}<=$curr_date->epoch){ syslog(LOG_INFO,"Removingold$partitionpartitionfrom$table_naMetable"); my$query="ALTERTABLE$db_schema.$table_nameDROPPARTITION$partition"; syslog(LOG_DEBUG,$query); $dbh->do($query); } } } subname_next_part{ my$period=shift; my$curr_part=shift; my$name_template; my$curr_date=DateTime->now; $curr_date->set_time_zone($curr_tz); if($periodeq'day'){ my$curr_date=$curr_date->truncate(to=>'day'); $curr_date->add(days=>1+$curr_part); $name_template=$curr_date->strftime('p%Y_%m_%d'); } elsif($periodeq'week'){ my$curr_date=$curr_date->truncate(to=>'week'); $curr_date->add(days=>7*$curr_part); $name_template=$curr_date->strftime('p%Y_%m_w%W'); } elsif($periodeq'month'){ my$curr_date=$curr_date->truncate(to=>'month'); $curr_date->add(months=>1+$curr_part); $name_template=$curr_date->strftime('p%Y_%m'); } return$name_template; } subdate_next_part{ my$period=shift; my$curr_part=shift; my$period_date; my$curr_date=DateTime->now; $curr_date->set_time_zone($curr_tz); if($periodeq'day'){ my$curr_date=$curr_date->truncate(to=>'day'); $curr_date->add(days=>2+$curr_part); $period_date=$curr_date->strftime('%Y-%m-%d'); } elsif($periodeq'week'){ my$curr_date=$curr_date->truncate(to=>'week'); $curr_date->add(days=>7*$curr_part+1); $period_date=$curr_date->strftime('%Y-%m-%d'); } elsif($periodeq'month'){ my$curr_date=$curr_date->truncate(to=>'month'); $curr_date->add(months=>2+$curr_part); $period_date=$curr_date->strftime('%Y-%m-%d'); } return$period_date; } subdelete_old_data{ $dbh->do("DELETEFROMsessionsWHERElastaccess<UNIX_TIMESTAMP(NOW()-INTERVAL1MONTH)"); $dbh->do("TRUNCATEhousekeeper"); $dbh->do("DELETEFROMauditlog_detailsWHERENOTEXISTS(SELECTNULLFROMauditlogWHEREauditlog.auditid=auditlog_details.auditid)"); }
chmod +x MysqL_partition.pl
yum install ntpdate
crontab -l
*/5 * * * * /usr/sbin/ntpdate ntp.api.bz
20 11 * * * /var/lib/MysqL/scripts/MysqL_partition.pl
定期备份配置数据
MysqLdump-uroot-p--single-transaction-R--default-character-set=utf8--triggers--events--hex-blob--databaseszabbix--ignore-table=zabbix.history--ignore-table=zabbix.history_uint--ignore-table=zabbix.history_log--ignore-table=zabbix.history_str--ignore-table=zabbix.history_text--ignore-table=zabbix.trends--ignore-table=zabbix.trends_uint>zabbix_`date`.sql
关闭 housekeeper ,防止出现select itemid,min(clock) from history_uint group by itemid 语句 ,改语句执行非常的慢,对数据库的插入性能,系统的负载等有非常大影响
Administration -> General -> Housekeeping.
关闭history ,trends表的清理策略
systemctl restart zabbix-server
zabbix的端口
tcp6 0 0 :::10050 :::* LISTEN 1248/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 1974/zabbix_server
zabbix的日志
# ll /var/log/zabbix/* #日志体系
-rw-rw-r-- 1 zabbix zabbix 18578 Feb 28 18:46 /var/log/zabbix/zabbix_agentd.log
-rw-rw-r--. 1 zabbix zabbix 79759 Feb 28 18:18 /var/log/zabbix/zabbix_server.log
参考:
http://www.zabbix.org/wiki/Docs/howto/mysql_partitioning
http://www.zabbix.org/wiki/Docs/howto/mysql_partition
常用的语句:
select partition_name part,partition_expression expr,partition_description descr,table_rows from information_schema.partitions where table_schema = schema() and table_name='history';