LNMP+zabbix5.0编译安装

# lumia98@vip.qq.com
# zabbix5.0编译安装及脚本
# 一、安装LNMP环境(CentOS7)
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 ~]# cd nginx-1.18
[root@zabbix ~]# ./configure --prefix=/opt/app/nginx-1.18 \
--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 ~]# make -j8
[root@zabbix ~]# make install
1.1 Nginx配置
[root@zabbix ~]# more /opt/app/nginx-1.18/conf/nginx.conf|grep -v '^$\|#'

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通用版安装

# 创建MySQL目录
[root@zabbix ~]# mkdir -p /opt/app/mysql-3306/{logs,etc,socket}
[root@zabbix ~]# mkdir -p /databases/mysql-3306/{data,binlog}
# 删除my.cnf
[root@zabbix ~]# rm -rf /etc/my.cnf*
# 配置文件
[root@zabbix ~]# vim /opt/app/mysql-3306/etc/my.cnf
[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  # binlog存放位置

server_id=3306

port=3306

secure-file-priv=/tmp   #新特性:只允许mysqld导入|导出到/tmp目录下

#autocommit=0  # 自动提交事物,根据场景需要,0代表关闭,1开启

# binlog
binlog_format = MIXED  			#binlog日志格式,mysql默认采用statement,建议使用mixed

max_binlog_size = 512M

# 5.7的binlog文件保存期限
expire_logs_days = 15
# 8.0开始binlog文件保存期限
#binlog_expire_logs_seconds = 2592000

binlog_cache_size = 4m           # binlog缓存大小

max_binlog_cache_size  = 512m    # 最大binlog缓存大小

# gtid开启
gtid-mode = on						# 启用gtid类型,否则就是普通的复制架构

enforce-gtid-consistency = true      # 强制GTID的一致性

log-slave-updates = ON   			# slave更新是否记入日志

innodb_buffer_pool_size = 5734M     # 等于物理内存的70%,8192*0.7

innodb_log_files_in_group = 3        # 为了提高性能,MySQL可以循环方式将日志写到多个文件

# 默认引擎
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 ~]# vim .bash_profile 
# 改成这样
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

# 初始化MySQL
mysqld --defaults-file=/opt/app/mysql-3306/etc/my.cnf --basedir=/opt/app/mysql-3306 --datadir=/databases/mysql-3306/data --initialize-insecure  --user=mysql

# 启动请看启动脚本(SQL项目下)

3、php编译安装

[root@zabbix ~]# ./configure --prefix=/opt/app/php-7.2.6/  \
--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 ~]# make -j8
[root@zabbix ~]# make install
3.1 PHP配置,zabbix如果检测不通过,请按要求更改php.ini
# 进入etc
[root@zabbix ~]# cd /opt/app/php-7.2.6/etc/
[root@zabbix etc]# ll
-rw-r--r-- 1 root root  4481 Nov 12 09:46 php-fpm.conf   # 把php-fpm.conf.default复制,取消.default
-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        # 从源码中拷贝php.ini-production

# 进入php-fpm.d 
[root@zabbix php-fpm.d]# ll  
-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  # 把www.conf.default后,取消.default

4、zabbix编译安装

[root@zabbix ~]# cd /opt/soft/zabbix-5.0.5
[root@zabbix zabbix-5.0.5]# ./configure --prefix=/opt/app/zabbix-5.lts --enable-server --enable-agent --with-mysql=/opt/app/mysql-3306/bin/mysql_config  --with-net-snmp --with-libcurl --with-libxml2
[root@zabbix ~]# make install
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;
 # 从源码中导入数据到zabbix库(schema, data, images)
 [root@zabbix ~]# mysql -uzabbix -p zabbix < /opt/soft/zabbix-5.0.5/database/mysql/schema.sql
 [root@zabbix ~]# mysql -uzabbix -p zabbix < /opt/soft/zabbix-5.0.5/database/mysql/data.sql
 [root@zabbix ~]# mysql -uzabbix -p zabbix < /opt/soft/zabbix-5.0.5/database/mysql/images.sql
4.2 修改字体
[root@zabbix ~]# cd /opt/app/nginx-1.18/html/assets/fonts
[root@zabbix fonts]# ll
lrwxrwxrwx 1 root  root        10 Nov 12 10:07 DejaVuSans.ttf -> simkai.ttf   # 软件成DejaVuSans.ttf即可识别中文
-rw-r--r-- 1 cents cents   756072 Oct 26 19:18 DejaVuSans.ttf.bak  # 备份这个DejaVuSans.ttf 
-rw-r--r-- 1 root  root  11787328 Oct 15  2019 simkai.ttf          # 从windows的font上传常规楷体

4.3修改zabbix-server.conf
[root@zabbix ~]# more /opt/app/zabbix5-lts/etc/zabbix_server.conf|grep -v "#\|^$"
LogFile=/opt/app/zabbix5-lts/log/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
# VMware 监控选项
StartVMwareCollectors=10   # 检测VMware Esxi主机数量
VMwareFrequency=60
VMwarePerfFrequency=60
VMwareCacheSize=8M
VMwareTimeout=10

SNMPTrapperFile=/tmp/zabbix_traps.tmp
Timeout=4
AlertScriptsPath=/opt/app/zabbix5-lts/share/zabbix/alertscripts    # 脚本(Email)
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
4.4 发送邮件脚本(赋予执行权限)
[root@zabbix ~]# more /opt/app/zabbix5-lts/share/zabbix/alertscripts/mail.py 
#!/usr/bin/python
# coding:utf-8

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+"<"+mail_user+"@"+mail_postfix+">"
    me = mail_user 
    # 增加 _charset="utf-8" ,使MIMEText使用utf-8编码,避免中文乱码
    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 ~]# more /etc/init.d/start_lnmp_zabbix.sh 
#!/bin/bash
# 启动脚本

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/

# 启动mysql
 /etc/init.d/mysqld start

sleep 20

# 启动zabbix
/opt/app/zabbix5-lts/sbin/zabbix_server
/opt/app/zabbix5-lts/sbin/zabbix_agentd

# 启动php
/opt/app/php-7.2.6/sbin/php-fpm

# 启动nginx
/opt/app/nginx-1.18/sbin/nginx

# time_wait过多
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值