Centos7编译安装zabbix(一次搞定)

01安装centos系统(注:推荐内存8G)

02、升级系统组件到最新版本:

yum -y update

03、关闭 SELinux:

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

04、关闭防火墙:

systemctl stop firewalld.service && systemctl disable firewalld.service

05、(可选)开启端口:

firewall-cmd --zone=public --list-interfaces

firewall-cmd --zone=public --permanent --add-interface=eth0

firewall-cmd --zone=public --add-port=10050/tcp --permanent

firewall-cmd --zone=public --add-port=10050/udp --permanent

firewall-cmd --set-default-zone=public

firewall-cmd --complete-reload

关闭SELinux的方法:

修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启

vim /etc/selinux/config

注:如果已执行了第4步,则第5步可忽略。如果有信息安全合规要求,不能直接关闭防火墙,则跳过第4步,执行第5步

补充:

缺少Error: Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)

          Requires: mariadb-server

依赖包

报错原因 :软件包依赖 mariadb组件

解决方案:

yum -y remove mariadb-libs

运行

yum install mysql-community-server

06、安装 MySQL 源:

rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

07、安装 zbx 所需软件支持包:

yum -y install ntsysv wget telnet net-tools python-paramiko php php-mysqlnd php-gd libjpeg* php-snmp php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-common httpd gcc gcc-c++ dejavu-sans-fonts python-setuptools python-devel sendmail mailx net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC unixODBC-devel mysql-community-server mysql-community-devel vim

08、(可选)卸载 postfix:

rpm -e postfix

09、设置 MySQL 参数(8GB 内存为例):

vim /etc/my.cnf

在此文件最后部分新增添加以下内容:

character-set-server = utf8mb4

open_files_limit = 65535

back_log = 2048

max_connections = 5000

max_connect_errors = 100000

table_open_cache = 10000

table_definition_cache = 2048

table_open_cache_instances = 64

ssl = 0

skip-host-cache

core-file

thread_stack = 512k

external-locking = FALSE

max_allowed_packet = 32M

host_cache_size = 0

thread_cache_size = 768

query_cache_limit = 256K

query_cache_min_res_unit = 2k

query_cache_size = 0

query_cache_type = 0

interactive_timeout = 600

wait_timeout = 600

tmp_table_size = 32M

max_heap_table_size = 32M

slow_query_log = 1

long_query_time = 0.1

key_buffer_size = 32M

read_buffer_size = 8M

bulk_insert_buffer_size = 64M

lock_wait_timeout = 3600

explicit_defaults_for_timestamp = 1

innodb_thread_concurrency = 0

innodb_doublewrite = 1

innodb_sync_spin_loops = 100

innodb_spin_wait_delay = 30

innodb_buffer_pool_size = 6G

innodb_buffer_pool_instances = 8

innodb_buffer_pool_load_at_startup = 1

innodb_buffer_pool_dump_at_shutdown = 1

innodb_data_file_path = ibdata1:10M:autoextend

innodb_flush_log_at_trx_commit = 0

innodb_log_buffer_size = 32M

innodb_log_file_size = 128M

innodb_log_files_in_group = 2

innodb_max_undo_log_size = 4G

innodb_io_capacity = 4000

innodb_io_capacity_max = 8000

innodb_flush_neighbors = 0

innodb_write_io_threads = 8

innodb_read_io_threads = 8

innodb_purge_threads = 4

innodb_page_cleaners = 4

innodb_open_files = 65535

innodb_max_dirty_pages_pct = 50

innodb_max_dirty_pages_pct_lwm = 10

innodb_flush_method = O_DIRECT

innodb_adaptive_hash_index = OFF

innodb_change_buffering = NONE

innodb_lru_scan_depth = 4000

innodb_checksum_algorithm = crc32

innodb_lock_wait_timeout = 10

innodb_rollback_on_timeout = 1

innodb_print_all_deadlocks = 1

innodb_online_alter_log_max_size = 4G

innodb_stats_on_metadata = 0

innodb_status_file = 1

innodb_status_output = 0

innodb_status_output_locks = 0

innodb_monitor_enable = '%'

internal_tmp_disk_storage_engine = InnoDB

transaction_isolation = REPEATABLE-READ

performance_schema = OFF

disable_partition_engine_check = 1

[mysql]

prompt = "(\U){\R:\m}[\d]> "

no-auto-rehash

[mysqldump]

quick

max_allowed_packet = 32M

注:

1、原则上 innodb_buffer_pool_size 需要设置为主机内存的 80%,如果主机内存不是 8GB,以上参数可依据相应比例进行调整,例如主机内存为 16GB,则 innodb_buffer_pool_size 建议设置为 12GB,innodb_log_buffer_size 建议设置为 32M,innodb_log_file_size 建议设置为 128M,以此类推。请注意innodb_buffer_pool_size的值必须是整数,例如主机内存是4G,那么innodb_buffer_pool_size可以设置为3G,而不能设置为3.2G

2、本设置以提升数据库性能为目标,降低了数据安全性。如果要保证数据安全,需对部分参数进行调整,具体请参考MySQL官方文档中的相关内容,本文不展开讨论

10、启动 MySQL:

systemctl enable mysqld && systemctl start mysqld

11、获取 MySQL 的 root 初始密码:

grep 'temporary password' /var/log/mysqld.log

12、进行 MySQL 安全配置,配置开始时会用到第 11 步获取的初始密码,建议修改为自定义密码,其它选项一般选择 y 即可:(密码强度:包含大小写和特殊字符大于八位)

mysql_secure_installation

13、重启 MySQL:

systemctl restart mysqld

14、配置 MySQL 中 zbx 所需要的库和账号权限:

mysql -u root -p(需要输入第 12 步中设置的自定义密码)

mysql>create database zabbix character set utf8;

mysql>create user zabbix@'%' identified by 'Yiyangboco@123';

mysql>grant all privileges on zabbix.* to zabbix@'%';

mysql>flush privileges;

mysql>exit;

15、安装 zbx源:

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

16、安装 zbx:

yum -y install zabbix-server-mysql zabbix-web-mysql

17、导入 zbx 所需信息(本文编写时,Zabbix 3.4 最新版本为 3.4.11):

cd /usr/share/doc/zabbix-server-mysql-3.4.11

zcat create.sql.gz | mysql -uroot zabbix -p(需要输入第 12 步中设置的自定义密码)

18、配置 zbx 参数:

vim /etc/zabbix/zabbix_server.conf

主要是以下几个选项参数需要设置(8GB 内存为例):

DBPassword 配置为第 14 步第 3 行中设置的自定义密码

CacheSize=512M

HistoryCacheSize=128M

HistoryIndexCacheSize=128M

TrendCacheSize=128M

ValueCacheSize=256M

Timeout=30

其它参数保持默认值即可

如果需要监控VMware虚拟机,则还需要设置以下选项参数:

StartVMwareCollectors=2

VMwareCacheSize=256M

VMwareTimeout=300

19、配置 Apache 中的 PHP 参数(8GB 内存为例):

vim /etc/httpd/conf.d/zabbix.conf

max_execution_time 600

memory_limit 256M

post_max-size 32M

upload_max_filesize 32M

max_input_time 600

date.timezone 去掉注释符号#,并将值修改为 Asia/Shanghai

20、重启系统:

systemctl stop mysqld && reboot

21、启动 zbx:

systemctl start httpd && systemctl start zabbix-server

22、在浏览器中输入 http://zbx监控服务器的IP地址/zabbix,进行 zabbix 的页面初始化配置,根据页面提示信息进行设置即可。

注:第4步的“Zabbix server detail”页面中,“Name”处可填写对此监控系统的描述性文字,支持中文

23、第一次登录zbx监控系统,默认用户名 admin(或Admin),默认密码 zabbix,确认可正常登录系统后,点击右上角图标退出

24、将 Windows 7系统自带的雅黑字体( 此字体文件的默认位置是 c:\windows\fonts\msyh.ttf)上传到 zbx监控服务器系统的 /usr/share/zabbix/fonts 目录下

25、修改 /usr/share/zabbix/include/defines.inc.php 文件,将其中的 45 行 ZBX_GRAPH_FONT_NAME 和 93 行 ZBX_FONT_NAME 的值改为 msyh

26、重启 Apache 和 zbx:

systemctl enable httpd && systemctl enable zabbix-server && systemctl restart httpd && systemctl restart zabbix-server

27、在浏览器中输入 http://zbx监控服务器的IP地址/zabbix,用户名 admin(或Admin),默认密码 zabbix,登录进入系统后,确认 Zabbix server is running 的值是 Yes。然后选择 Administrator --> Users --> Admin

28、Language 设置为 Chinese(zh_CN),点击 Update 按钮使之生效

29、回到“监测中” --> “仪表板”,就可以看到监控系统已设置为中文界面了

Zabbix包下载地址:http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/

zabbxi-agent安装及配置

1、安装zabbxi-agent

yum install zabbix-agent -y

2、配置zabbxi-agent

grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf

vim /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid

32:LogFile=/var/log/zabbix/zabbix_agentd.log

43:LogFileSize=0

97:Server=172.16.8.254

138:ServerActive=172.16.8.254

149:Hostname=Zabbix server

267:Include=/etc/zabbix/zabbix_agentd.d/*.conf

3、启动zabbxi-agent并设置开机启动

systemctl enable zabbix-agent.service

systemctl restart zabbix-agent.service

老版本

开启zabbix要用的端口, 也可以关闭服务器的防火墙

#vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT

#service iptables restart

或关闭服务器防火墙

#service iptables stop

下载zabbix rpm安装包

#rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

安装zabbix-agent

#yum -y install zabbix-agent

配置zabbix-agent

#vim /etc/zabbix/zabbix_agentd.conf

###修改配置文件中的Server, ServerActive的IP, 该IP是zabbix服务端IP地址

Server=zabbix server ip

ServerActive=zabbix server ip

Hostname=本机Ip #不要用127.0.0.1

启动zabbix-agent

#service zabbix-agent start

zabbix3.4安装graphtrees补丁

1、插件安装

Zabbix-web目录

提示:如果是yum安装并且是centos7目录会在/usr/share/zabbix,也可以使用find进行查找,目录不对的话patch安装不上,会提示指定目录

/usr/share/zabbix 

wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3.2.x.patch

yum install -y patch

patch -Np0 < graphtree3.2.x.patch

注意此处的权限,权限不对打开网页是空白的,必须和nginx或者apache的用户一致,我用的是apache

chown -R apache:apache oneoaas

#vim /etc/httpd/conf.d/zabbix.conf   

Alias /oneoaas /usr/share/zabbix/oneoaas   

Alias /zabbix /user/share/zabbix

你可能感兴趣的:(Centos7编译安装zabbix(一次搞定))