zabbix server 一键安装脚本

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: !/usr/bin/pythonimport osimport socketdef sto():os.system('sed -i "s/SELINUX=enabled/SELINUX=disabled/g" /etc/selinux/config')os.

!/usr/bin/python

import os
import socket

def sto():
os.system('sed -i "s/SELINUX=enabled/SELINUX=disabled/g" /etc/selinux/config')
os.system('getenforce 0')
os.system('service iptables stop')
os.system('service firewalld stop')
os.system('yum install -y epel-release')
def yumsub():
os.system("yum -y install wget libtool expat-devel pcre-devel zlib-devel openssl openssl-devel pcre")
os.system("yum -y install gcc gcc-c++ glibc automake autoconf libtool make")
os.system("yum -y install libmcrypt-devel mhash-devel libxslt-devel")
os.system("yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel")
os.system("yum -y install zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel")
os.system("yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel")
os.system("yum -y install krb5 krb5-devel libidn libidn-devel openssl openssl-devel")
def inspcre():
os.chdir('/data')
os.system('wget http://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz -O pcre-8.39.tar.gz --no-check-certificate')
os.system('tar -zxvf pcre-8.39.tar.gz')
os.chdir('/data/pcre-8.39')
os.system('./configure')
os.system('make&&make install')
def inszlib():
os.chdir('/data')
os.system('wget http://zlib.net/zlib-1.2.11.tar.gz')
os.system('tar -zxvf zlib-1.2.11.tar.gz')
os.chdir('/data/zlib-1.2.11')
os.system('./configure&&make&&make install')
def insopenssl():
os.chdir('/data')
os.system('wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz')
os.system('tar -zxvf openssl-1.1.0b.tar.gz')
os.chdir('/data/openssl-1.1.0b')
os.system('./config&&make&&make install')
def insnginx():
os.chdir('/data')
os.system('wget http://nginx.org/download/nginx-1.10.2.tar.gz')
os.system('tar -zxvf nginx-1.10.2.tar.gz')
os.chdir('/data/nginx-1.10.2')
os.system('groupadd -r nginx')
os.system('useradd -r -g nginx nginx')
os.system("""
./configure
--prefix=/data/nginx
--sbin-path=/data/nginx/sbin/nginx
--conf-path=/data/nginx/nginx.conf
--pid-path=/data/nginx/nginx.pid
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_flv_module
--with-http_mp4_module
--with-http_stub_status_module
--with-http_gzip_static_module
--http-client-body-temp-path=/var/tmp/nginx/client/
--http-proxy-temp-path=/var/tmp/nginx/proxy/
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
--with-pcre=/data/pcre-8.39
--with-zlib=/data/zlib-1.2.11
--with-openssl=/data/openssl-1.1.0b
""")
os.system('make && make install')
os.system('mkdir -p /var/tmp/nginx/client')
os.system('/data/nginx/sbin/nginx')
def insmysql():
os.chdir('/data')
os.system('wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz')
os.system('tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz')
os.system('mkdir -p /data/mysql/logs /data/mysql/data')
os.system('mv mysql-5.6.40-linux-glibc2.12-x86_64/* /data/mysql/')
os.system('useradd -s /sbin/nologin -M mysql')
os.system('chown -R mysql.mysql /data/mysql/')
os.system('chown -R mysql.mysql /var/lib/mysql/')
os.chdir('/data/mysql')
with open(r'/etc/my.cnf','w') as fileobject:
fileobject.write("""
[mysqld]
\nbasedir = /data/mysql
\ndatadir = /data/mysql/data
\ntmpdir = /data/mysql
\nsocket = /data/mysql/mysql.sock
\nskip-external-locking
\nskip-name-resolve
\nlower_case_table_names=1
\nauto_increment_offset = 1
\nauto_increment_increment = 2
\n#server-id
\n########## binlog ##########
\nlog_bin = /data/mysql/logs/mysql-bin
\nbinlog_format = row
\nbinlog_cache_size = 2M
\nexpire-logs-days = 7
\n########## error log ##########
\nlog_error = /data/mysql/logs/mysql-error.log
\n########## slow log ##########
\nslow_query_log = 1
\nslow_query_log_file = /data/mysql/logs/mysql-slow.log
\nlong_query_time = 5
\n########## per_thread_buffers ##########
\nmax_connections = 1024
\nmax_connect_errors = 1000
\nkey_buffer_size = 64M
\nmax_allowed_packet = 128M
\ntable_open_cache = 6144
\ntable_definition_cache = 4096
\nsort_buffer_size = 512K
\nread_buffer_size = 512K
\njoin_buffer_size = 512K
\ntmp_table_size = 64M
\nmax_heap_table_size = 64M
\nthread_cache_size = 64
\nthread_concurrency = 32
\nbulk_insert_buffer_size = 64M
\n########innodb########
\ninnodb_buffer_pool_size = 1G
\ninnodb_log_file_size = 500M
\ninnodb_log_buffer_size = 64M
\ninnodb_flush_log_at_trx_commit = 2
\ninnodb_file_per_table = 1
\ninnodb_file_io_threads = 4
\ninnodb_flush_method = O_DIRECT
\ninnodb_thread_concurrency = 0
\ninnodb_additional_mem_pool_size = 16M
\n[mysqlhotcopy]
\ninteractive-timeout
\n[mysqld_safe]
\nopen_files_limit = 65535
\n[client]
\nsocket = /data/mysql/mysql.sock
\n[mysql]
\nsocket = /data/mysql/mysql.sock
""")
os.chdir('/data/mysql')
os.system('./scripts/mysql_install_db --basedir=/data/mysql/ --datadir=/data/mysql/data/ --user=mysql')
os.system('sed -i "s#/data/mysql#/data/mysql#g" /data/mysql/bin/mysqld_safe')
os.system('/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql &')
os.system('cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld')
os.system('/data/mysql/bin/mysqladmin -h 127.0.0.1 -u root password mysqldb')
def insphp():
os.chdir('/data')
os.system('yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel gd-devel curl-devel openssl-devel libxslt-devel* php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel')
os.system('wget http://au1.php.net/get/php-5.6.30.tar.gz/from/this/mirror -O php-5.6.30.tar.gz')
os.system('tar zxvf php-5.6.30.tar.gz')
os.chdir('/data/php-5.6.30')
os.system("""
./configure
--prefix=/data/php
--with-config-file-path=/data/php/etc
--enable-inline-optimization
--enable-fpm
--with-mysql=/data/mysql
--with-mysqli=/data/mysql/bin/mysql_config
--with-pdo-mysql=/data/mysql
--with-gettext
--enable-mbstring
--with-iconv=/data/libiconv
--with-mcrypt
--with-mhash
--enable-bcmath
--enable-soap
--with-libxml-dir
--enable-sockets
--with-curl
--with-zlib
--enable-zip
--with-bz2
--with-gd
--with-freetype-dir
--with-jpeg-dir
--with-iconv
--with-png-dir
""")
os.system('make&&make install')
os.system('cp php.ini-production /data/php/etc/php.ini')
def inszabbix():
os.chdir('/data')
os.system('wget http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.1/zabbix-3.2.1.tar.gz')
os.system('yum install -y net-snmp-devel')
os.system('tar zxvf zabbix-3.2.1.tar.gz')
os.chdir('/data/zabbix-3.2.1')
os.system('./configure --prefix=/data/zabbix --enable-server --enable-agent --with-mysql=/data/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2&&make&&make install')
def mysqlzabbix():
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "create database zabbix"')
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "grant all on zabbix.* to 'zabbixuser'@'%' identified by 'mysqldb'"')
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "flush privileges"')
os.system('sed -i "1i\use zabbix;" /data/zabbix-3.2.1/database/mysql/schema.sql')
os.system('sed -i "1i\use zabbix;" /data/zabbix-3.2.1/database/mysql/images.sql')
os.system('sed -i "1i\use zabbix;" /data/zabbix-3.2.1/database/mysql/data.sql')
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "source /data/zabbix-3.2.1/database/mysql/schema.sql"')
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "source /data/zabbix-3.2.1/database/mysql/images.sql"')
os.system('/data/mysql/bin/mysql -h127.0.0.1 -uroot -pmysqldb -e "source /data/zabbix-3.2.1/database/mysql/data.sql"')
def zabbixconf():
os.system('echo "LogFile=/data/zabbix/logs/zabbix_server.log">>/data/zabbix/etc/zabbix_server.conf')
os.system('echo "DBHost=127.0.0.1">>/data/zabbix/etc/zabbix_server.conf')
os.system('echo "DBName=zabbix">>/data/zabbix/etc/zabbix_server.conf')
os.system('echo "DBUser=zabbixuser">>/data/zabbix/etc/zabbix_server.conf')
os.system('echo "DBPassword=mysqldb">>/data/zabbix/etc/zabbix_server.conf')
os.system('echo "LogSlowQueries=3000">>/data/zabbix/etc/zabbix_server.conf')
os.system('cp /data/zabbix-3.2.1/misc/init.d/fedora/core/* /etc/init.d/')
os.system('chmod +x /etc/init.d/zabbix_server')
os.system('chmod +x /etc/init.d/zabbix_agentd')
os.system('sed -i "s#BASEDIR=/data#BASEDIR=/data/zabbix#g" /etc/init.d/zabbix_agentd')
os.system('sed -i "s#BASEDIR=/data#BASEDIR=/data/zabbix#g" /etc/init.d/zabbix_server')
os.system('useradd -s /sbin/nologin -M zabbix')
os.system('mkdir /data/zabbix/logs')
os.system('chown -R zabbix.zabbix /data/zabbix/')
os.system('/etc/init.d/zabbix_agentd start')
os.system('/etc/init.d/zabbix_server start')
os.system('sed -i "s#;date.timezone =#date.timezone = Asia/Shanghai#g" /data/php/etc/php.ini')
os.system('sed -i "s#post_max_size = 8M#post_max_size = 16M#g" /data/php/etc/php.ini')
os.system('sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /data/php/etc/php.ini')
os.system('sed -i "s#max_input_time = 60#max_input_time = 300#g" /data/php/etc/php.ini')
os.system('sed -i "s#;always_populate_raw_post_data = -1#always_populate_raw_post_data = -1#g" /data/php/etc/php.ini')
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
def nginx():
os.system('mkdir -p /var/log/nginx')
os.system('touch /var/log/nginx/error.log')
with open(r'/data/nginx/nginx.conf','w') as fileobject:
fileobject.write("""
\nuser www www;
\npid /data/nginx/nginx.pid;
\nworker_processes auto;
\nworker_rlimit_nofile 100000;
\nevents
\n {
\n use epoll;
\n multi_accept on;
\n worker_connections 51200;
\n }
\nhttp {
\nserver_tokens off;
\nsendfile on;
\ntcp_nopush on;
\ntcp_nodelay on;
\naccess_log off;
\nerror_log /var/log/nginx/error.log crit;
\nkeepalive_timeout 10;
\nclient_header_timeout 10;
\nclient_body_timeout 10;
\nreset_timedout_connection on;
\nsend_timeout 10;
\nlimit_conn_zone binary_remote_addr zone=addr:5m; \nlimit_conn addr 100; \ninclude /data/nginx/mime.types; \ndefault_type text/html; \ncharset UTF-8; \ngzip on; \ngzip_disable "msie6"; \ngzip_proxied any; \ngzip_min_length 1000; \ngzip_comp_level 6; \ngzip_disable <93>MSIE [1-6].(?!.*SV1)<94>; \nopen_file_cache max=100000 inactive=20s; \nopen_file_cache_valid 30s; \nopen_file_cache_min_uses 2; \nopen_file_cache_errors on; \ninclude /data/nginx/conf.d/*.conf; \nserver \n{ \n listen 9001; \n location ~ /nginx_status { \n stub_status on; \n access_log off; \n allow all; \n } \n} \nserver \n{ \n listen 80; \n server_name zabbix.com; """+"server_name "+get_host_ip()+";"+""" \n root /data/nginx/html; \n location /zabbix{ \n index index.php index.html index.htm; \n } \n location ~ \.php {
\n include fastcgi_params;
\n fastcgi_pass 127.0.0.1:9000;
\n fastcgi_index index.php;
\n fastcgi_param SCRIPT_FILENAME /data/nginx/htmlfastcgi_script_name; \n } \n } \n } """) def run(): os.chdir('/data/php/etc') os.system('cp php-fpm.conf.default php-fpm.conf') os.chdir('/data/zabbix-3.2.1') os.system('cp -ra frontends/php/ /data/nginx/html/zabbix') os.system('useradd -s /sbin/nologin -M www') os.system('chown www.www /var/log/nginx/error.log') os.system('chown -R www.www /data/nginx/html/zabbix') os.system('touch /data/nginx/html/zabbix/conf/zabbix.conf.php') with open(r'/data/nginx/html/zabbix/conf/zabbix.conf.php','w') as fileobject: fileobject.write(""" \n<?php \n// Zabbix GUI configuration file. \nglobalDB;
\n
\nDB['TYPE'] = 'MYSQL'; \nDB['SERVER'] = '127.0.0.1';
\nDB['PORT'] = '0'; \nDB['DATABASE'] = 'zabbix';
\nDB['USER'] = 'zabbixuser'; \nDB['PASSWORD'] = 'mysqldb';
\n
\n// Schema name. Used for IBM DB2 and PostgreSQL.
\nDB['SCHEMA'] = ''; \n \nZBX_SERVER = 'localhost';
\nZBX_SERVER_PORT = '10051'; \nZBX_SERVER_NAME = 'zabbixserver';
\n
\n$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
""")
os.system('chown -R zabbix.zabbix /data/nginx/html/zabbix/conf')
os.system('/data/php/sbin/php-fpm')
os.system('/data/nginx/sbin/nginx')
os.chdir('/data/nginx/sbin')
os.system('./nginx -s reload')
os.chdir('/data/nginx/html/')
os.system('wget https://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.linux2_6_23.amd64.tar.gz')
os.system('wget https://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.win.zip')
sto()
yumsub()
inspcre()
inszlib()
insopenssl()
insnginx()
insmysql()
insphp()
inszabbix()
mysqlzabbix()
zabbixconf()
nginx()
run()

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
监控 前端开发 数据库连接
Zabbix 5.0 LTS的web界面安装及修改zabbix web管理员的默认密码
这篇文章是关于如何安装Zabbix 5.0 LTS的web界面以及如何修改Zabbix web管理员默认密码的教程。
187 1
|
4月前
|
监控 关系型数据库 MySQL
如何在 Ubuntu 16.04 上安装和配置 Zabbix 以安全监控远程服务器
如何在 Ubuntu 16.04 上安装和配置 Zabbix 以安全监控远程服务器
41 0
|
5月前
|
域名解析 缓存 监控
安装zabbix时报错Could not resolve host: mirrors.huaweicloud.com;Unknown error解决办法
安装zabbix时报错Could not resolve host: mirrors.huaweicloud.com;Unknown error解决办法
|
5月前
|
监控 关系型数据库 应用服务中间件
Linux zabbix监控 软件的安装
Linux zabbix监控 软件的安装
|
7月前
|
监控 关系型数据库 MySQL
红帽 9 zabbix 安装流程
Zabbix是一个监控软件,用于确保企业服务架构的安全运行,具备灵活的告警机制和分布式监控能力。它由Server、Web页面、数据库、Proxy和Agent五个组件组成。工作流程中,Agent在目标设备上收集数据,Server存储和处理数据,Web页面提供监控信息。Zabbix支持主动和被动两种数据收集模式。在Redhat 9.2环境下,安装包括关闭防火墙、设置SELinux、安装MySQL、创建Zabbix数据库和用户、安装Zabbix RPM包及配置服务。完成安装后,通过Web界面使用Admin账号和预设密码zabbix登录。
186 2
|
7月前
|
监控 网络协议 Unix
centos7 zabbix安装客户端agent -配置监控远程主机 在需要监控的电脑上安装
centos7 zabbix安装客户端agent -配置监控远程主机 在需要监控的电脑上安装
206 0
|
7月前
|
监控 关系型数据库 MySQL
centos7 zabbix-service 源码编译 安装部署服务端 和 常见安装错误
centos7 zabbix-service 源码编译 安装部署服务端 和 常见安装错误
108 0
|
20天前
|
监控 Java Shell
监控堆外第三方监控工具Zabbix
监控堆外第三方监控工具Zabbix
32 5
|
7月前
|
存储 SQL 监控
修改Zabbix源码实现监控数据双写,满足业务需求!
虽然对接Elasticsearch后有诸多好处,但是它不往数据库写历史数据了,同时还不再计算趋势数据了。有这么一个场景...
修改Zabbix源码实现监控数据双写,满足业务需求!
|
17天前
|
监控 安全 前端开发
使用 Zabbix 监控堆外应用
使用 Zabbix 监控堆外应用
37 9

推荐镜像

更多