centos7-搭建zabbix 6.0LTS

一、下载安装包

wget http://nginx.org/download/nginx-1.18.0.tar.gz
wget https://www.php.net/distributions/php-7.3.18.tar.gz
wget http://github.com/Kitware/CMake/releases/download/v3.18.0-rc1/cmake-3.18.0-rc1.tar.gz
wget https://libzip.org/download/libzip-1.7.1.tar.gz

二、安装nginx

./configure --prefix=/usr/local/nginx   --with-http_ssl_module --with-http_realip_module  --with-http_gzip_static_module  --with-pcre   --with-http_stub_status_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module

make && make install

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

三、安装mysql

1.下载二进制mysql

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

2.相关配置

tar xf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/mysql8.0

vim /etc/profile
export PATH=$PATH:/usr/local/mysql8.0/bin

useradd mysql
mkdir -p /data/mysql/3306/data/

3.修改配置文件

vim /etc/my.cnf
[root@p0-tkhijbs-broadco-app02 usr]# cat /etc/my.cnf
[client]
socket=/data/mysql/3306/data/mysql.sock

[mysqld]
#server configuration
user=mysql
datadir=/data/mysql/3306/data
basedir=/usr/local/mysql
port=3306
socket=/data/mysql/3306/data/mysql.sock
log_timestamps=system
log_error=/data/mysql/3306/data/mysqld.err
skip_name_resolve

#Replication Framework
server_id=1
master_info_repository=TABLE
relay_log_info_repository=TABLE
log_slave_updates=ON
log_bin=mysql-bin
binlog_format=ROW

4.初始化数据库

/usr/local/mysql8.0/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure

5.启动mysql

nohup /usr/local/mysql8.0/bin/mysqld_safe --defaults-file=/etc/my.cnf &

6.初始化数据库

create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix_admin'@'%' identified with mysql_native_password by 'zabbix_pass';
grant all privileges on zabbix.* to 'zabbix_admin'@'%';
flush privileges;

四、安装php

1.安装php依赖包

yum  install libmcrypt-devel  libxml2-devel  curl-devel  libjpeg-devel  libpng-devel freetype-devel 

2.安装cmake

cd cmake-3.18.0-rc1.tar.gz

./configure --prefix=/usr/local/cmake
make && make install

ln -s /usr/local/cmake/bin/cmake  /usr/bin/

3.安装libzip

不能使用yum安装libzip,因为版本比较低

cd libzip-1.7.1
cmake .
make && make install


#添加搜索路径到配置文件
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib64
/usr/lib
/usr/lib64


#生效
ldconfig -v

4.安装php

cd php-7.3.18

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/ \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-gd \
--with-curl \
--with-openssl \
--with-mhash \
--with-gettext \
--with-xmlrpc \
--without-pear \
--enable-fpm \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-maintainer-zts \
--disable-fileinfo \
--disable-rpath 

make && make install

5.修改配置文件

cp php.ini-production /usr/local/php/php.ini

cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default ../php-fpm.conf

#修改以下内容
vim /usr/local/php/php.ini 
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai


#复制启动脚本
cp /opt/zabbix/php-7.3.18/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm 

/etc/init.d/php-fpm start
[root@p0-tkhijbs-broadco-app02 php-7.3.18]# netstat -antp |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      19257/php-fpm: mast 

6.配置nginx转发php

vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

五、安装zabbix

1.导入zabbix数据到数据库

tar xf zabbix-6.0.14.tar.gz 
cd zabbix-6.0.14/database/mysql/
mysql zabbix < schema.sql
mysql zabbix < images.sql 
mysql zabbix < data.sql 

2.安装依赖包

yum -y install mysql-devel libevent-devel libcurl-devel libxml2-devel net-snmp-devel mariadb-devel

3.安装zabbix

cd zabbix-6.0.14
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

make && make install

报错如下:

parse.c:391:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i = ctx->ops.values_num - 1; i >= 0; i --)

解决:

export CFLAGS="-std=gnu99"
然后重新./configure 在make

4.修改server配置文件

cd /usr/local/zabbix
mkdir pid
mkdir /data/zabbix_logs



[root@p0-tkhijbs-broadco-app02 ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix_admin
DBPassword=zabbix_pass
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

5.修改agent配置文件

[root@p0-tkhijbs-broadco-app02 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

6.复制编辑server脚本

这里复制的是fedora版本的启动脚本,tru64为centos的,但是还需要改,所以就没有用

cp /opt/zabbix/zabbix-6.0.14/misc/init.d/fedora/core5/zabbix_server /etc/init.d/

[root@p0-tkhijbs-broadco-app02 sbin]# vim /etc/init.d/zabbix_server 
#编辑server启动脚本
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

#增加此行
CONFIG_FILE="/usr/local/zabbix/etc/zabbix_server.conf"

start() {
        echo -n $"Starting $prog: "
        #修改此行
        daemon $ZABBIX_BIN -c $CONFIG_FILE

7.复制编辑agent脚本

cp /opt/zabbix/zabbix-6.0.14/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

[root@p0-tkhijbs-broadco-app02 ~]# vim /etc/init.d/zabbix_agentd 
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"

#增加此行
CONFIG_FILE="/usr/local/zabbix/etc/zabbix_agentd.conf"

start() {
        echo -n $"Starting $prog: "
        #修改此行
        daemon $ZABBIX_BIN -c $CONFIG_FILE

8.启动server和agent

问题: 如果使用绝对路径就启动失败,在/etc/init.d下 使用bash启动就成功

cd /etc/init.d/
bash zabbix_server start

9.复制zabbix UI

将zabbix UI 复制到nginx根目录

mkdir /usr/local/nginx/html/zabbix
cp -r /opt/zabbix/zabbix-6.0.14/ui/* /usr/local/nginx/html/zabbix/

10.在UI界面配置zabbix

http://xx.xx.xx.xx/zabbix/index.php

#默认登陆用户名和密码
Admin/zabbix

11.主机图形下文字乱码问题

1.在笔记本上 找到C:\Windows\Fonts 路径中的 "楷体 常规"  文件,文件上传后自动变成"simkai.ttf" 文件名
2.将字体文件上传到服务器上的网页根目录下的zabbix文件下的/assets/fonts目录
本文章中是: /usr/local/nginx/html/zabbix/assets/fonts

3.
mv DejaVuSans.ttf DejaVuSans.ttf_backup

#将楷体常规文件改为默认的字体
mv simkai.ttf DejaVuSans.ttf


4.刷新页面字体正常了

你可能感兴趣的:(liunx,zabbix)