---
# System prepended metadata

title: Zabbix節點安裝

---

---
title: Zabbix節點安裝

---

## 　第一步、安裝Zabbix基本元件
```
sudo su -

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm

sudo yum install zabbix-agent -y
```

## 　第二步、編輯Zabbix文檔

`sudo vim /etc/zabbix/zabbix_agentd.conf`

 Zabbix Server 的 IP 地址
```
Server=43.129.85.214
```

允许连接的客户端（Zabbix Server）的 IP 地址
```
ServerActive=43.129.85.214
```

最末要添加 
**现在这个不准 请去抓zabbix监控项状态全部显示已启用的 节点 抓资料**
![zabbix资料](https://hackmd.io/_uploads/SkUS27FXyg.gif)


```
UserParameter=check.established, /etc/zabbix/scripts/check_established.sh
UserParameter=check.nginx_worker, /etc/zabbix/scripts/check_nginx_worker.sh
UserParameter=check.ants_agent, /etc/zabbix/scripts/check_ants_agent.sh
UserParameter=check.memory, /etc/zabbix/scripts/check_memory.sh
UserParameter=check.cpu, /etc/zabbix/scripts/check_cpu.sh
UserParameter=check.5xx,/etc/zabbix/scripts/check_5xx.sh
UserParameter=check.4xx,/etc/zabbix/scripts/check_4xx.sh
UserParameter=check.df,/etc/zabbix/scripts/check_df.sh
UserParameter=check.rx,/etc/zabbix/scripts/check_rx.sh
UserParameter=check.tx,/etc/zabbix/scripts/check_tx.sh
UserParameter=check.synrecv,/etc/zabbix/scripts/SYN_RECV.sh
UserParameter=check.waitconnection,/etc/zabbix/scripts/wait_connection.sh
UserParameter=check.udpconnection,/etc/zabbix/scripts/udp_connection.sh
UserParameter=nginx.error.timeout,/etc/zabbix/scripts/nginx_error_log_stats.pl | grep timeout_error | awk '{print $2}'
UserParameter=nginx.error.upstream_closed,/etc/zabbix/scripts/nginx_error_log_stats.pl | grep upstream_closed | awk '{print $2}'
UserParameter=nginx.error.connection_timed_out,/etc/zabbix/scripts/nginx_error_log_stats.pl | grep connection_timed_out | awk '{print $2}'
UserParameter=nginx.error.connection_reset,/etc/zabbix/scripts/nginx_error_log_stats.pl | grep connection_reset | awk '{print $2}'
UserParameter=iostat.read,/etc/zabbix/scripts/iostat_to_zabbix.sh | awk '{print $1}'
UserParameter=iostat.write,/etc/zabbix/scripts/iostat_to_zabbix.sh | awk '{print $2}'
UserParameter=loadavg.1min,/etc/zabbix/scripts/loadavg_to_zabbix.sh | awk '{print $1}'
UserParameter=loadavg.5min,/etc/zabbix/scripts/loadavg_to_zabbix.sh | awk '{print $2}'
UserParameter=loadavg.15min,/etc/zabbix/scripts/loadavg_to_zabbix.sh | awk '{print $3}'
UserParameter=check.http_service,/etc/zabbix/scripts/http_service.sh
UserParameter=check.user_login,/etc/zabbix/scripts/user_login.sh
UserParameter=vmstat.r,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $1}'
UserParameter=vmstat.swpd,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $2}'
UserParameter=vmstat.cpu_us,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $3}'
UserParameter=vmstat.cpu_sy,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $4}'
UserParameter=vmstat.cpu_id,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $5}'
UserParameter=vmstat.cpu_wa,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $6}'
UserParameter=vmstat.cpu_st,/etc/zabbix/scripts/collect_vmstat.sh | awk '{print $7}'
UserParameter=mpstat.cpu_usage_0,/etc/zabbix/scripts/collect_mpstat.sh | awk '{print $1}'
UserParameter=mpstat.cpu_usage_1,/etc/zabbix/scripts/collect_mpstat.sh | awk '{print $2}'
UserParameter=mpstat.cpu_usage_2,/etc/zabbix/scripts/collect_mpstat.sh | awk '{print $3}'
UserParameter=mpstat.cpu_usage_3,/etc/zabbix/scripts/collect_mpstat.sh | awk '{print $4}'
UserParameter=iostat.util_avg,/etc/zabbix/scripts/collect_iostat_util.sh
```

## 　第三步、賦予zabbix用戶有sudo 權限
`sudo visudo`
新增內容
```
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/ipset
```



## 　第四步、放置腳本文件並開啟Zabbix-agent 



脚本放置路徑:/etc/zabbix/script    //script資料夾要建立  可使用Termius
![image](https://hackmd.io/_uploads/SkYeM2rZyg.png)


直接把腳本資料夾拉到節點的/etc/zabbix裡面


![image](https://hackmd.io/_uploads/rJBJrnS-yl.png)

把腳本權限設為777 並啟動 zabbix-agent
```
chmod 777 /etc/zabbix/scripts/*
sudo systemctl start zabbix-agent
sudo systemctl enable zabbix-agent
sudo systemctl status zabbix-agent
```


## 　第五步、Zabbix頁面新增節點

在zabbix>配置>主機>新增節點
![image](https://hackmd.io/_uploads/BJhkyOQZyx.png)


## 错误排查
zabbix>主機>監控項
![image](https://hackmd.io/_uploads/SkMZP8i81x.png)
若出現以上錯誤，有可能是iostat這個服務未安裝
iostat -> 此服務是監控cpu使用率等問題

```
yum install sysstat -y
systemctl restart zabbix-agent.service

```