1 clear
2 ls
3 rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
4 sudo rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
5 cd /etc/yum.repos.d/
6 ls
7 yum install zabbix-server zabbix-server-mysql zabbix-web-mysql mariadb-server mariadb -y
8 sudo yum install zabbix-server zabbix-server-mysql zabbix-web-mysql mariadb-server mariadb -y
9 ls
10 clear
11 ls
12 vim /etc/httpd/conf.d/zabbix.conf
13 sudo vim /etc/httpd/conf.d/zabbix.conf
14 sudo vi /etc/httpd/conf.d/zabbix.conf
15 systemctl start mariadb
16 sudo systemctl start mariadb
17 mysql
18 mysql -u root -p
19 ls
20 cd /usr/share/doc/zabbix-server-mysql-3.0.16/
21 ls
22 zcat create.sql.gz | mysql -uzabbix -pzabbix
23 zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
24 source /usr/share/doc/zabbix-server-mysql-3.0.16/create.sql.gz
25 mysql -u root -p
26 zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
27 mysql -u root -p
28 zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
29 sudo vi /etc/zabbix/zabbix_server.conf
30 systemctl start zabbix
31 sudo systemctl start zabbix
32 systemctl stop firewalld.service
33 sudo systemctl stop firewalld.service
34 sudo systemctl stautus zabbix
35 sudo vim /etc/zabbix/zabbix_server.conf
36 sudo vi /etc/zabbix/zabbix_server.conf
37 systemctl start zabbix
38 sudo systemctl start zabbix
39 clear
40 ls
41 history
42 sudo yum install zabbix-agent -y
43 clear
44 ls
45 cd /etc/zabbix/
46 ls
47 cat /etc/services | grep zabbix
48 sudo vim /etc/zabbix/zabbix_server.conf
49 sudo vi /etc/zabbix/zabbix_server.conf
50 systemctl start httpd.service
51 sudo systemctl start httpd.service
52 sudo systemctl start zabbix-server
53 +
54 sudo -s
55 /bin/mail
56 ls
57 cd /etc/zabbix/zabbix_server.conf
58 yum cat /etc/zabbix/zabbix_server.conf
59 sudo cat /etc/zabbix/zabbix_server.conf
60 cd //usr/lib/zabbix/externalscripts
61 ls
62 clear
63 ls
64 ll
65 cd ..
66 ls
67 cd alertscripts/
68 ls
69 sudo vim email.sh
70 wget https://dldir1.qq.com/foxmail/work_weixin/WXWork_2.4.14.2349.exe
71 curl -O https://dldir1.qq.com/foxmail/work_weixin/WXWork_2.4.14.2349.exe
72 ls
73 sudo curl -O https://dldir1.qq.com/foxmail/work_weixin/WXWork_2.4.14.2349.exe
74 ls
75 sudo curl -O https://dldir1.qq.com/foxmail/work_weixin/WXWork_2.4.14.2349.exe
76 ls
77 rm -rf WXWork_2.4.14.2349.exe
78 sudo rm -rf WXWork_2.4.14.2349.exe
79 clear
80 sudo systemctl start zabbix-agent
81 netstat -lnpt | grep zabbix_agent
82 sudo netstat -lnpt | grep zabbix_agent
83 ps -ef | grep agent
84 ls
85 sudo vim /etc/zabbix/zabbix_agentd.conf
86 cd /etc/zabbix/zabbix_agentd.conf
87 sudo vi /etc/zabbix/zabbix_agentd.conf
88 cd /etc/rc.local
89 cat /etc/rc.local
90 sudo vi /etc/zabbix/zabbix_agentd.conf
91 cd /etc/zabbix/
92 ls
93 sudo vi /etc/zabbix/zabbix_agentd.conf
94 cat /etc/redhat-release
95 clear
96 ls
97 which alertscripts
98 ls
99 cat zabbix_server.conf
100 sudo cat zabbix_server.conf
101 sudo vim zabbix_server.conf
102 sudo vi zabbix_server.conf
103 cd /usr/lib/zabbix/alertscripts
104 ls
105 sudo vim email.sh
106 sudo vi email.sh
107 ls
108 clear
109 ls
110 chmod +x email.sh
111 sudo chmod +x email.sh
112 ls
113 tail -F /tmp/email.log
114 sudo yum install dos2unix
115 clear
116 sudo yum install sendmail
117 mail
118 /bin/mail
119 service sendmail start
120 sudo service sendmail start
121 vim boday.txt
122 vi boday.txt
123 ls
124 sudo vi body.txt
125 cat /var/log/maillog
126 sudo cat /var/log/maillog
127 sudo vim /etc/mail.rc
128 sudo vi /etc/mail.rc
129 sudo set from=yourname@163.com smtp=smtp.163.com
130 sudo vi /etc/mail.rc
131 sudo vim /etc/sysconfig/network
132 sudo vi /etc/sysconfig/network
133 ls
134 mail -s "test mail from linux" 13510777836@163.com <body.txt
135 sudo yum install mailx
136 mail -s "test mail from linux" 13510777836@163.com <body.txt
137 ls
138 clear
139 ls
140 ./email.sh
141 sudo vi email.sh
142 mail
143 mail -s "test mail from linux" chao.liu@hitachivantara.com <body.txt
144 mail -s "test mail from linux" liuchao@bitspace.com <body.txt
145 mail -s "test mail from linux" l3510777836@163.com <body.txt
146 mail -s "test mail from linux" 13510777836@163.com <body.txt
147 ls
148 sudo cat body.txt
149 sudo vim body.txt
150 sudo vi body.txt
151 mail -s "test mail from linux" 13510777836@163.com <body.txt
152 sudo vi body.txt
153 mail -s "test mail from linux" liuchao@bitspace.com <body.txt
154 sudo vim email.sh
155 sudo yum install vim
156 clar
157 clear
158 ls
159 sudo vim email.sh
160 tail -F /tmp/email.log
161 ls
162 curl 172.31.38.146: 10050
163 curl 172.31.41.175
164 curl 172.31.41.175:10050
165 clear
166 ls
167 whch zabbix_agentd
168 which zabbix_agentd
169 whereis zabbix_agentd
170 systemctl start zabbix_agentd
171 sudo systemctl start zabbix_agentd
172 sudo systemctl stop zabbix_agentd
173 sudo apt-get install zabbix_agentd
174 yum install zabbix_agentd
175 sudo yum install zabbix_agentd
176 sudo systemctl zabbix_server statux
177 sudo systemctl zabbix_server status
178 history
179 clear
180 zabbix_get
181 zabbix_get -s
182 which is zabbix_get
183 whereis zabbix_get
184 which zabbix
185 find -name /*/zabbix/bin
186 rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-get-3.2.1-1.el7.x86_64.rpm
187 sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-get-3.2.1-1.el7.x86_64.rpm
188 ls
189 zabbin_get
190 ls
191 cd ..
192 ls
193 cd ..
194 ls
195 whereis zabbix_get
196 /usr/bin/zabbix_get -help
197 /usr/bin/zabbix_get -s 18.188.187.173 -p 10050 -k "login-user"
198 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
199 yum install wget
200 sudo yum install wget
201 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
202 sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
203 yum -y install wqy-microhei-fonts
204 sudo yum -y install wqy-microhei-fonts
205 which fonts
206 whereis fonts
207 history
208 cd /etc/httpd/
209 ls
210 cd modules/
211 ls
212 cd ..
213 ls
214 cd run/
215 cd /etc/zabbix/
216 ls
217 cd web/
218 ls
219 su -s
220 su -S
221 sudo -s
222 ls
223 cat /etc/zabbix/zabbix_server.conf
224 sudo cat /etc/zabbix/zabbix_server.conf
225 cd /usr/lib/zabbix/
226 ls
227 cd alertscripts/
228 ls
229 cat email.sh
230 clear
231 mysql -uzabbix -p
232 sudo systemctl start mariadb.service
233 sudo systemctl stop mariadb.service
234 history
235 cat /etc/redhat_release
236 cat /etc/redhat-release
237 sudo systemctl start mariadb.service
238 sudo systemctl start zabbix
239 sudo systemctl start zabbix-server
240 history
手动编译
wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.8/zabbix-3.4.8.tar.gz/download
参考http://www.cnblogs.com/ctulzq/p/8709084.html
CentOS7安装Zabbix
一、Zabbix简介
Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
Zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
Zabbix由2部分构成,zabbix server与可选组件zabbix agent。
Zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,可以运行在众多平台上。
二、基础组件安装
zabbix的安装需要LAMP环境:
1
2
|
# yum install php php-gd php-mysql php-bcmath php-mbstring php-xml curl curl-devel net-snmp net-snmp-devel perl-DBI # yum install httpd mariadb* |
三、数据库配置
1
2
3
4
5
6
7
8
9
|
#systemctl start mariadb.service # mysql -u root -p Enter password: ##输入MySQL密码,默认为空 MariaDB [(none)]> create database zabbix character set utf8; ##创建数据库zabbix,并且数据库编码使用utf8 MariaDB [(none)]> insert into mysql.user(Host,User,Password) values( 'localhost' , 'zabbix' ,password( 'zabbix' )); ##新建账户zabbix,密码zabbix MariaDB [(none)]> flush privileges; ##刷新系统授权 MariaDB [(none)]> grant all on zabbix.* to 'zabbix' @ '127.0.0.1' identified by 'zabbix' with grant option; ##允许账户能从本机连接至数据库zabbix MariaDB [(none)]> flush privileges; |
四、zabbix的安装和配置
①下载并进行编译安装
1
2
3
4
5
6
7
8
9
10
11
12
|
# wget http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.5/zabbix-2.4.5.tar.gz # tar -zxvf zabbix-2.4.5.tar.gz # cd zabbix-2.4.5 # ./configure --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --prefix=/usr/local/zabbix --prefix----> 指定zabbix安装目录 -- enable -server----> 支持zabbix服务器 -- enable -agent----> 支持zabbix代理 -- enable -proxy----> 支持zabbix代理服务器 --with-libcurl----> 使用curl包 --with-net-snmp----> 使用net-snmp软件包,选择性地指定路径NET-SNMP配置 --with-mysql= /usr/bin/mysql_config 使用MySQL客户端库可以选择指定路径mysql_config 注:如出现configure: error: MySQL library not found错误,是因为缺少mariadb-devel 该软件包,yum install mariadb-devel进行安装 # make # make install |
②导入数据库
1
2
3
4
5
6
|
# mysql -u root -p MariaDB [(none)]> use zabbix; MariaDB [zabbix]> source /root/zabbix-2 .4.5 /database/mysql/schema .sql MariaDB [zabbix]> source /root/zabbix-2 .4.5 /database/mysql/data .sql MariaDB [zabbix]> source /root/zabbix-2 .4.5 /database/mysql/images .sql MariaDB [zabbix]> quit |
注:导入请按以上顺序导入,否则会出现错误情况。
③添加服务器对应的端口(可省略)
1
2
3
4
5
|
[root@localhost ~] # cat /etc/services |grep zabbix zabbix-agent 10050 /tcp # Zabbix Agent //客户端 zabbix-agent 10050 /udp # Zabbix Agent zabbix-trapper 10051 /tcp # Zabbix Trapper //服务端 zabbix-trapper 10051 /udp # Zabbix Trapper |
④拷贝相关的配置文件到/etc下并进行相关配置修改
1
2
3
4
5
6
|
[root@localhost ~] # mkdir -p /etc/zabbix [root@localhost ~] # cp -r zabbix-2.4.5/conf/* /etc/zabbix/ [root@localhost ~] # chown -R zabbix:zabbix /etc/zabbix [root@localhost ~] #ln -s /usr/local/zabbix/etc /etc/zabbix/ [root@localhost ~] # ln -s /usr/local/zabbix/bin/* /usr/bin/ [root@localhost ~] # ln -s /usr/local/zabbix/sbin/* /usr/sbin/ |
a).修改zabbix_server.conf
1
|
[root@localhost ~] # vi /etc/zabbix/zabbix_server.conf |
修改后如下:
1
2
3
4
5
6
7
8
|
[root@localhost ~] # cat /etc/zabbix/zabbix_server.conf|grep -n ^[^#] 30:LogFile= /tmp/zabbix_server .log ##日志文件地址 68:DBHost=localhost ##数据库主机 78:DBName=zabbix ##数据库名 94:DBUser=zabbix ##数据库用户名 102:DBPassword=zabbix ##数据库密码 282:ListenIP=127.0.0.1 ##数据库IP地址 425:AlertScriptsPath= /usr/local/zabbix/share/zabbix/alertscripts ##zabbix运行脚本存放目录 |
b).修改zabbix_agentd.conf
1
|
[root@localhost ~] # vi /etc/zabbix/zabbix_agentd.conf |
修改后如下:
1
2
3
4
5
6
7
8
9
|
[root@localhost ~] # cat /etc/zabbix/zabbix_agentd.conf|grep -n ^[^#] 11:PidFile= /tmp/zabbix_agentd .pid ##进程PID 21:LogFile= /tmp/zabbix_agentd .log ##日志保存位置 59:EnableRemoteCommands=1 ##允许执行远程命令 81:Server=127.0.0.1,192.168.10.128 122:ServerActive=127.0.0.1 133:Hostname=Zabbix server ##必须与zabbix创建的hostname相同 252:Include= /usr/local/etc/zabbix_agentd .conf.d/ 265:UnsafeUserParameters=1 ##启动自定义key |
五、修改PHP相关参数
1
2
3
4
5
6
7
|
# vi /etc/php.ini 384 max_execution_time = 300 394 max_input_time = 300 405 memory_limit = 128M 800 upload_max_filesize = 2M 878 date .timezone = Asia /Shanghai 672 post_max_size = 28M |
六、配置web站点
①
1
2
|
# cd zabbix-2.4.5/ # cp -r frontends/php /var/www/html/zabbix |
②修改httpd.conf的参数
1
2
3
4
|
# vi /etc/httpd/conf/httpd.conf 163 <IfModule dir_module> 164 DirectoryIndex index.html index.php 165 < /IfModule > |
③关闭SELinux和防火墙:
a、临时关闭(不用重启机器):
1
2
|
# setenforce 0 ##设置SELinux 成为permissive模式 (关闭SELinux) # setenforce 1 ##设置SELinux 成为enforcing模式 (开启SELinux) |
b、修改配置文件需要重启机器:
1
|
# vi /etc/selinux/config |
将SELINUX=enforcing 改为SELINUX=disabled(需重启机器)
c、可自己做策略开放相应端口,这里我直接关闭:
1
2
|
# systemctl status firewalld.service ##查看防火墙状态 # systemctl stop firewalld.service ##关闭防火墙 |
七、安装web界面
1
|
# systemctl start httpd.service |
在浏览器中输入http://127.0.0.1/zabbix进入zabbix的web配置页面=====》
(如全部OK)NEXT=====》
配置MySQL数据库信息,并点击“Test connection”按键,如OK====》NEXT=====》
默认,直接NEXT=====》
默认,直接NEXT=====》出现错误,提示Fail(忘截图了)
Configuration file"/var/www/html/zabbix/conf/zabbix.conf.php"
created: Fail
Unable to create the configuration file.Please install it manually, or fix permissions on the conf directory.
Press the "Download configuration file" button, download the configuration file and save it as"/var/www/html/zabbix/conf/zabbix.conf.php"When done, press the "Retry" button
=====》按提示点击“Download configuration file”按钮,并将下载的zabbix.conf.php保存到
/var/www/html/zabbix/conf/下,点击“Retry”按钮重试=====》
显示OK,点击“Finish”按钮完成安装操作。
1
|
Zabbix的默认账号为admin,密码为zabbix。 |
zabbix默认是英文版,更改语言======》Profile
======》在Language中选择zh_CN,点击Update
=====》已更改为汉语
八、添加开机启动脚本
1
2
3
4
5
6
7
8
9
|
# cd zabbix-2.4.5/ # cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server # cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd # chmod u+x /etc/rc.d/init.d/zabbix_server # chmod u+x /etc/rc.d/init.d/zabbix_agentd # chkconfig zabbix_server on # chkconfig zabbix_agentd on # /usr/local/zabbix/sbin/zabbix_server start # /usr/local/zabbix/sbin/zabbix_agentd start |
注:zabbix_server和zabbix_agentd都要启动。
当出现下图错误:
并提示如下:
Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
开启zabbix_agentd即可,如下,已经正常了
九、zabbix客户端的安装
在这里我使用的是Ubuntu来作为客户端,Ubuntu安装zabbix相对简单,只需安装如下组件:
zabbix-agent
zabbix-frontend-php
zabbix-server-mysql
如只做客户端,只需安装zabbix-agent即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$ sudo apt-get update $ sudo apt-get install zabbix-agent $ sudo /usr/sbin/zabbix_agentd start ##开启客户端端口 $ ss -tlnp | grep 10050 ##查看端口是否已开启 $ cat /etc/zabbix/zabbix_agentd .conf | grep ^[^ #] PidFile= /var/run/zabbix/zabbix_agentd .pid LogFile= /var/log/zabbix-agent/zabbix_agentd .log LogFileSize=0 SourceIP=192.168.10.131 ##本地IP Server=192.168.10.128 ##zabbix服务端IP Hostname=Prozj ##本地主机名 ListenPort=10050 Include= /etc/zabbix/zabbix_agentd .conf.d/ $ sudo /usr/sbin/zabbix_agentd restart |
然后进入服务端web界面======》组态=====》主机=====》创建主机=====》
=====》添加客户端主机名称、群组及IP地址======》切换至模板项======》
在链接的新模板后点击“选择”,选择完成后点击“添加”,就可以再连接的模板上看到管理了,最后点击“更新”,添加主机完成=====》
显示绿色,已正常监控。等待一段时间后,切换至第一栏“监控中”====》点击“图形”,就可以看到相应主机数据显示了。
附:
在Ubuntu上安装zabbix的wiki:
1
|
http: //wiki .ubuntu.org.cn /index .php?title=Zabbix&variant=zh-cn |