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设置
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.gz
cd nginx-1.9.9
./configure --prefix=/usr/local/nginx/ --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
make
make 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.conf
nginxd=/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=0
prog="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 ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
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 -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
```
```
cp nginx.sh /etc/rc.d/init.d/nginx
chmod 755 /etc/rc.d/init.d/nginx
chkconfig 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 -y
yum 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/phpize
cp -frp /usr/lib64/libldap* /usr/lib
./configure --with-ldap --with-php-config=/usr/local/php/bin/php-config
make
make install
# php.ini添加ldap模块
vim /usr/local/php/etc/php.ini
extension = ldap.so
service php-fpm reload
service php-fpm restart
```
依赖软件
```
yum install libevent-devel
yum 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 on
chkconfig zabbix_agentd on
```
创建用户
```
groupadd zabbix
useradd zabbix -g zabbix -s /bin/false # /bin/false 账号禁止用于登陆
```
添加zabbix服务对应的端口
```
# vim /etc/services 末尾添加以下内容:
# 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
```
创建zabbix数据库
create database zabbix DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
创建zabbix用户
```
# 允许本地 IP 访问 localhost, 127.0.0.1
use 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=123
use 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.sql
mysql -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/mysql
ln -s libmysqlclient.so.16.0.0 libmysqlclient.so
ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so
```
配置站点目录
```
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 reload
service nginx restart
```
数据库配置
zabbix 服务端详细信息
zabbix.conf.php 配置
vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
```
登陆
```
# 初始账号:
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
官网下载预编译包解压即完成安装
配置config文件
```
LogFile #日志文件目录
Server #zabbix服务器IP
ServerActive #zabbix服务器IP和端口,默认10051,用于检测服务端活性,可以注释掉
Hostname #自定义主机名,Web端创建主机时主机名称必须与之相同
UnsafeUserParameters #0,1;1表示支持用户自定义key
UserParameter #用户自定义key
UserParameter=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]"