1.安装NGINX



yum install wget gcc* make pcre-devel zlib zlib-devel openssl openssl-devel -y
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar fvxz nginx-1.14.2.tar.gz 
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx
make && make install



手动启动和关闭nginx



1.环境变量:export PATH=$PATH:/usr/local/nginx/sbin/
2.检查nginx配置:nginx -t
3.启动nginx: nginx
4.关闭nginx:nginx -s stop



验证nginx安装是否成功



1.查看进程
2.查看监控端口
3.nginx日志
4.浏览器访问



使用systemctl管理nginx,/usr/lib/systemd/system/nginx.service



[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=multi-user.target



2.安装PHP



yum install epel-release -y 
yum install -y gcc* make  bzip2 bzip2-devel readline-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel 
cd /usr/local/src/
wget https://www.php.net/distributions/php-5.6.34.tar.gz
tar fvxz php-5.6.34.tar.gz 
cd php-5.6.34
./configure --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir=/usr/ --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline
 make && make install
cp php.ini-production /usr/local/php/etc/php.ini



启动PHP



环境变量:export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/

使用默认配置文件:
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf

检查配置文件:php-fpm -t

配置启动命令:
cp /usr/local/src/php-5.6.34/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm 
useradd www
service php-fpm start

配置测试页
vim /usr/local/nginx/html/test.php
<?php
echo "taobao zabbix";
?>

配置nginx
vim /usr/local/nginx/conf/nginx.conf

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

nginx -s reload 
浏览器访问:http://10.10.10.15/test.php



3.安装MySQL

 省略

测试PHP能否连接数据库



cat /usr/local/nginx/html/mysql.php 
<?php 
$link=mysql_connect("localhost","root","123456"); 
if(!$link) echo "FAILD!连接错误,用户名密码不对"; 
else echo "OK!可以连接"; 
?> 

然后浏览器访问:http://10.10.10.15/mysql.php



4.安装zabbix server



yum install -y libevent-devel wget tar gcc* make net-snmp-devel libxml2-devel libcurl-devel 
useradd -s /sbin/nologin zabbix
cd /usr/local/src
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
tar -zxf zabbix-4.0.3.tar.gz
cd zabbix-4.0.3
./configure --prefix=/usr/local/zabbix  --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install



选项说明



1.--prefix指定安装目录
2.--enable-server 安装zabbix server
3.--enable-agent  安装zabbix agent
4.--with-mysql



登录数据库,创建zabbix数据库及用户名和密码:



mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.08 sec)

mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected, 2 warnings (0.07 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

mysql>  show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.07 sec)



zabbix server需要导入3个sql文件:



cd /usr/local/src/zabbix-4.0.3

mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql



mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql 
mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql



将前端文件拷贝到项目目录下:



cd /usr/local/src/zabbix-4.0.3
cp -rp frontends/php /usr/local/nginx/html/zabbix



编辑zabbix_server.conf文件:


[root@yanglin2 ~]# egrep -v '(^$|^#)' /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=10.10.10.15
Timeout=4
LogSlowQueries=3000



启动zabbix server



[root@yanglin2 zabbix-4.0.3]# /usr/local/zabbix/sbin/zabbix_server



如果启动的时候报错:



[root@yanglin2 zabbix-4.0.3]# /usr/local/zabbix/sbin/zabbix_server 
/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

[root@yanglin2 zabbix-4.0.3]# ll /usr/local/mysql/lib/libmysqlclient.so.20
lrwxrwxrwx 1 mysql mysql 25 4月  13 22:22 /usr/local/mysql/lib/libmysqlclient.so.20 -> libmysqlclient.so.20.3.13
[root@yanglin2 zabbix-4.0.3]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/



web端配置zabbix



浏览器输入地址
10.10.10.15/zabbix/index.php
按照向导安装
第二步检查若有问题
vim /usr/local/php/etc/php.ini
date.timezone = Asia/Chongqing
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
然后重启PHP
第三步如果报错zabbix error connecting to database [no such file or directory]
vim /usr/local/php/etc/php.ini
mysqli.default_socket = /data/app/mysql/mysql.sock
然后重启PHP
第六步如果报错,先点击download
cp /root/下载/zabbix.conf.php /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
然后点击retry
安装完成后,通过http://10.10.10.15/zabbix/index.php#就能直接访问web管理界面(点击完成也会自动跳转)
默认用户名:admin,密码:zabbix
然后点击profile,调整语言



编辑zabbix server上面的agent



[root@yanglin2 ~]# egrep -v '(^$|^#)' /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
UnsafeUserParameters=1



启动zabbix server上的agent


/usr/local/zabbix/sbin/zabbix_agentd


4.解决中文乱码问题



进入电脑C:\Windows\Fonts,找到微软雅黑字体,上传到/usr/local/nginx/html/zabbix/fonts/目录下
修改zabbix网页设置
vim /usr/local/nginx/html/zabbix/include/defines.inc.php 
修改如下:
define('ZBX_GRAPH_FONT_NAME',           'msyh'); // font file name
默认是DejaVuSans,改成msyh
修改完成后到网页去验证即可



主机监控添加时的多种接口



1.agent:zabbix提供一个agent客户端,可装在Linux和windows
2.snmp:使用snmp协议去监控服务器,交换机,路由器
3.jmx:方便我们去监控java进程
4.ipmi监控硬件信息



5.grafana简介



1.Grafana本身并不存储数据,数据从其他地方获取,需要配置数据源
2.grafana支持从zabbix中获取数据
3.grafana优化了图形的展示,可以用来做监控大屏



安装grafana



wget https://dl.grafana.com/oss/release/grafana-6.2.5-1.x86_64.rpm 
sudo yum localinstall grafana-6.2.5-1.x86_64.rpm 
systemctl enable grafana-server
systemctl start grafana-server



浏览器访问grafana



http://10.10.10.23:3000/login
默认账号密码都是admin
登录后需要马上修改密码



grafana的使用

1.首先创建dashboard,然后再创建图形
2.每次操作都需要save程序,类似代码写完提交到代码管理服务器一样

zabbix WINDWOS安装 zabbix4.0安装部署_zabbix WINDWOS安装

然后保存,save

zabbix WINDWOS安装 zabbix4.0安装部署_zabbix WINDWOS安装_02

然后命名

zabbix WINDWOS安装 zabbix4.0安装部署_php_03

grafana的数据源介绍



1.支持influxdb等
2.默认不支持去zabbix读取数据,需要安装插件



grafana安装zabbix插件



1.grafana-cli plugins list-remote
2.grafana-cli plugins list-remote|grep -i zabbix
3.grafana-cli plugins install alexanderzobnin-zabbix-app
4.如果在线安装慢,可以先到此地址下载 https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/3.10.2/download
  放到 /var/lib/grafana/plugins,然后解压即可
5.systemctl restart grafana-server  重启grafana



zabbix WINDWOS安装 zabbix4.0安装部署_开发工具_04

可以看到已经支持zabbix插件

 

grafana开启zabbix插件
plugins-->apps-->zabbix-->enable

 

zabbix WINDWOS安装 zabbix4.0安装部署_zabbix WINDWOS安装_05

zabbix WINDWOS安装 zabbix4.0安装部署_php_06

点击enable即可

 

grafana配置zabbix数据源

zabbix WINDWOS安装 zabbix4.0安装部署_mysql_07

选择zabbix

zabbix WINDWOS安装 zabbix4.0安装部署_开发工具_08

填写配置信息

zabbix WINDWOS安装 zabbix4.0安装部署_mysql_09

zabbix WINDWOS安装 zabbix4.0安装部署_开发工具_10

数据源配置完成

grafana画板中添加图形

 

zabbix WINDWOS安装 zabbix4.0安装部署_php_11

zabbix WINDWOS安装 zabbix4.0安装部署_运维_12

zabbix WINDWOS安装 zabbix4.0安装部署_mysql_13

zabbix WINDWOS安装 zabbix4.0安装部署_zabbix WINDWOS安装_14

zabbix WINDWOS安装 zabbix4.0安装部署_zabbix WINDWOS安装_15

最后点击右上角的save即可

 

 

grafana画板中添加图形

grafana变量高级功能

grafana展示zabbix数据
1.单台服务器的流量比较好展现,但多台服务器的流量得手动创建图形,比较麻烦
2.grafana的变量功能让我们可以选择展现哪台服务器的流量