1.Zabbix4.4 服务搭建

Zabbix4.4 服务搭建

搭建环境:

主机名 服务
zabbix nginx+php
192.168.10.2 mysql5.7
备注 可以分离部署,也可以在一台主机部署

zabbix server:依赖于 Mysql 端口号:10051

zabbix web:依赖于 php+web

硬件要求:内存4GB以上,处理器2核

一、安装nginx

1、解决依赖关系
[root@localhost ~]# yum -y install gcc \
yum -y install gcc \
 pcre \
 pcre-devel \
 openssl \
 openssl-devel \
 zlib-devel \
 gd \
 gd-devel \
 perl \
 perl-ExtUtils-Embed \

[root@localhost ~]# useradd -M -s /sbin/nologin  nginx			//创建nginx使用用户

2、编译安装
[root@localhost ~]# tar -zxvf nginx-1.12.0.tar.gz -C /usr/src/		
[root@localhost ~]# cd /usr/src/nginx-1.12.0/
[root@localhost nginx-1.12.0]# ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_ssl_module \
--with-pcre \
--with-cc-opt="-O3" \
--with-cpu-opt=CPU \
[root@localhost nginx-1.12.0]# make && make install			//编译安装nginx软件包

3、优化路径
[root@localhost ~]# vim /etc/profile
--PATH=$PATH:/usr/local/nginx/sbin/

4、编辑nginx启动脚本
[root@localhost ~]# vim /etc/init.d/nginx
添加:
#!/bin/bash
#### welcome to nginx  ####
# chkconfig: 2345 85 20
# description: this is nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
        start)		
           $PROG
;;
        stop)
           kill -s QUIT $(cat $PIDF)
	#killall  -9  nginx
	#rm -rf  /var/run/nginx.pid
;;
        restart)
           $0 stop
           $0 start
;;
        reload)
           kill -s HUP $(cat $PIDF)
;;
        *)
          echo "Usage: $0 {start|stop|restart|status}"
          exit 1
;;
        esac
        exit 0
        
[root@localhost ~]#chmod +x /etc/init.d/nginx        
[root@localhost ~]#chkconfig --add nginx
[root@localhost ~]#chkconfig nginx on

[root@localhost ~]#systemctl  start  nginx
[root@localhost ~]#netstat -anpt | grep nginx

5、重启nginx
[root@localhost ~]#nginx -t
[root@localhost ~]#nginx -s reload
[root@localhost ~]#nginx -s  stop 
[root@localhost ~]#nginx 

6、设置nginx开机自启动
[root@localhost ~]#vim /etc/rc.local
--/usr/local/nginx/sbin/nginx
[root@localhost ~]#chmod 755 /etc/rc.local

二、安装php

按照我所写的php步骤一步步执行,绝对没有问题,不要根据别人的文档来改我的内容

有一些软件如果没有,可以联系我shm1136265636(VX)

1、下载阿里的源,执行
[root@localhost ~]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]#  wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

2、解决依赖关系
[root@localhost ~]# yum -y install epel-release 
[root@localhost ~]# yum -y install  gcc gcc-c++ make 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 bzip2-devel gd-devel xz-devel libzip

3、安装cmake程序
[root@localhost ~]# tar zxvf cmake-2.8.6.tar.gz  -C /usr/src
[root@localhost ~]# cd /usr/src/cmake-2.8.6/
[root@localhost cmake-2.8.6]# ./configure 
[root@localhost cmake-2.8.6]# gmake
[root@localhost cmake-2.8.6]# gmake install

4、#下载libzip-1.5.2.tar.gz软件包(php依赖关系)
[root@localhost ~]# wget https://libzip.org/download/libzip-1.5.2.tar.gz
[root@localhost ~]# tar -zxf libzip-1.5.2.tar.gz
[root@localhost ~]# cd libzip-1.5.2 
[root@localhost ~]# mkdir build
[root@localhost ~]# cd build 
[root@localhost ~]# cmake ..
[root@localhost ~]# make -j4
[root@localhost ~]# make install

libzip生效
[root@localhost php-7.3.12]# vim /etc/ld.so.conf
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
#保存退出
:wq
[root@localhost php-7.3.12]# ldconfig -v # 使之生效


5、编译安装php
[root@localhost ~]# tar zxvf php-7.3.11.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/php-7.3.11/
[root@localhost ~]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --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-mbstring --with-gd  --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
[root@localhost ~]# make && make install
[root@localhost ~]# cp php.ini-production  /usr/local/php/etc/php.ini

 
6、设置优化路径
[root@localhost ~]# vim /etc/profile
--PATH=$PATH:/usr/local/php/sbin/
[root@localhost ~]# source /etc/profile

7、创建php用户并修改配置文件,php-fpm进程文件
[root@localhost ~]# useradd -M -s /sbin/nologin  php
[root@localhost ~]# cd /usr/local/php/etc/
[root@localhost etc]# vim php.ini
-- short_open_tag = On
   extension_dir = "/usr/local/php/"
[root@localhost etc]# cp  php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# cp php-fpm.d/www.conf.default  php-fpm.d/www.conf
[root@localhost etc]# vim php-fpm.conf
--pid = run/php-fpm.pid
[root@localhost etc]# vim php-fpm.d/www.conf
--user = php
  group = php
  
8、启动php-fpm
[root@localhost etc]# php-fpm
[root@localhost etc]# netstat -anpt | grep php-fpm

9、配置nginx index.php页面
[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf
--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  /scripts$fastcgi_script_name;
            	include        fastcgi.conf;
        	}
[root@localhost etc]# vim /usr/local/nginx/html/index.php

[root@localhost etc]# nginx -t 
[root@localhost etc]# nginx
[root@localhost etc]# firewall http://127.0.0.1/index.php &

3、配置Mysql数据库5.7版本

1、安装Mysql数据库
yum -y install  ncurses-base \
ncurses-devel \
ncurses-libs \
libtool-ltdl-devel libxm12 libxm12-devel zlib-devel xz-devel \
pcre pcre-devel openssl openssl-devel gd gd-devel \
perl perl-devel perl-ExtUtils-Embed \

[root@locahost ~]# tar -xvf mysql-5.7.29-el7-x86_64.tar
[root@locahost ~]# tar -zxvf mysql-5.7.29-el7-x86_64.tar.gz
[root@locahost ~]# mv mysql-5.7.29-el7-x86_64 /usr/local/mysql
[root@locahost ~]# mkdir /usr/local/mysql/data

创建mysql系统用户
[root@locahost ~]# useradd -r mysql
[root@locahost ~]# chown -R mysql:mysql  /usr/local/mysql/
初始化MySql数据库
[root@locahost ~]# /usr/local/mysql/bin/mysqld  --initialize  --user=mysql  --basedir=/usr/local/mysql/   --datadir=/usr/local/mysql/data &> /tmp/1.txt
mysql的SSL认证
[root@locahost ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data/

优化mysql工具路径
[root@locahost ~]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[root@localhost ~]# source /etc/profile
5.设置Mysql启动文件
[root@locahost ~]# cp /usr/local/mysql/support-files/mysql.server   /etc/init.d/mysqld
[root@locahost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on

mysql配置文件修改
vim  /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
default-character-set = utf8mb4
[mysqld]
user = mysql
server-id = 1
port = 3306
socket = /usr/local/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log_error = /var/log/mysqld.log
pid-file = /usr/local/mysql/data/localhost.localdomain.pid

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start mysqld

2、配置zabbix数据库,并授权zabbix用户远程访问
mysql> CREATE DATABASE zabbix;

mysql> GRANT ALL ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123.com';

3、设置index.php页面连接mysql


4、重启nginx服务,验证是否可以访问数据库
[root@localhost html]# nginx -s reload
[root@localhost html]# firefox http://192.168.10.1/index.php &

4、安装 zabbix server / zabbix web

https://blog.csdn.net/tatatatata/article/details/103242909

1、下载阿里的源,执行
[root@localhost ~]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]#  wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
2、安装依赖包 执行【联网的情况下】
[root@localhost ~]# yum -y install net-snmp net-snmp-devel libxml2 libxml2-devel libcurl-devel libevent libevent libevent-devel curl curl-devel mysql-devel snmp perl-DBI php-xml php-bcmath php-mbstring php-ldap php-xml rpc  php php-mysql php-common php-gd php-odbc php-pear gcc* net-snmp mariadb
[root@localhost ~]# yum -y install net-snmap-devel libcurl-devel curl-devel libxml2-devel OpenIPMI-devel unixODBC-devel


3、先创建 zabbix用户,开始编译安装
[root@localhost ~]# groupadd zabbix
[root@localhost ~]# useradd -g zabbix -s /sbin/nologin zabbix
[root@localhost ~]# cd /usr/src && tar -zxvf zabbix-4.4.0.tar.gz
[root@localhost src]# cd zabbix-4.4.0/
[root@localhost zabbix-4.4.0]# ./configure \
--prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-mysql=mysqlnd \
--with-openipmi \
--with-unixodbc \
[root@localhost zabbix-4.4.0]# make && make install 

4、选项说明
--prefix指定安装目录
--enable-server安装zabbix server
--enable-agent安装zabbix agent
--with-mysql用mysql来存储

5、设置环境变量
[root@localhost zabbix-4.4.0]# cd /usr/local/zabbix/
[root@localhost zabbix]# ls
bin  etc  lib  sbin  share
[root@localhost zabbix]# vim  /etc/profile
--export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin/
[root@localhost zabbix]# source  /etc/profile
[root@localhost zabbix-4.4.0]# zabbix_server --version

2、配置 Mysql 数据库 (数据初始化)

1、授权用户访问zabbix数据库
MySql - 192.168.10.19:
[root@localhost mysql-5.6.33]# mysql -u root -p123.com
mysql> CREATE DATABASE zabbix;
mysql> GRANT ALL ON zabbix.* TO  'zabbix'@'192.168.10.%' IDENTIFIED BY '123.com' ;

2、在zabbix服务器连接Mysql初始化数据
Zabbix - 192.168.10.3
[root@localhost ~]# mysql -h192.168.10.19 -uzabbix -p123.com
mysql> set names utf8;
mysql> use zabbix;
mysql> source /usr/src/zabbix-4.4.0/database/mysql/schema.sql;
mysql> source /usr/src/zabbix-4.4.0/database/mysql/data.sql;
mysql> source /usr/src/zabbix-4.4.0/database/mysql/images.sql;

3、修改zabbix配置文件

1、修改zabbix server的配置文件:
[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=192.168.10.19
DBName=zabbix
DBUser=zabbix
DBPassword=123.com
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts		#邮件告警,微信告警脚本
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000 

2、启动 zabbix 
[root@localhost ~]# chown zabbix -R /usr/local/zabbix/
[root@localhost zabbix]# zabbix_server
[root@localhost zabbix]# netstat -anpt | grep zabbix

4、zabbix-web 安装启动

1、复制zabbix-web动态页面
[root@localhost html]# mkdir /usr/local/nginx/html/zabbix
[root@localhost html]# \cp -a /usr/src/zabbix-4.4.0/frontends/php/* /usr/local/nginx/html/zabbix/
[root@localhost zabbix]# firefox http://192.168.10.1/zabbix & 
修改下图中错误的 Fall

1.Zabbix4.4 服务搭建_第1张图片

[root@localhost ~]# cd /usr/local/php/etc
[root@localhost etc]# vim php.ini
--	post_max_size = 32M
	max_execution_time = 350
	max_input_time = 350
  	date.timezone = Asia/Shanghai
[root@localhost etc]# killall php-fpm
[root@localhost etc]# php-fpm
[root@localhost etc]# netstat -anpt | grep php-fpm
[root@localhost etc]# firefox http://192.168.10.1/zabbix

1.Zabbix4.4 服务搭建_第2张图片

默认下一步到下列图片,需要手动下载,并生成配置文件

1.Zabbix4.4 服务搭建_第3张图片

#点击 1.Download the configuration file 下载此文件
#在 /usr/local/nginx/html/zabbix/conf/ 目录下生成 zabbix.conf.php文件

重新访问 http://192.168.10.1/zabbix 页面,进行登录

登录zabbix
默认用户名和密码:Admin  zabbix
(在web界面右上角头像,点击后,设置 chinese_cn 语言)
修改 guest用户访问权限
修改 admin管理员用户密码

解决zabbix汉化后乱码问题

解决zabbix部分乱码问题
将C:\Windows\Fonts下的 微软雅黑字体上传至zabbix服务器
#zabbix字体的放置目录:/usr/local/nginx/html/zabbix/fonts/
#zabbix网页的字体配置修改/usr/local/nginx/html/zabbix/include/defines.inc.php
默认是DejaVuSans字体,改成msyh微软雅黑字体
验证中文是否正常

你可能感兴趣的:(zabbix)