zabbix應用搭建

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
zabbix應用搭建
2.2
zabbix應用搭建
2.3
zabbix應用搭建
2.4
zabbix應用搭建
2.5
zabbix應用搭建
2.6
zabbix應用搭建
2.7

登陸 name:Admin pwd: zabbix

2.8
zabbix應用搭建

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

zabbix應用搭建

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

zabbix應用搭建

也可以打開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上添加監控服務器
zabbix應用搭建

3.6查看連接
zabbix應用搭建

zabbix基礎部分到此結束

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章