赞
踩
一、环境准备
1、系统环境:Centos7.6
2、系统优化:
- (1)修改主机名
- hostnamectl set-hostname controlnode
-
- (2)关闭不常用服务
- service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd
- auditd chronyd microcode postfix firewalld)
- for ((i=0;i<${#service_array[*]};i++)); do
- /usr/bin/systemctl stop ${service_array[$i]}
- done
-
-
- service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd
- auditd chronyd microcode postfix firewalld)
- for ((i=0;i<${#service_array[*]};i++)); do
- /usr/bin/systemctl disable ${service_array[$i]}
- done
-
-
- (3)关闭selinux
- sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
- grep "SELINUX=disabled" /etc/selinux/config
- setenforce 0
-
- (4)优化内存(可选)
- cat >>/etc/sysctl.conf<<EOF
- net.ipv4.tcp_fin_timeout = 2
- net.ipv4.tcp_tw_reuse = 1
- #net.ipv4.tcp_tw_recycle = 1
- net.ipv4.tcp_syncookies = 1
- net.ipv4.tcp_keepalive_time = 600
- net.ipv4.tcp_keepalive_probes = 5
- net.ipv4.tcp_keepalive_intvl = 15
- net.ipv4.ip_local_port_range = 1024 65000
- net.ipv4.tcp_max_syn_backlog = 262144
- net.ipv4.tcp_max_tw_buckets =5000
- net.ipv4.tcp_syn_retries = 1
- net.ipv4.tcp_synack_retries = 1
- net.core.somaxconn = 16384
- net.core.netdev_max_backlog = 16384
- net.ipv4.tcp_max_orphans = 16384
- EOF
-
- sysctl -p
3、环境配置:
- (1)安装必备软件
- yum install lrzsz dos2unix bash-completion nmap telnet tree wget vim net-tools ntpdate salt-minion git -y
-
- (2)配置阿里源
-
- 配置阿里的yum源:
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
- 配置阿里的epel源:
- yum install epel-release
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
-
- 设置yum和epel源的缓存:
- yum clean all
- yum makecache
-
- 查看系统可用的源:
- yum repolist enabled
-
- (3)修改字符集
- localectl set-locale LANG=zh_CN.UTF-8
- source /etc/locale.conf
-
- (4)配置时间同步定时任务
- [root@localhost ~]# crontab -e
- */5 * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
二、配置zabbix5.0的yum源
1、说明:
zabbix 5.0 版本于 5 月 11 日正式发布,是最新的 LTS(长期支持)版本,5.0 带来很多功能和特性。
5.0 版本对基础环境的要求有大的变化,最大的就是对 php 版本的要求,最低要求 7.2.0 版本,对 php
扩展组件版本也有要求,详见官网文档
https://www.zabbix.com/documentation/current/manual/installation/requirements
2、安装阿里云的zabbix镜像源:
- (1)安装源:
- [root@controlnode ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
- [root@controlnode ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
-
- (2)启用 zabbix 前端源,修改/etc/yum.repos.d/zabbix.repo,将[zabbix-frontend]下的 enabled 改为 1:
- [zabbix-frontend]
- name=Zabbix Official Repository frontend - $basearch
- baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
- enabled=1
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
-
- (3)清除yum源之前的缓存:
- [root@controlnode ~]# yum clean all
3、验证yum源:
yum list | grep zabbix
三、安装zabbix服务端及相关组件
1、安装zabbix-server、zabbix-agent、zabbix-get:
[root@controlnode ~]# yum install zabbix-server-mysql zabbix-agent zabbix-get -y
2、安装 Software Collections,便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4 过低:
- [root@controlnode ~]# yum install centos-release-scl -y
-
3、安装 zabbix 前端和相关环境:
[root@controlnode ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
4、查看安装的zabbix软件:
- [root@controlnode ~]# rpm -qa | grep zabbix
- zabbix-server-mysql-5.0.0-1.el7.x86_64
- zabbix-get-5.0.0-1.el7.x86_64
- zabbix-web-mysql-scl-5.0.0-1.el7.noarch
- zabbix-release-5.0-1.el7.noarch
- zabbix-agent-5.0.0-1.el7.x86_64
- zabbix-web-5.0.0-1.el7.noarch
- zabbix-web-deps-scl-5.0.0-1.el7.noarch
- zabbix-apache-conf-scl-5.0.0-1.el7.noarch
四、安装mariadb数据库
1、安装
[root@controlnode ~]# yum install mariadb-server -y
2、优化my.cnf参数:/etc/my.cnf【2核4G的配置】(可选):
- #清空/etc/my.cnf文件中的内容,复制下面全部的参数到/etc/my.cnf中:
- [client]
- port=3306
- default-character-set=utf8
- socket=/var/lib/mysql/mysql.sock
- [mysql]
- no-auto-rehash
- [mysqld]
- user=mysql
- port=3306
- socket=/var/lib/mysql/mysql.sock
- basedir=/usr
- datadir=/var/lib/mysql
- open_files_limit = 10240
- symbolic-links=0
- default-storage-engine = innodb
- innodb_file_per_table = on
- max_connections = 1000
- max_connect_errors = 6000
- back_log = 600
- table_open_cache = 614
- skip-external-locking
- max_allowed_packet = 32M
- character-set-server = utf8
- skip-name-resolve
- innodb_buffer_pool_size = 1024M
- query_cache_size=16M
- join_buffer_size = 2M
- query_cache_limit = 4M
- query_cache_min_res_unit = 2K
- thread_stack = 192K
- tmp_table_size = 64M
- max_heap_table_size = 64M
- read_buffer_size = 1M
- read_rnd_buffer_size = 4M
- bulk_insert_buffer_size = 16M
- key_buffer_size = 384M
- server-id = 1
- thread_concurrency = 4
- thread_cache_size = 64
- sort_buffer_size = 2M
- slow_query_log = ON
- long_query_time = 2
- slow_query_log_file = /tmp/mysql-slow.log
- innodb_thread_concurrency = 2
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 16M
- innodb_log_file_size = 128M
- lower_case_table_names = 1
- innodb_additional_mem_pool_size = 16M
- innodb_data_file_path = ibdata1:1024M:autoextend
- innodb_file_io_threads = 4
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
- innodb_write_io_threads = 2
- innodb_read_io_threads = 2
- sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- transaction_isolation = READ-COMMITTE
-
- [mysqldump]
- quick
- max_allowed_packet = 32M
- [mysqld_safe]
- log-error=/var/log/mariadb/mariadb.log
- pid-file=/var/run/mariadb/mariadb.pid
3、启动mariadb数据库,并开机自启动:
- [root@controlnode ~]# systemctl start mariadb.service
- [root@controlnode ~]# systemctl enable mariadb.service
- [root@controlnode ~]# netstat -tunlp | grep 3306
- tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17226/mysqld
4、初始化Mariadb,并配置root密码:
- [root@controlnode ~]# mysql_secure_installation
- #第二次回车,设置所需要的密码,重复输入密码完成后,再按回车至结束
- #root密码设置为1qaz@WSX
5、创建zabbix库:
- [root@controlnode ~]# mysql -uroot -p1qaz@WSX
- MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
- MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@"%" identified by "1qaz@WSX";
- MariaDB [(none)]> flush privileges;
- MariaDB [(none)]> quit;
6、初始化 zabbix 数据库:
- #导入数据
- [root@controlnode ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p1qaz@WSX zabbix
- #验证数据是否导入成功
- [root@controlnode ~]# mysql -uroot -p1qaz@WSX -e "use zabbix;show tables"
7、修改/etc/zabbix/zabbix_server.conf连接数据库的配置:
DBPassword=1qaz@WSX
五、时区和字体乱码解决
1、配置时区
- 修改 zabbix 的 php 配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的时区:
- php_value[date.timezone] = Asia/Shanghai
2、解决zabbix-web中文乱码的问题:
(1)查看zabbix-web链接的字体:
[root@controlnode ~]# ls -l /etc/alternatives/zabbix-web-font
(2)在windows中找到需要的字体格式后上传到"/usr/share/fonts/dejavu/"目录下:
在windows中查找需要的字体
(3)将字体上传到"/usr/share/fonts/dejavu/"目录下:
- [root@controlnode ~]# cd /usr/share/fonts/dejavu/
- [root@controlnode dejavu]# rz -y
(4)对旧的字体备份后进行替换:
- 备份旧的字体:
- [root@controlnode dejavu]# cp -a DejaVuSans.ttf DejaVuSans.ttf.bak
- 替换字体:
- [root@controlnode dejavu]# \mv simkai.ttf DejaVuSans.ttf
-
-
六、启动zabbix相关服务及配置连接
1、启动zabbix服务并设置开机自启动:
- [root@controlnode ~]# systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm
- [root@controlnode ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
2、访问页面配置连接
2.1、访问zabbix-server的配置页面,点击下一步:
http://192.168.1.201/zabbix/setup.php
2.2、点击下一步:
2.3、配置mysql数据库地址和密码,点击下一步:
2.4、配置zabbixServer的连接地址和zabbixServer的名称(可选):
2.5、点击下一步:
2.6、配置完成:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。