lnmp-zabbix
lnmp-zabbix
一,php,nginx安装
安装第三方php源:
yum install epel-release.noarch -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装nginx、php7.2和所需php扩展模块
yum install nginx php72w-cli php72w-fpm php72w-common php72w-mysqlnd php72w-mbstring php72w-gd php72w-bcmath php72w-ldap php72w-xml -y
修改php配置文件:
vim /etc/php-fpm.d/www.conf
改成:
user = nginx
group = nginx
修改Nginx配置文件
# vim nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
location / {
root /html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
include fastcgi_params;
}
}
}
启动nginx,php服务
systemctl enable --now nginx
systemctl enable --now php-fpm
二 安装 zabbix-web
cd /opt
#下载源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.4.tar.gz
tar xf zabbix-5.0.4.tar.gz
#移动文件到/html目录中,与nginx配置文件中的一致
mkdir /html
cp -a zabbix-5.0.4/ui/* /html
# 给/html目录添加权限
chown -R nginx:nginx /html
访问http://10.30.xxx.xx,结果报错,查看日志
cat /var/log/nginx/error.log
PHP message: PHP Warning: session_start(): Failed to read session data: files (path: /var/lib/php/session) in /html/include/classes/core/CSession.php on line 45
PHP message: PHP Fatal error: Uncaught Exception: Cannot start session. in /html/include/classes/core/CSession.php:46
Stack trace:
#0 /html/setup.php(66): CSession::start()
#1 {main}
thrown in /html/include/classes/core/CSession.php on line 46" while reading response header from upstream, client: 10.31.23.194, server: localhost, request: "GET /setup.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "10.30.162.191"
2022/04/08 14:17:33 [error] 16523#16523: *85 open() "/html/zabbix" failed (2: No such file or directory), client: 10.31.23.194, server: localhost, request: "GET /zabbix HTTP/1.1", host: "10.30.162.191"
#可以看到是缺少目录,手动新建目录,并添加权限
mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session
先访问网页 http://ip,可以看到有fasle选项,按报划的项修改/etc/php.ini
vim /etc/php.ini
post_max_size = 8M
# 修改为
post_max_size = 16M
max_execution_time = 30
# 修改为
max_execution_time = 300
max_input_time = 60
# 修改为
max_input_time = 300
;date.timezone =
# 去掉注释,并修改为
date.timezone = Asia/Shanghai
#重启php-fpm,并刷新浏览器
systemctl restart php-fpm.service
三,创建zabbix-server
3.1 安装数据库
yum install mariadb-server.x86_64 -y
systemctl enable --now mariadb.service
mysql_secure_installation
3.2 创建zabbix数据库
mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
3,3 安装zabbix-server
rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-server-mysql -y
# 导入初始数据文件
zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz |mysql -uzabbix -p123456 zabbix
修改zabbix-server配置文件
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
# 启动zabbix-server
systemctl enable --now zabbix-server.service
现在以在网页继续操作了
1.1 zabbix 6.0 LTS CentOS7安装
1.1.1 yum 安装php+nginx
yum install epel-release -y
#安装PHP
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum list php
yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis
#启动php-fpm
systemctl enable --now php-fpm
#查看版本
php -v
#查看启动模块
php --modules
#查看安装路径
whereis php
#nginx安装
yum -y install net-tools
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
#启动nginx
systemctl enable --now nginx
#访问页面
http://IP
#修改配置文件
vim /etc/nginx/conf.d/default.conf ##修改如下图片
nginx -t
systemctl restart nginx
#添加index.php文件
vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
#访问页面: http://ip/index.php
1.1.2 安装mariadb 10.5
#添加MariaDB.repo源
vim /etc/yum.repos.d/CentOS-MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
#清除Yum的缓存并重新建立
yum clean all
yum makecache
yum list --disablerepo=\* --enablerepo=mariadb
#安装mariaDB数据库
yum -y install mariadb mariadb-libs mariadb-devel mariadb-server
mysql -uroot -p
mysql> show databases; #查看默认数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password'; (密码可以自行修改)
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> flush privileges; 更新
mysql> quit;
1.1.3 编译安装zabbix
#安装依赖
yum install gcc -y
yum install openssl -y
yum install openssl-devel -y
yum -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel openldap openldap-devel sqlite-devel oniguruma-devel
yum install -y libevent-devel net-snmp-devel
#下载压缩包,解压
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gz
tar -zvxf zabbix-6.0.0.tar.gz
#创建用户组等,授权
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
chown zabbix:zabbix /usr/lib/zabbix
cd zabbix-6.0.0
#同步时钟,设置系统时间与网络时间同步
yum -y install ntpdate
#编译安装
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make install
#导入数据库
cd zabbix-6.0.0
mysql -uzabbix -p zabbix < database/mysql/schema.sql
mysql -uzabbix -p zabbix < database/mysql/images.sql
mysql -uzabbix -p zabbix < database/mysql/data.sql
#添加数据库zabbix用户的登陆密码
vim +/DBPassword /usr/local/etc/zabbix_server.conf
DBPassword=
DBSocket=/var/lib/mysql/mysql.sock
#php修改参数
find / -name php.ini
vim /etc/php.ini
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
date.timezone = Asia/Shanghai
#启动server与agentd服务
zabbix_server
zabbix_agentd
#Zabbix 前端是 PHP 编写的,所以必须运行在支持 PHP 的 Web 服务器上。需要从ui路径下复制 PHP 文件到 Web 服务器的 HTML 文档目录,完成安装,把整个ui目录都拷贝过去并命名为zabbix
cp -r ui /usr/share/nginx/html/zabbix/
访问页面
二,zabbix ldap认证
ZABBIX 认证方式有三种,分别是Internal、LDAP和HTTP。
**注意:**实现LDAP用户账户统一认证需要AD和ZABBIX共有用户帐号并且保证LDAP设置中 Test authentication 选项中用户和密码和AD中的相同
2.1 页面配置
zabbix 配置如下图:
注释:
LDAP host:格式:ldap://ip地址
Port:默认389
Base DN: DC=ytzjsj,DC=com,也就是域名(ytzjsj.com)
Search attribute: sAMAccountName。
Bind DN:CN=Admin, OU=zabbix, DC=ytzjsj, DC=com。CN就是在DC中创建的LDAPuser用户, OU就是LDAPuser属于哪个ou,DC=ytzjsj和DC=com同上。
Bind password:xxxx
用户的密码Login:AdminUser password:在DC中创建Admin用户和密码
2.2 添加用户
**注意:**在添加新用户时,如果 ZABBIX 已经开启ldap 认证且AD上已经创建新用户的账户和密码,这时在ZABBIX上创建用户可以不填写用户的密码可直接使用AD上的密码实现认证!
2.3 ldap躺了
使用LDAP认证后,本地账号无法登录,如果LDAP认证躺了,LDAP用户也无法登录;可以通过SSH登录zabbix
操作如下:
# mysql -uroot -p
MariaDB [(none)]> show database;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
| zbxtable |
+--------------------+
MariaDB [(none)]> use zabbix
MariaDB [zabbix]> select authentication_type from config;
+---------------------+
| authentication_type |
+---------------------+
| 1 |
+---------------------+
1 row in set (0.00 sec)
MariaDB [zabbix]> update config set authentication_type = 0;
MariaDB [zabbix]> select authentication_type from config;
+---------------------+
| authentication_type |
+---------------------+
| 0 |
+---------------------+
1 row in set (0.00 sec)
成功