0、前期准备
[root@zabbix ~]# 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
[root@zabbix ~]# useradd -s /sbin/nologin cents # 用于NGINX
[root@zabbix ~]# useradd -s /sbin/nologin mysql # 用于MySQL
[root@zabbix ~]# useradd -s /sbin/nologin zabbix # 用于zabbix
[root@zabbix ~]# mkdir /opt/app
1、Nginx编译
[ root@zabbix ~]
[ root@zabbix ~]
--user= cents \
--group= cents \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module= dynamic \
--with-http_image_filter_module= dynamic \
--with-http_geoip_module= dynamic \
--with-http_sub_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-pcre= /opt/soft/pcre-8.44 \
--with-pcre-jit \
--with-openssl= /opt/soft/openssl-1.1.1h
[ root@zabbix ~]
[ root@zabbix ~]
1.1 Nginx配置
[ root@zabbix ~]
user cents;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name ;
include fastcgi_params;
}
}
}
2、MySQL-5.7.30通用版安装
[ root@zabbix ~]
[ root@zabbix ~]
[ root@zabbix ~]
[ root@zabbix ~]
[ mysqld]
basedir= /opt/app/mysql-3306
datadir= /databases/mysql-3306/data
socket= /opt/app/mysql-3306/socket/mysql.sock
pid-file= /opt/app/mysql-3306/socket/mysql.pid
log-error= /opt/app/mysql-3306/logs/mysql-error.log
log_bin= /databases/mysql-3306/binlog/mysql-bin
server_id= 3306
port= 3306
secure-file-priv= /tmp
binlog_format = MIXED
max_binlog_size = 512M
expire_logs_days = 15
binlog_cache_size = 4m
max_binlog_cache_size = 512m
gtid-mode = on
enforce-gtid-consistency = true
log-slave-updates = ON
innodb_buffer_pool_size = 5734M
innodb_log_files_in_group = 3
default-storage-engine = InnoDB
character-set-server = utf8mb4
wait_timeout = 1800
skip_name_resolve = 1
[ client]
socket= /opt/app/mysql-3306/socket/mysql.sock
default-character-set = utf8mb4
chown -R mysql.mysql /opt/app/mysql-3306
chown -R mysql.mysql /databases/mysql-3306
[ root@zabbix ~]
PATH= $PATH : $HOME /bin:/opt/app/mysql-3306/bin:/opt/app/zabbix5-lts/sbin:/opt/app/php-7.2.6/sbin/
export PATH
TMOUT= 300
mysqld --defaults-file= /opt/app/mysql-3306/etc/my.cnf --basedir= /opt/app/mysql-3306 --datadir= /databases/mysql-3306/data --initialize-insecure --user= mysql
3、php编译安装
[ root@zabbix ~]
--with-config-file-path= /opt/app/php-7.2.6/etc \
--enable-fpm \
--with-fpm-user= cents \
--with-fpm-group= cents \
--enable-soap \
--enable-gd-native-ttf \
--enable-exi \
--enable-pdo \
--enable-mbstring \
--enable-opcache \
--enable-sockets \
--enable-pcntl \
--enable-zip \
--enable-calendar \
--enable-bcmath \
--enable-intl \
--with-pdo-mysql \
--with-mysql \
--with-mysqli \
--with-libxml-dir \
--with-pcre-dir \
--with-gd \
--with-vpx-dir \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-xpm-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--with-zlib \
--with-curl \
--with-openssl \
--with-gettext \
--with-mhash \
--with-ldap \
--with-libdir= lib64 \
--without-pear \
--disable-phar
[ root@zabbix ~]
[ root@zabbix ~]
3.1 PHP配置,zabbix如果检测不通过,请按要求更改php.ini
[ root@zabbix ~]
[ root@zabbix etc]
-rw-r--r-- 1 root root 4481 Nov 12 09:46 php-fpm.conf
-rw-r--r-- 1 root root 4483 Nov 12 09:43 php-fpm.conf.default
drwxr-xr-x 2 root root 49 Nov 12 09:45 php-fpm.d
-rw-r--r-- 1 root root 70465 Nov 12 09:53 php.ini
[ root@zabbix php-fpm.d]
-rw-r--r-- 1 root root 18877 Nov 12 09:43 www.conf.default
-rw-r--r-- 1 root root 18877 Nov 12 09:45 zabbix.conf
4、zabbix编译安装
[ root@zabbix ~]
[ root@zabbix zabbix-5.0.5]
[ root@zabbix ~]
4.1 创建数据库账号及导入数据
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> quit;
[ root@zabbix ~]
[ root@zabbix ~]
[ root@zabbix ~]
4.2 修改字体
[ root@zabbix ~]
[ root@zabbix fonts]
lrwxrwxrwx 1 root root 10 Nov 12 10:07 DejaVuSans.ttf -> simkai.ttf
-rw-r--r-- 1 cents cents 756072 Oct 26 19:18 DejaVuSans.ttf.bak
-rw-r--r-- 1 root root 11787328 Oct 15 2019 simkai.ttf
4.3修改zabbix-server.conf
[ root@zabbix ~]
LogFile= /opt/app/zabbix5-lts/log/zabbix_server.log
PidFile= /tmp/zabbix_server.pid
DBHost= localhost
DBName= zabbix
DBUser= zabbix
DBPassword= zabbix
StartVMwareCollectors= 10
VMwareFrequency= 60
VMwarePerfFrequency= 60
VMwareCacheSize= 8M
VMwareTimeout= 10
SNMPTrapperFile= /tmp/zabbix_traps.tmp
Timeout= 4
AlertScriptsPath= /opt/app/zabbix5-lts/share/zabbix/alertscripts
LogSlowQueries= 3000
StatsAllowedIP= 127.0.0.1
4.4 发送邮件脚本(赋予执行权限)
[ root@zabbix ~]
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'mail.qq.com'
mail_user = 'monitor@qq.com'
mail_pass = 'nicai'
mail_postfix = 'qq.com'
def send_mail( to_list,subject,content) :
me = mail_user
msg = MIMEText( content,_charset= "utf-8" )
msg[ 'Subject' ] = subject
msg[ 'From' ] = me
msg[ 'to' ] = to_list
try:
s = smtplib.SMTP( )
s.connect( mail_host)
s.login( mail_user,mail_pass)
s.sendmail( me,to_list,msg.as_string( ))
s.close( )
return True
except Exception as e:
print( e)
return False
if __name__ == "__main__" :
send_mail( sys.argv[ 1] , sys.argv[ 2] , sys.argv[ 3] )
python mail.py test.qq.com 主要 内容
lnmp与zabbix启动脚本
[ root@zabbix ~]
export PATH= /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/app/mysql-3306/bin:/opt/app/zabbix5-lts/sbin:/opt/app/php-7.2.6/sbin/
/etc/init.d/mysqld start
sleep 20
/opt/app/zabbix5-lts/sbin/zabbix_server
/opt/app/zabbix5-lts/sbin/zabbix_agentd
/opt/app/php-7.2.6/sbin/php-fpm
/opt/app/nginx-1.18/sbin/nginx
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle