摘要
-
zabbix 3.4版本
-
CentOS6.9+Nginx1.9.9+Mysql5.7+Php5.6(LNMP)
安装
– CentOS6.9环境准备
-
系统安装指导文档
-
网卡配置
-
防火墙设置
-
iptables 文件
ll /etc/sysconfig/iptables
查看iptables是否存在
iptables -P OUTPUT ACCEPT
生成任意规则
service iptables save
生成iptables文件 -
设置防火墙规则
service iptables stop
vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
`service iptables start``chkconfig iptables on``chkconfig --list iptables`
-
-
SELINUX设置
- vim /etc/selinux/config
vi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXTYPE=targeted #注释掉SELINUX=disabled #增加:wq! #保存退出
setenforce 0
使配置立即生效
-
wget安装
yum install wget
– Nginx1.9.9安装
-
依赖软件
yum install pcre* -y yum install openssl* -y yum install zlib* -y
-
源码包下载
cd /usr/local/src/ wget http://nginx.org/download/nginx-1.9.9.tar.gz
-
安装
tar -zxvf nginx-1.9.9.tar.gzcd nginx-1.9.9./configure --prefix=/usr/local/nginx/ --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcremakemake install
-
开机自启动脚本
vim /usr/local/nginx/nginx.sh
#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for everyone.# processname: nginx# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginx #/注意你安装nginx是否这个路径nginx_config=/usr/local/nginx/conf/nginx.conf #/注意你安装nginx是否这个路径nginx_pid=/usr/local/nginx/logs/nginx.pid #/注意你安装nginx是否这个路径RETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start) {if [ -e $nginx_pid ];thenecho "nginx already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop) {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid}# reload nginx service functions.reload) {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1esacexit $RETVAL``````cp nginx.sh /etc/rc.d/init.d/nginxchmod 755 /etc/rc.d/init.d/nginxchkconfig nginx on```
-
启动
service nginx start
-
维护命令
service nginx start 或者 /usr/local/nginx/sbin/nginx service nginx reload 或者 /usr/local/nginx/sbin/nginx -s reload service nginx stop 或者/usr/local/nginx/sbin/nginx -s stop
-
多站点配置
-
基本配置与参数说明
– Mysql5.7安装
-
配置yum源
cd /etc/yum.repos.d
vim mysql-community.repo
# Enable to use MySQL 5.7 [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
`yum repolist enabled | grep mysql`下载RPM-GPG-KEY-mysql `wget http://repo.mysql.com/RPM-GPG-KEY-mysql -O /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql`
-
yum安装
yum install mysql -y yum install mysql-server -y yum install mysql-devel -y
查看具体安装目录 `rpm -ql mysql-community-server-5.7.22-1.el6.x86_64` 查看mysql安装包名称 `rpm -qa mysql* `
-
密码修改
查看初始密码sudo grep 'temporary password' /var/log/mysqld.log
修改密码
mysql -uroot -pcl4it0XX9_ul SET PASSWORD = PASSWORD'123=abc@ABC=123'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; flush privileges;
-
开机启动
chkconfig mysqld on chkconfig mysqld on
– PHP5.6安装
-
依赖软件
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -yyum install openldap openldap-devel -y```
-
源码包下载
cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.36.tar.gz
-
安装
tar -zxvf php-5.6.36.tar.gz
cd php-5.6.36
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --with-ldap --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make make install
-
配置
4.1 修改php.ini参数
cp /usr/local/src/php-5.6.36/php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
max_execution_time = 300 memory_limit = 128M post_max_size = 16M upload_max_filesize = 2M max_input_time = 300 date.timezone PRC always_populate_raw_post_data = -1
4.2 php-fpm.conf
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
修改如下参数:
pid = run/php-fpm.pid request_terminate_timeout = 300
-
开机自启动服务
cp /usr/local/src/php-5.6.36/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm chkconfig php-fpm on
-
启动
service php-fpm start 或者 /usr/local/php/sbin/php-fpm
-
校验
netstat -lnt | grep 9000
ps aux | grep php-fpm
-
维护命令
service php-fpm start 或者 /usr/local/php/sbin/php-fpm service php-fpm stop service php-fpm reload
-
不重新编译为PHP增加LDAP模块的支持
```cd /usr/local/src/php-5.6.36/ext/ldap/usr/local/php/bin/phpizecp -frp /usr/lib64/libldap* /usr/lib./configure --with-ldap --with-php-config=/usr/local/php/bin/php-configmakemake install# php.ini添加ldap模块vim /usr/local/php/etc/php.iniextension = ldap.soservice php-fpm reloadservice php-fpm restart```
- Zabbix安装
-
依赖软件
```yum install libevent-develyum install net-snmp*# find / -name mysql_config 如果没找到执行下边一条yum install mysql-devel```
-
安装
``` wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.9/zabbix-3.4.9.tar.gz tar -zxvf zabbix-3.4.9.tar.gz cd zabbix-3.4.9 ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config make make install # 添加系统软连接 ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ ln -s /usr/local/zabbix/bin/* /usr/local/bin/ ```
-
修改Zabbix Server配置
`cd /usr/local/zabbix/etc``vim vim zabbix_server.conf````DBName=zabbix #数据库名称DBUser=zabbix #数据库用户名 DBPassword=123=abc@ABC=123 #数据库密码 ListenIP=127.0.0.1 #数据库ip地址 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录```
-
修改Zabbix Agent配置
vim /usr/local/zabbix/etc/zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ UnsafeUserParameters=1 #启用自定义key
-
开机自启动服务
```cp /usr/local/src/zabbix-3.4.9/misc/init.d/fedora/core/zabbix_* /etc/rc.d/init.d/# 修改脚本中zabbix的安装目录 vim /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件BASEDIR=/usr/local/zabbix/ #zabbix安装目录:wq! #保存退出vim /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件BASEDIR=/usr/local/zabbix/ #zabbix安装目录:wq! #保存退出chmod +x /etc/rc.d/init.d/zabbix_*chkconfig zabbix_server onchkconfig zabbix_agentd on```
-
创建用户
```groupadd zabbix useradd zabbix -g zabbix -s /bin/false # /bin/false 账号禁止用于登陆```
-
添加zabbix服务对应的端口
```# vim /etc/services 末尾添加以下内容:# Zabbixzabbix-agent 10050/tcp # Zabbix Agentzabbix-agent 10050/udp # Zabbix Agentzabbix-trapper 10051/tcp # Zabbix Trapperzabbix-trapper 10051/udp # Zabbix Trapper```
- Mysql数据库配置
-
创建zabbix数据库
create database zabbix DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
-
创建zabbix用户
```# 允许本地 IP 访问 localhost, 127.0.0.1use mysql;create user 'zabbix'@'localhost' identified by '123=abc@ABC=123';# 允许外网 IP 访问use mysql;create user 'zabbix'@'%' identified by '123=abc@ABC=123';# 刷新授权flush privileges;```
-
数据库授权
```# 授予用户在本地服务器对该数据库的全部权限grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123=abc@ABC=123';# 授予用户通过外网IP对于该数据库的全部权限grant all privileges on zabbix.* to 'zabbix'@'%' identified by '123=abc@ABC=123';# 刷新授权flush privileges;# 权限查看show grants for 'zabbix'@'localhost';```
-
导入zabbix数据库
方法一``` mysql -uroot -p123=abc@ABC=123use zabbix;source /usr/local/src/zabbix-3.4.9/database/mysql/schema.sql;source /usr/local/src/zabbix-3.4.9/database/mysql/images.sql;source /usr/local/src/zabbix-3.4.9/database/mysql/data.sql;```
方法二
``` mysql -uroot -p123=abc@ABC=123 zabbix < /usr/local/src/zabbix-3.4.9/database/mysql/schema.sqlmysql -uroot -p123=abc@ABC=123 zabbix < /usr/local/src/zabbix-3.4.9/database/mysql/images.sql;mysql -uroot -p123=abc@ABC=123 zabbix < /usr/local/src/zabbix-3.4.9/database/mysql/data.sql;```
-
添加软连接
```cd /usr/lib64/mysql #32位系统为/usr/lib/mysqlln -s libmysqlclient.so.16.0.0 libmysqlclient.soln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so```
- Nginx站点配置
-
配置站点目录
```mkdir -p /usr/local/nginx/html/zabbix/cp -rf /usr/local/src/zabbix-3.4.9/frontends/php/* /usr/local/nginx/html/zabbix/```
-
添加配置文件
```# 创建多站点配置目录mkdir /usr/local/nginx/conf/vhost/# vim /usr/local/nginx/conf/vhost/monitor.zabbix.com.conf 添加以下内容:server {listen 80 default; #default表示默认以IP作为访问方式,不添加则禁止IP访问server_name monitor.zabbix.com;access_log /usr/local/nginx/logs/zabbix/monitor.zabbix.com.access.log main;index index.html index.php index.html;root /data/site/monitor.zabbix.com;location /{try_files $uri $uri/ /index.php?$args;}location ~ ^.+.php).*)$ {fastcgi_split_path_info ^.+.php).*)$;include fastcgi.conf;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param PATH_INFO $fastcgi_path_info;}}```
-
载入多站点配置
```vim /usr/local/nginx/conf/nginx.conf# http项最后加上include /usr/local/nginx/conf/vhost/*.conf;# 去掉log_format 的注释service nginx reloadservice nginx restart```
- 在线配置 zabbix
-
zabbix.conf.php 配置
vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
```<?php// Zabbix GUI configuration file.global $DB;$DB['TYPE'] = 'MYSQL';$DB['SERVER'] = '127.0.0.1';$DB['PORT'] = '3306';$DB['DATABASE'] = 'zabbix';$DB['USER'] = 'zabbix';$DB['PASSWORD'] = '123=abc@ABC=123';// Schema name. Used for IBM DB2 and PostgreSQL.$DB['SCHEMA'] = '';$ZBX_SERVER = 'localhost';$ZBX_SERVER_PORT = '10051';$ZBX_SERVER_NAME = '';$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;```也可直接从给的链接下载
-
登陆
```# 初始账号:admin# 初始密码:zabbix
- 中文乱码解决方案
# 下载simkai.ttf字体文件,放到/usr/local/nginx/html/zabbix/fonts
# 使用sed 替换掉原来的字体
sed -i 's/DejaVuSans/simkai/g' /usr/local/nginx/html/zabbix/include/defines.inc.php
- Windows Zabbix Agent安装
-
官网下载预编译包解压即完成安装
-
配置config文件
```LogFile #日志文件目录Server #zabbix服务器IPServerActive #zabbix服务器IP和端口,默认10051,用于检测服务端活性,可以注释掉Hostname #自定义主机名,Web端创建主机时主机名称必须与之相同UnsafeUserParameters #0,1;1表示支持用户自定义keyUserParameter #用户自定义keyUserParameter=keyname[*], python key_script $1 $2 #可用zabbix_get测试key是否生效```
-
使用zabbix_agentd.exe安装成服务,注意指定config文件
zabbix_agentd.exe --install --config config_path
-
服务端使用zabbix_get工具检测客户机是否连接成功
zabbix_get -s zabbix_server_ip -p 10050 -k "system.cpu.load[all,avg1]"