1.yum安装zabbix 1.1使用MySQL数据库安装存储库repo文件

[root@localhost ~]# yum -y install wget [root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm warning: /var/tmp/rpm-tmp.6aQiSY: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY

1.2安装Zabbix服务,前端,代理

[root@localhost yum.repos.d]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent [root@bogon ~]# yum install zabbix-get.x86_64

1.3.安装数据库mysql5.7.20

#!/bin/bash
#author:pan
#切换到相应文件夹
cd 
#二进制安装mysql5.7.20
tar xvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local/
mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
cd /usr/local/mysql/
mkdir -p data log binlogs run
cd /usr/local/
#添加用户
useradd -M -s /sbin/nologin mysql
#更改属主
chown -R mysql.mysql mysql
#添加路径
ln -s /usr/local/mysql/bin/* /usr/local/bin/
#删除原my.cnf
rm -f /etc/my.cnf
#创建my.cnf
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535

skip-name-resolve
lower_case_table_names=1

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0

key_buffer_size = 64M

log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5

tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0

server-id=1
EOF
#初始化数据库
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#设置启动项
cat > /usr/lib/systemd/system/mysqld.service << EOF
#Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
##This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; version 2 of the License.
##This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
##You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
##systemd service file for MySQL forking server

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/run/mysqld.pid

#Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

#Execute pre and post scripts as root
PermissionsStartOnly=true

#Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd

#Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS

#Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

#Sets open_files_limit
LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false
EOF
#重新加载daemon
systemctl daemon-reload
systemctl enable mysqld.service
systemctl start mysqld
#启动后第一次登陆密码
#grep 'temporary password' /usr/local/mysql/log/mysql_error.log
#修改初始密码
#mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '000000';
#安装完成

1.4创建账号

[root@localhost ~]# grep 'temporary password' /usr/local/mysql/log/mysql_error.log 2018-09-21T01:26:12.677078Z 1 [Note] A temporary password is generated for root@localhost: jltipYaq<644 [root@localhost ~]# mysql -uroot -p Enter password: #输入上面的密码 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '000000'; #修改密码 Query OK, 0 rows affected (0.01 sec) mysql> create database zabbix character set utf8 collate utf8_bin; #创建数据库 Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@'192.168.%.%' identified by '000000'; #创建账户 Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '000000'; Query OK, 0 rows affected, 2 warnings (0.00 sec) #创建账户 mysql> flush privileges; #刷新账户 Query OK, 0 rows affected (0.00 sec) mysql> exit #退出 Bye

1.5导入数据库

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix -h192.168.9.22 Enter password:

1.6配置zabbix-server.conf #如果此处用的是服务3的数据库脚本,则别忘了更改数据库的sock位置/app/mysql5.7/mysql.sock和port端口2297

[root@localhost ~]# cat -n /etc/zabbix/zabbix_server.conf | sed -n '12p;38p;101p;117p;125p;132p;140p;164p;203p;346p;490p' 12 ListenPort=10051 监听端口 38 LogFile=/var/log/zabbix/zabbix_server.log 日志路径 101 DBName=zabbix 数据库的数据库名 117 DBUser=zabbix 数据库的用户 125 DBPassword=000000 132 DBSocket=/usr/local/mysql/run/mysql.sock 140 DBPort=3306 164 StartPollers=5 203 StartTrappers=10 346 ListenIP=0.0.0.0 490 AlertScriptsPath=/usr/lib/zabbix/alertscripts

1.7为Zabbix前端配置PHP

[root@localhost ~]# cat -n /etc/httpd/conf.d/zabbix.conf |grep 20 20 php_value date.timezone Asia/Shanghai

1.8 启动Zabbix服务器和代理进程

[root@localhost ~]# systemctl restart zabbix-server zabbix-agent httpd [root@localhost ~]# systemctl enable zabbix-server zabbix-agent httpd Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service. Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

2.基础配置zabbix

[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0

2.1 2.2 2.3 2.4 2.5 2.6 2.7

登陆 name:Admin pwd: zabbix

2.8

2.9解决乱码问题

[root@localhost ~]# cd /usr/share/zabbix/fonts/ [root@localhost fonts]# ls graphfont.ttf [root@localhost fonts]# rz -E #上传黑体的ttf rz waiting to receive. [root@localhost fonts]# ls graphfont.ttf simhei.ttf [root@localhost fonts]# cp graphfont.ttf{,.bak} [root@localhost fonts]# ls graphfont.ttf graphfont.ttf.bak simhei.ttf [root@localhost fonts]# mv simhei.ttf graphfont.ttf mv: overwrite ‘graphfont.ttf’? y [root@localhost fonts]# ls graphfont.ttf graphfont.ttf.bak

3.zaibbix-agent配置 3.1下载agent端

[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm warning: /var/tmp/rpm-tmp.6aQiSY: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY

3.2安装Zabbix客户端

[root@localhost yum.repos.d]# yum -y install zabbix-agent

[root@bogon yum.repos.d]# cat -n /etc/zabbix/zabbix_agentd.conf | sed -n '13p;32p;97p;105p;122p;138p;149p;267p;286p' 13 PidFile=/var/run/zabbix/zabbix_agentd.pid #进程pid存放路径 32 LogFile=/var/log/zabbix/zabbix_agentd.log #zabbix agent日志存放路径 97 Server=192.168.9.22 #指定zabbix server端IP地址 此处我根据实际情况改为了Server=192.168.9.22 105 ListenPort=10050 #指定agentd的监听端口 122 StartAgents=3 #指定启动agentd进程数量。设置0表示关闭 138 ServerActive=192.168.9.22:10051 #启用agnetd主动模式,启动主动模式后,agentd将主动将收集到的数据发送到zabbix server端,Server Active后面指定的IP就是zabbix server端IP 149 Hostname=192.168.9.14 #需要监控服务器的主机名或者IP地址,此选项的设置一定要和zabbix web端主机配置中对应的主机名一致 267 Include=/etc/zabbix/zabbix_agentd.d/ #相关配置都可以放到此目录下,自动生效 286 UnsafeUserParameters=1 #启用agent端自定义item功能,设置此参数为1后,就可以使用UserParameter指令了。UserParameter用于自定义item


此149条很重要**** 此hostname为agent的hostname或ip

也可以打开HostnameItem功能,设置自己获取hostname

[root@zabbix-agent zabbix]# hostname zabbix-agent 但不管怎么样,此处设置hostname或ip在以后建主机时也必须是这个名字,决不能错

3.3启动zabbix-agent

[root@bogon yum.repos.d]# systemctl start zabbix-agent [root@bogon yum.repos.d]# which ss /usr/sbin/ss [root@bogon yum.repos.d]# ss -antup|grep 10050 tcp LISTEN 0 128 :10050 : users:(("zabbix_agentd",pid=2201,fd=4),("zabbix_agentd",pid=2200,fd=4),("zabbix_agentd",pid=2199,fd=4),("zabbix_agentd",pid=2198,fd=4),("zabbix_agentd",pid=2197,fd=4),("zabbix_agentd",pid=2196,fd=4)) tcp LISTEN 0 128 :::10050 ::: users:(("zabbix_agentd",pid=2201,fd=5),("zabbix_agentd",pid=2200,fd=5),("zabbix_agentd",pid=2199,fd=5),("zabbix_agentd",pid=2198,fd=5),("zabbix_agentd",pid=2197,fd=5),("zabbix_agentd",pid=2196,fd=5))

3.4在zabbix-server测试连通性,如果不通查看防火墙

[root@bogon share]# zabbix_get -s 192.168.9.14 -p 10050 -k "system.uptime" 14846

3.5在web上添加监控服务器

3.6查看连接

zabbix基础部分到此结束