linux下 zabbix 4.2 安装

 

安装环境

主机操作系统:windows 10
虚拟机:VMware15
虚拟:OSCentOS-7.6

zabbix版本:4.2

安装步骤:

添加Zabbix存储库

安装存储库配置包

rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm

 

在将运行Zabbix前端的系统中启用可选rpms的存储库

yum-config-manager --enable rhel-7-server-optional-rpms

 

安装支持MySQL的Zabbix服务

yum install zabbix-server-mysql

 

安装支持MySQL的Zabbix前端

yum install zabbix-web-mysql

 

安装MySQL5.7数据库(没有特别说明均在root用户下)

卸载mariadb包

rpm -qa |grep mariadb 

#查看当前安装的mariadb的包

 

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 

#卸载mariadb的包

 

下载并解压MySQL源码包

wget  https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

#从官网下载源码包


这里系统没有安装wget 可以用 yum 直接安装 yum install -y wget*

tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 

#解压源码包

 

mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql

#移动目录

 

创建MySQL用户并对MySQL文件进行授权

groupadd mysql 

#创建mysql用户组组

 

useradd -r -g mysql mysql 

#创建mysql用户并添加到mysql用户组中

 

chown -R mysql.mysql mysql/ 

#将mysql目录访问权限赋为myql用户

 

创建MySQL配置文件

cat >>/etc/my.cnf <<EOF #写入配置文件
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
EOF

 

初始化数据库

touch /var/log/mysqld.log 

#创建日志文件并授权

chmod 777 /var/log/mysqld.log
chown mysql.mysql /var/log/mysqld.log
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 

查看初始化密码(mysql从5.7版本起不再支持简单密码,可以在实例初始化中看到密码)

cat /var/log/mysqld.log|grep root@localhost

 

执行如下操作开启MySQL服务,并设置相应权限

mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chmod -R 777 /var/run/mysqld
chown -R mysql.mysql /var/run/mysqld
/usr/local/mysql/support-files/mysql.server start 

#启动MySQL,提示缺失lib库的话,这里需要在文件/etc/ld.so.conf中添加一行/usr/lib64/mysql/

 

修改MySQL密码(修改后重新启动数据库才能生效!)

vim /etc/my.cnf 

#修改配置文件

skip-grant-tables 
#跳过密码认证
default_password_lifetime=360 
#修改密码超时时间

 

不然修改密码之后密码会过期,会提示让你重新设置密码
You must reset your password using ALTER USER statement before executing this statement.

 

/usr/local/mysql/bin/mysql -uroot -p 

#登录MySQL(密码用刚刚从日志获取的密码)

 

mysql> use mysql 

#切换MySql数据库

 

mysql> alter user 'root'@'localhost' identified by 'wanjiaming'; 

#修改MySQL密码

mysql> flush privileges;

 

将MySQL加入环境变量

echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile 

#将MySQL二进制文件加入环境变量

 

ln -s /usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/ 

#将MySQL的启动文件软连接到MySQL的环境变量中

 

进入数据库并创建zabbix数据库以及创建授权用户

mysql> create database zabbix character set utf8 collate utf8_bin;

或者

mysql> create user 'zabbix'@'localhost' identified by 'zabbix';

 

mysql> grant all privileges on zabbix. * to 'zabbix'@'%';
或者
mysql> grant all privileges on zabbix. * to 'zabbix'@'localhost';
mysql> flush privileges;

 

编辑zabbix-server配置文件,修改以下参数为创建数据库时的信息,并重启zabbix-server

vim /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBHost=localhost
DBUser=zabbix
DBPassword=zabbix

 

创建pid文件(要与上文的配置文件路径一致)

touch /var/run/zabbix/zabbix_server.pid
chmod 777 /var/run/zabbix/zabbix_server.pid

 

启动zabbix-server
(缺少lib的话,wget https://downloads.mysql.com/archives/get/file/mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm)

systemctl enable zabbix-server
systemctl start zabbix-server

 

将初始数据导入MySQL中

zcat /usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz | mysql -uzabbix -p Dzabbix

 

安装Nginx

关掉防火墙和selinux

firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disable/g' /etc/selinux/config

 

安装依赖

yum -y install wget vim lsof lrzsz pcre-devel zlib-devel make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel libmcrypt libmcrypt-devel mcrypt mhash net-snmp-devel
yum -y install gcc bison bison-devel openssl-devel readline-devel libedit-devel sqlite-devel freetype freetype-devel libevent-devel mysql-devel

 

配置Nginx的yum仓库

cat >>/etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx.repo
baseurl=http://nginx.org/packages/centos/7/X86_64/
gpgcheck=0
enabled=1
skip_if_unavailable = 1
keepcache = 0
EOF

 

安装并启动Nginx

yum install nginx -y
systemctl start nginx
systemctl enable nginx

 

安装PHP

添加PHP用户

useradd -s /sbin/nologin php-fpm

 

安装PHP依赖库

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

 

编译安装php

wget http://mirrors.sohu.com/php/php-7.2.6.tar.gz
tar zxvf php-7.2.6.tar.gz
cd php-7.2.6
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
make && make install

 

echo $? 

#每执行完上条命令就运行一下,如果返回0,则执行成功

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

 

更改PHP配置文件

sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php/etc/php.ini
sed -i 's/; max_input_vars = 1000/max_input_vars = 10000/g' /usr/local/php/etc/php.ini

 

启动php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

 

安装zabbix-agent

yum install zabbix-agent
vim /etc/zabbix/zabbix-agentd.conf

#Server和ServerActive分别代表zabbix的被动模式和主动模式,这里都填server端的IP
最后一行是开启脚本采集数据

 

安装zabbix-web

将zabbix的php源文件拷贝到网站目录上

cp -r /usr/share/zabbix/. /usr/share/nginx/html/

 

修改nginx配置

egrep -v '(^.#|^$)' /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name http://192.168.149.128; #本机IP
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}

 

授予zabbix-web目录权限并重启nginx

chmod -R 777 /etc/zabbix/web.
chmod -R 777 /usr/share/nginx/html/zabbix
systemctl restart nginx

 

在浏览器上访问192.168.149.129/setup.php开始安装zabbix-web(默认密码 Admin/zabbix)

欢迎界面

 

环境检查

 

 

数据库配置

 

 

服务器细节

 

 

安装总览

 

 

完成安装

 

 

登陆后界面

 

 

添加sqlserver模板

(传送门 https://share.zabbix.com/databases/microsoft-sql-server/template-ms-sql-2012
导入模板:

 

 

修改配置文件,在zabbix客户端的配置文件追加内容:
UserParameter=sqldatabasename.discovery,powershell -NoProfile -ExecutionPolicy Bypass -File E:\Program Files\Zabbix Agent\scripts\SQLBaseName_To_Zabbix.ps1
路径就是你脚本放置的地方

配置邮件告警

posted @ 2020-04-14 16:00  破仔  阅读(244)  评论(0编辑  收藏  举报