Zabbix4.0版本

Zabbix部署之安装mysql


#安装MYSQL,包从官网下的
rpm -ivh perl-JSON-2.59-2.el7.noarch.rpm
rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
#删除之前安装的包,否则会冲突
yum remove -y mariadb-libs
rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-devel-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-5.7.27-1.el7.x86_64.rpm

#开启服务
systemctl enable mysqld
systemctl start mysqld

#保存初始密码
temppassword=`cat /var/log/mysqld.log  |grep password |awk -F ": " '{print $2}'`

#利用临时密码登陆,这种方法很好,记住
mysql -uroot -p$temppassword <> /usr/local/nginx/conf/extra/zabbix.conf

#更改目录权限 及重启各种服务
chown -R nginx:nginx /etc/zabbix/web 
chown -R nginx:nginx /var/lib/php/session
systemctl restart zabbix-server zabbix-agent 
systemctl enable zabbix-server zabbix-agent 
/usr/local/nginx/sbin/nginx -s reload
pkill php
/usr/local/php/sbin/php-fpm

#这时注意   /usr/local/nginx/conf/zabbix.conf 的配置文件中的 各种目录是否正确
#zabbix默认web目录在  /usr/share/zabbix里  ,而不在 在/usr/local/nginx/html中

Zabbix部署之安装PHP

需要5.4以上,请注意PHP版本

#安装所需组件
yum install -y pcre pcre-devel openssl openssl-devel zlib-devel \
libxml2-devel libjpeg-turbo-devel libpng-devel libcurl-devel libxslt-devel \
freetype-devel gd-devel mhash mhash-devel mcrypt libmcrypt-devel  &&

#切换到PHP目录
cd /server/download &&
cd php* &&
./configure \
--prefix=/usr/local/php \
--with-pdo-mysql \
--with-gettext=/usr/local/mysql/bin/mysql_config \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp &&
make && make install && echo $? &&

#配置文件更改相关
cp /usr/local/php/etc/{php-fpm.conf.default,php-fpm.conf} &&
cp /server/data/php-5.6.18/php.ini-production /usr/local/php/lib/php.ini &&
cp -a /usr/local/php/bin/* /usr/local/bin/ &&
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /usr/local/php/lib/php.ini &&
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /usr/local/php/lib/php.ini &&
sed -i 's/max_input_time = 60/max_input_time = 300/' /usr/local/php/lib/php.ini &&
sed -i 's/post_max_size = 8M/post_max_size = 16M/' /usr/local/php/lib/php.ini &&
ln -s /usr/local/php /server/app/php

#php-fpm开机启动
chmod +x /etc/rc.local
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

Zabbix部署之安装Nginx


#安装所需软件
yum install -y pcre pcre-devel openssl openssl-devel

##添加需要的用户
useradd -M -s /sbin/nologin nginx
./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --prefix=/usr/local/nginx/
make && make install 
ln -s /usr/local/nginx /server/app/nginx

#开启NGINX
/usr/local/nginx/sbin/nginx

#nginx 开机启动
chmod +x /etc/rc.local
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

#创建子配置文件目录
mkdir -p /usr/local/nginx/conf/extra

#写入conf/extra/phpinfo.php,为了测试
echo "
server {
listen 80;
server_name test.zabbix;
location / {
root /usr/local/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_conf;
}
}" >> /usr/local/nginx/conf/extra/phpinfo.conf

#测试index.php 是否正常链接

Zabbix部署之安装Zabbix

#zabbix 官网 安装命令
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum clean all
#agent端只装 zabbix-agent就可以
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

#agent端配置文件 /etc/zabbix/zabbix-agent.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
#Server端地址 被动模式
Server=172.16.1.61
#Server端地址 主动模式
ServerActive=172.16.1.61
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf

#server端配置文件  /etc/zabbix/zabbix-server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
#数据库地址,数据库分离改这里
DBHost=localhost
#数据库名
DBName=zabbix
#数据库用户名
DBUser=zabbix
#数据库密码
DBPassword=123
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
#监听地址
ListenIP=0.0.0.0
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

Zabbix部署之常见问题

zabbix安装配置汇总
###非常重要,server agent端一定在同一源来安装,版本最好相同,即使不相同也一定保证是同一个源,否则会出问题,被坑过

  1. PHP databases support off Fail 编译 ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
    有可能报错,取消掉--with-mysqli 选项,并在 php.ini 设置 extensions=mysqli.so

2.php.ini 设置 always_populate_RAW_post_data = -1 (在PHP.INI中,-1 为关闭 0为开启 目前看是这样)

3.zabbix Error connecting to database: No such file or directory 在php.ini 中 mysqli_default_sock = 指定mysql.sock的位置

4.zabbix 默认账号 Admin 密码 zabbix 注意,区分大小写
zabbix 更改密码,库里密码是MD5加密的

   use zabbix;
   select * from zabbix.users\G;
   echo 123 | md5sum
   update users set passwd='5fce1b3e34b520afeffb37ce08c7cd66' where userid='1';

5.web界面无法选择中文 php缺少gettext 模块 编译
cd /server/data/php/ext/gettext
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
vim /server/app/php/lib/php.ini
添加 extension=gettext.so

同时保证 /usr/share/zabbix/include/locale.XXX 文件里 简体中文 是true状态