前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zabbix自动安装篇

Zabbix自动安装篇

作者头像
菲宇
发布2022-12-21 19:42:58
3200
发布2022-12-21 19:42:58
举报
文章被收录于专栏:菲宇

shell脚本自动安装,方便大家快速上手zabbix。

autoinstall_Zabbix.sh

#!/bin/sh

#############################defined variable#############################

package_path=`pwd`

wait_second=10

mysql_pwd="root"

nginx_conf="nginx.conf" #nginxy主配置文件

nginx_zabbix_conf="zabbix.conf" #zabbix的vhost配置文件

install_report="${package_path}/install_report.log"

###################install nginx php zabbix Package by yum######################

function yum_install_zabbix()

{

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 2>>${install_report}

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 2>>${install_report}

rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm 2>>${install_report}

yum clean all 2>>${install_report}

yum makecache 2>>${install_report}

yum -y install wget gzip nginx php php-fpm php-cli php-common php-gd php-mbstring php-mcrypt php-mysql

php-pdo php-devel php-xmlrpc php-xml php-bcmath php-dba php-enchant mariadb-server zabbix-server

zabbix-get zabbix-agent zabbix-server-mysql zabbix-web-mysql 2>>${install_report}

}

###############check files exists########################################

function check_files(){

if [ -e ${install_report} ]

then

rm -fr ${install_report}

fi

}

##############config nginx#########################

function config_nginx(){

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

cp ${nginx_conf} /etc/nginx/nginx.conf

cp ${nginx_zabbix_conf} /etc/nginx/conf.d/zabbix.conf

}

################config mysql################################

function config_mysql(){

gzip -d /usr/share/doc/zabbix-server-mysql-3.4.8/create.sql.gz

systemctl start mariadb

mysqladmin -uroot password ${mysql_pwd}

mysql -uroot -p${mysql_pwd}<<EOF

create database zabbix character set utf8 collate utf8_bin;

grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";

flush privileges;

EOF

mysql -uroot -p${mysql_pwd} zabbix</usr/share/doc/zabbix-server-mysql-3.4.8/create.sql

}

######################config php#################################

function config_php(){

sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php.ini

sed -i 's/;default_charset = "UTF-8"/default_charset = "UTF-8"/g' /etc/php.ini

sed -i 's/expose_php = On/expose_php = off/g' /etc/php.ini

sed -i 's/max_execution_time = 30$/max_execution_time = 300/g' /etc/php.ini

sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini

sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php.ini

sed -i 's/^;date.timezone =/date.timezone = Asia\/Shanghai/g' /etc/php.ini

}

######################config zabbix############################

function config_zabbix(){

sed -i 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf

sed -i 's/# DBSocket=\/tmp\/mysql.sock/DBSocket=\/var\/lib\/mysql\/mysql.sock/g' /etc/zabbix/zabbix_server.conf

}

######################start service####################################

function start_service(){

systemctl start nginx.service

systemctl start php-fpm

systemctl start zabbix-server

systemctl start zabbix-agent

systemctl stop firewalld

}

#########################config service##################################

function config_service(){

config_nginx

config_mysql

config_php

config_zabbix

}

#########################Health Check##################################

check_health(){

success_info=$1

error_num=`egrep '(error|Failed)' ${install_report} |wc -l`

if [ $error_num == "0" ]

then

tput bold

echo "----------------------------------------------------------------------------------------"

echo ${success_info}

echo "----------------------------------------------------------------------------------------"

tput sgr0

else

tput bold

echo "----------------------------------------------------------------------------------------"

echo "Notice:Abnormal exit,Please Check ${install_report}!"

echo "----------------------------------------------------------------------------------------"

tput sgr0

sleep ${wait_second}

exit 2

fi

}

##########################main######################################

check_files

yum_install_zabbix

check_health "Zabbix Install Success"

config_service

start_service

check_health "Service start Success!"

nginx.conf配置文件

user zabbix;

worker_processes 8;

pid /var/run/nginx.pid;

worker_rlimit_nofile 65535;

events {

worker_connections 65535;

}

http {

include /etc/nginx/mime.types;

default_type application/octet-stream;

open_file_cache max=65535 inactive=60s;

open_file_cache_valid 80s;

open_file_cache_min_uses 1;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 2048;

proxy_buffer_size 128k;

proxy_buffers 32 32k;

proxy_busy_buffers_size 128k;

server_tokens off;

client_header_buffer_size 4k;

server_names_hash_bucket_size 64;

server_name_in_redirect off;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

log_format main '$server_name $remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '$ssl_protocol $ssl_cipher $upstream_addr $request_time $upstream_response_time';

gzip on;

gzip_disable "MSIE [1-6]\.(?!.*SV1)";

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml text/javascript;

include /etc/nginx/conf.d/*.conf;

}

zabbix.conf nginx虚拟主机配置

server{

listen 80;

server_name _;

index index.php;

root /usr/share/zabbix/;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {

expires 30d;

}

location ~* \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_buffer_size 128k;

fastcgi_buffers 4 256k;

fastcgi_busy_buffers_size 256k;

include fastcgi_params;

}

}

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-07-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档