Zabbix安装配置
将相关命令写下,留作参考1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#一 服务端配置
#1.配置前先关闭iptables和SELINUX,避免安装过程中报错。
service iptables stop
chkconfig iptables off
getenforce
#Disabled
setenforce 0
#添加iptables防火墙放行
iptables -I INPUT -p tcp -m multiport --destination-port 10050:10055 -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT
一、查看SELinux状态命令:
1、/usr/sbin/sestatus -v##如果SELinux status参数为enabled即为开启状态
SELinux status:enabled
2、getenforce##也可以用这个命令检查
二、关闭SELinux方法:
1、临时关闭(不用重启机器):
#复制代码
#代码如下:
#setenforce 0 #设置SELinux 成为permissive模式
#setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
#修改/etc/selinux/config 文件
#将SELINUX=enforcing改为SELINUX=disabled
#重启机器即可
#2.安装lamp环境
yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-common php-mbstring php-gd php-odbc php-xml php-pear
#3.下载zabbix-2.0.6.tar.gz
#4.安装zabbix组件
yum install -y curl curl-devel net-snmp net-snmp-devel perl-DBI
#5.创建用户账号(server,agent)
useradd zabbix
usermod -s /sbin/nologin zabbix
#6.创建zabbix数据库并导入zabbix数据库(server)
tar zxvf zabbix-2.0.6.tar.gz
mysqladmin -u root password zxsoft
mysql –uroot –pzxsoft
mysql>
#mysql下
create database zabbix character set utf8;
grant all on zabbix.* to zabbix@localhost identified by 'zxsoft';
use zabbix;
source /root/zabbix-2.2.6/database/mysql/schema.sql
source /root/zabbix-2.2.6/database/mysql/images.sql
source /root/zabbix-2.2.6/database/mysql/data.sql
#7.编译安装,如果是客户端安装选择--enable-agent就行了。
#cd /root/zabbix-2.0.6
# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl
#(可以用--prefix=/usr/local/ 指定安装目录)
#报错: checking for main in -lmysqlclient... no
# configure: error: Not found mysqlclient library
#解决:# ln -s /usr/lib64/mysql/libmysqlclient.so.16 /usr/lib64/mysql/libmysqlclient.so
#***********************************************************
#* Now run 'make install' *
#* Thank you for using Zabbix! *
#* <http://www.zabbix.com> *
#***********************************************************
make install
#8.编辑配置文件
# grep -vE '(^#|" "|^$)' /usr/local/etc/zabbix_server.conf >> /usr/local/etc/zabbix_server.conf.bak
# cd /usr/local/etc/
# cp zabbix_server.conf.bak zabbix_server.conf
# grep -vE '(^#|" "|^$)' zabbix_agentd.conf >> zabbix_agentd.conf.bak
# cp zabbix_agentd.conf.bak zabbix_agentd.conf
#提示 cp: overwrite `zabbix_agentd.conf'? y
# more zabbix_server.conf
#服务端的配置
LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
#我这查看的时候是空的,可能前面操作有问题吧,如果是空的,直接用vim编辑,把上面几行复制进去就行了
# more zabbix_agentd.conf #客户端配置
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
# touch /var/log/zabbix_server.log
# touch /var/log/zabbix_agentd.log
# chmod 777 /var/log/zabbix_*
#9.启动服务(server,agent)
# cp misc/init.d/tru64/zabbix_server /etc/init.d/
# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
# chmod +x /etc/init.d/zabbix_*
#在文件头部#!/bin/bash下面分别添加两行
#!/bin/sh
#chkconfig: 35 95 95
#description:zabbix Agent server
#添加服务
# chkconfig --add zabbix_server
# chkconfig --add zabbix_agentd
#设置服务器开机自动启动
# chkconfig zabbix_server on
# chkconfig zabbix_agentd on
# /etc/init.d/zabbix_server start
Zabbix server started.
# /etc/init.d/zabbix_agentd start
Zabbix agent started.
# ps -ef |grep zabbix
zabbix 1803 10 08:21 ? 00:00:00 /usr/local/sbin/zabbix_agentd
zabbix 180518030 08:21 ? 00:00:00 /usr/local/sbin/zabbix_agentd
zabbix 180618030 08:21 ? 00:00:00 /usr/local/sbin/zabbix_agentd
zabbix 180718030 08:21 ? 00:00:00 /usr/local/sbin/zabbix_agentd
zabbix 180818030 08:21 ? 00:00:00 /usr/local/sbin/zabbix_agentd
zabbix 1814 10 08:21 ? 00:00:00 /usr/local/sbin/zabbix_server
root 204320060 08:23 pts/0 00:00:00 grep zabbix
# netstat -lantp |grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1803/zabbix_agentd
# netstat -lantp |grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2308/zabbix_server
#10.安装zabbix web界面(server)
#复制php文件,zabbix的终端程序是用php写的,因此需要一个支持php脚本解析的web服务器。然后将frontends/php下面的php文件拷贝到web服务器html文件目录下面。
# cp -r frontends/php /var/www/html/zabbix
#service httpd restart
Stopping httpd:
Starting httpd:
#报错:根据提示修改/etc/php.ini文件里的参数
# yum install -y php-bcmath
#设置时区,修改php.ini,在php.ini中找到data.timezone =去掉它前面的;号,然后设置data.timezone = “Asia/Shanghai”;即可
# /etc/init.d/httpd restart
Stopping httpd:
Starting httpd:
#mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
#Error connecting to database
#连接数据库时报错测试不成功
port = 3306
socket = /var/lib/mysql_data/mysql.sock
#这个添加后,不行,重新启动mssqld服务又可以了,不知是不是有关
#给/tmp/mysql.sock设置个软连接: 测试没有/tmp/mysql.sock 这个文件
#ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
#socket=/var/lib/mysql/mysql.sock
#如果提示创建文件失败,更改目录权限就行了 下面是报错
#Configuration file
#"/var/www/html/zabbix/conf/zabbix.conf.php"
#created: Fail
#登陆时初始用户名admin密码zabbix
web支持中文设置
#vim /var/www/html/zabbix/include/locales.inc.php
#zh_CN false改为true
图像无显示或乱码 修改zabbix页面管理的中文字体设置
#找到本地C:Windows\Fonts\simkai.ttf(楷体)
#sed -i ‘s/graphfont/simkai/g’ include/defines.inc.php
# vi /var/www/html/zabbix/include/defines.inc.php
#修改如下2行
define('ZBX_FONT_NAME', 'simkai');
define('ZBX_GRAPH_FONT_NAME','simkai');
zabbix simple check 配置
#fping测试网卡存活
#下载源码包编译安装
wget http://www.fping.org/dist/fping-3.10.tar.gz
tar zxvf fping-3.10.tar.gz
cd fping-3.10
./configure --prefix=/usr/local/fping/
make && make install
#根据安装地址,可能需要更改配置文件
修改zabbix_server.conf配置文件
vim /usr/local/zabbix/etc/zabbix_server.conf
把FpingLocation路径修改为刚安装的fping路径。
FpingLocation=/usr/local/fping/sbin/fping
如果不修改zabbix_server.conf配置件需要使用软连接到/usr/local/sbin/fping,zabbix默认fping的路径是/usr/sbin/fping
ln -s /usr/sbin/fping /path/to/non-existant/fping
ln -s /usr/sbin/fping6 /path/to/non-existant/fping6
chmod 4755 /usr/local/sbin/fping
service zabbix_server restart#重启服务
3.修改fping权限(如果不设下面权限,zabbix服务端会采集不到数据)
# chown root:zabbix /usr/local/fping/sbin/fping
# chmod 4710 /usr/local/fping/sbin/fping
4.zabbix用户测试fping命令
/usr/local/fping/sbin/fping www.baidu.com
www.baidu.com is alive # 说明命令返回成功。
本地邮件服务器发送邮件告警
#CentOS默认已安装postfix 开机自动启动
#mailx版本12.4
yum install mailx #版本12
使用外部邮件发送告警,本地测试正常,zabbix测试失败
vim /etc/mail.rc
set from=malin@safefw.com smtp=smtp.exmail.qq.com
set smtp-auth-user=malin@safefw.com smtp-auth-password=************ smtp-auth=login
zabbix实际只使用了简单的监控
页:
[1]