脚本简介
基于运维统一脚本 中,9、监控服务下的Zabbix选项 使用yum安装(yum仓库)基础软件,系统版本Centos7 使用Centos7构建lnmp环境,然后通过脚本实现zabbix5.0的安装部署
脚本注解
该脚本为了在新安装的Centos7服务器上快速完成zabbix服务的安装部署(使用方式需要自行查看)
脚本结构
base_install.sh
脚本涉及lnmp、zabbix环境的相关操作,通过函数进行封装后通过下面两个脚本调用 其中lnmp环境的编译安装时,添加了监控模块vts,可通过http://ip:port/status可访问基础面板 start_zabbix_server.sh
zabbix server 端,通过调用上边的定义的函数,实现zabbix server+zabbix agent的构架 start_zabbix_agentd.sh
zabbix agent端,通过调用上边的定义的函数,采用同类型的yum仓库安装,实现zabbix agent的构架 离线安装包(rpm),为准备,如若需要,自行下载rpm下载 ,需要先找一台可联网的机器执行当前agent的脚本(装配yum源,版本需要与源码包的版本保持一致) 如果不想安装agent,则可以执行安装yum源
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum makecache
模板中包含CentOS-Base.repo nginx.conf php.ini zabbix_server.conf文件
CentOS-Base.repo == 阿里云yum源文件 nginx.conf == 添加vts模块的nginx配置文件 php.ini == 符合zabbix使用的php-fpm zabbix_server.conf == zabbix server的主配置文件(可自行修改端口,agent服务端地址
)
注意事项
因为该脚本是从运维统一脚本(Run)拆分得来的,所有该脚本建议是测试环境使用,第一次使用的时候建议使用虚拟机或者云主机 有些场景可能会出现问题,但是新装的Centos7.5,7.6这两个系统版本本人亲测无误,其他的机器未过多的涉及 执行 start_zabbix_server.sh
脚本时
修改脚本
根据脚本内容上方写的变量,尤其是start_zabbix_agent.sh中zabbix_server_ip="192.168.1.123"这个是服务端zabbix的地址,需要根据实际情况修改
其他的变量自行根据实际情况修改,如果不想修改,则可下载 安装包,然后新建目录,把所有的安装包存放到template/zabbix
目录下,然后修改一下agent的地址即可 脚本中提示信息已存放相关安装包的下载地址
pd_template ( ) {
cd ${template}
for name in ${tar_name}
do
if [ ! -f ${name} ] ; then
info1 "${name} 不存在"
zabbix_help ${name}
continue
fi
done
info "离线安装包已提前存放在百度网盘中"
info "链接:https://pan.baidu.com/s/1CbgVKboTbFbqnEsDD-X-zw "
info "提取码:ekj7"
}
执行方式
sh start_zabbix_server.sh
sh start_zabbix_agent.sh
安装完成后,简单配置后的界面
模板配置
CentOS-Base.repo
文件内容较多,建议自行下载,然后保存到template/zabbix
目录下
curl http://mirrors.aliyun.com/repo/Centos-7.repo > template/zabbix/CentOS-Base.repo
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
vhost_traffic_status_zone;
log_format access '[$time_local] $remote_addr $status $request_time $upstream_response_time '
'$body_bytes_sent "$request" "$http_referer" $upstream_addr '
'$http_x_real_ip "$http_x_forwarded_for" $http_user_agent" $request_filename ';
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
root /usr/local/nginx/html;
location / {
index index.php index.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
access_log logs/zabbix.access.log access;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
php.ini
[ PHP ]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib. output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = - 1
disable_functions =
disable_classes =
zend. enable_gc = On
expose_php = On
max_execution_time = 300
max_input_time = 300
memory_limit = 128 M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 32 M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2 M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[ CLI Server]
cli_server. color = On
[ Date]
date. timezone = Asia/ Shanghai
[ filter]
[ iconv]
[ imap]
[ intl]
[ sqlite3]
[ Pcre]
[ Pdo]
[ Pdo_mysql]
pdo_mysql. cache_size = 2000
pdo_mysql. default_socket=
[ Phar]
[ mail function ]
SMTP = localhost
smtp_port = 25
mail. add_x_header = Off
[ ODBC ]
odbc. allow_persistent = On
odbc. check_persistent = On
odbc. max_persistent = - 1
odbc. max_links = - 1
odbc. defaultlrl = 4096
odbc. defaultbinmode = 1
[ Interbase]
ibase. allow_persistent = 1
ibase. max_persistent = - 1
ibase. max_links = - 1
ibase. timestampformat = "%Y-%m-%d %H:%M:%S"
ibase. dateformat = "%Y-%m-%d"
ibase. timeformat = "%H:%M:%S"
[ MySQLi]
mysqli. max_persistent = - 1
mysqli. allow_persistent = On
mysqli. max_links = - 1
mysqli. cache_size = 2000
mysqli. default_port = 3306
mysqli. default_socket =
mysqli. default_host =
mysqli. default_user =
mysqli. default_pw =
mysqli. reconnect = Off
[ mysqlnd]
mysqlnd. collect_statistics = On
mysqlnd. collect_memory_statistics = On
[ OCI8 ]
[ PostgreSQL]
pgsql. allow_persistent = On
pgsql. auto_reset_persistent = Off
pgsql. max_persistent = - 1
pgsql. max_links = - 1
pgsql. ignore_notice = 0
pgsql. log_notice = 0
[ bcmath]
bcmath. scale = 0
[ browscap]
[ Session]
session. save_handler = files
session. use_strict_mode = 0
session. use_cookies = 1
session. use_only_cookies = 1
session. name = PHPSESSID
session. auto_start = 0
session. cookie_lifetime = 0
session. cookie_path = /
session. cookie_domain =
session. cookie_httponly =
session. serialize_handler = php
session. gc_probability = 1
session. gc_divisor = 1000
session. gc_maxlifetime = 1440
session. referer_check =
session. cache_limiter = nocache
session. cache_expire = 180
session. use_trans_sid = 0
session. sid_length = 26
session. trans_sid_tags = "a=href,area=href,frame=src,form="
session. sid_bits_per_character = 5
[ Assertion]
zend. assertions = 1
[ COM ]
[ mbstring]
[ gd]
[ exif]
[ Tidy]
tidy. clean_output = Off
[ soap]
soap. wsdl_cache_enabled= 1
soap. wsdl_cache_dir= "/tmp"
soap. wsdl_cache_ttl= 86400
soap. wsdl_cache_limit = 5
[ sysvshm]
[ ldap]
ldap. max_links = - 1
[ dba]
[ opcache]
[ curl]
[ openssl]
zabbix_server.conf
LogFile = /tmp/zabbix_server.log
DBHost = localhost
DBName = zabbix
DBUser = zabbix
DBPassword = zabbix
DBPort = 3306
StartPollers = 10
StartTrappers = 30
CacheSize = 256M
TrendCacheSize = 256M
ValueCacheSize = 256M
Timeout = 10
LogSlowQueries = 3000
StatsAllowedIP = 127.0 .0.1
脚本内容
start_zabbix_server.sh
#!/bin/bash
basepath = $( cd `dirname $0`; pwd )
envs = "bcbx"
name = "zabbix"
dir = "/opt/images/tmp"
log_dir = "${basepath} /log"
lnmp_nginx_name = "nginx-1.19.9.tar.gz"
lnmp_nginx_dir = "nginx-1.19.9"
lnmp_nginx_vts = "nginx-module-vts-master.zip"
lnmp_vts_dir = "nginx-module-vts-master"
lnmp_php72_name = "php-7.2.29.tar.gz"
lnmp_php72_dir = "php-7.2.29"
lnmp_log = "lnmp"
lnmp_mariadb_worker = "/var/lib/mysql"
zabbix_worker = "/usr/local/zabbix"
nginx_dir = "/usr/local/nginx"
vts_dir = "/usr/local"
zabbix_server_name = "zabbix-5.0.22.tar.gz"
zabbix_server_dir = "zabbix-5.0.22"
zabbix_log = "zabbix"
agentd_conf_dir = "/etc/zabbix/zabbix_agentd.conf"
zabbix_server_ip = "106.15.78.83"
agent_hostname = "node01"
source ${basepath} /base_install.sh
template = "${basepath} /template/zabbix"
tar_name = ` echo "${lnmp_nginx_name} ${lnmp_nginx_vts} ${lnmp_php72_name} ${zabbix_server_name} nginx.conf php.ini zabbix_server.conf" `
pd_template ( ) {
cd ${template}
for name in ${tar_name}
do
if [ ! -f ${name} ] ; then
info1 "${name} 不存在"
zabbix_help ${name}
continue
fi
done
info "离线安装包已提前存放在百度网盘中"
info "链接:https://pan.baidu.com/s/1CbgVKboTbFbqnEsDD-X-zw "
info "提取码:ekj7"
}
run ( ) {
info4
mkdir_tmp_dir
info4
copy_files
log_dir_tmp = "$( cd ${ log_dir} /${ lnmp_log} ; pwd ) "
zabbix_log_tmp = "$( cd ${ log_dir} /${ zabbix_log} ; pwd ) "
lnmp_install
start_lnmp
info4
install_zabbix
}
pd_template
run
start_zabbix_agnet.sh
#!/bin/bash
basepath = $( cd `dirname $0`; pwd )
envs = "bcbx"
name = "zabbix"
dir = "/opt/images/tmp"
log_dir = "${basepath} /log"
zabbix_server_name = "zabbix-5.0.22.tar.gz"
zabbix_server_dir = "zabbix-5.0.22"
zabbix_log = "zabbix"
agentd_conf_dir = "/etc/zabbix/zabbix_agentd.conf"
zabbix_server_ip = "106.15.78.83"
agent_hostname = "node01"
source ${basepath} /base_install.sh
run ( ) {
[ -d ${log_dir} /${zabbix_log} /agentd ] || mkdir -p ${log_dir} /${zabbix_log} /agentd
zabbix_log_tmp = "$( cd ${ log_dir} /${ zabbix_log} ; pwd ) "
info4
[ $? -eq 0 ] && info2 "创建临时构建目录: 【${zabbix_log_tmp} /agentd】success"
info4
install_zabbix_agentd
}
run
base_install.sh
#!/bin/bash
info ( ) {
echo -e "\033 [35m 【` hostname ` ` date '+%Y-%m-%d %H:%M:%S' ` 】\033 [0m" "\033 [36m$1 \033 [0m "
}
info1 ( ) {
echo -e "\033 [31m 【` hostname ` ` date '+%Y-%m-%d %H:%M:%S' ` 】\033 [0m" "\033 [91m$1 \033 [0m "
}
info2 ( ) {
echo -e "\033 [32m 【` hostname ` ` date '+%Y-%m-%d %H:%M:%S' ` 】\033 [0m" "\033 [36m$1 \033 [0m "
}
info3 ( ) {
echo -e "\033 [36m----------------------------------------------------------------------------\033 [0m"
}
info4 ( ) {
echo -e "\033 [34m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\033 [0m"
}
info5 ( ) {
echo -e "\033 [91m 【` hostname ` ` date '+%Y-%m-%d %H:%M:%S' ` 】\033 [0m" "\033 [34m$1 \033 [0m "
}
mkdir_tmp_dir ( ) {
if [ -d ${dir} /${tmp_dir} ] && [ -d ${log_dir} /${lnmp_log} ] && [ -d ${log_dir} /${zabbix_log} ] ; then
rm -rf ${dir} /${tmp_dir}
rm -rf ${log_dir} /${lnmp_log}
rm -rf ${log_dir} /${zabbix_log}
info1 "删除临时构建目录: 【${dir} /${tmp_dir} 】success"
mkdir_tmp_dir
else
mkdir -p ${dir} /${tmp_dir}
mkdir -p ${log_dir} /${lnmp_log}
mkdir -p ${log_dir} /${zabbix_log}
info2 "创建临时构建目录: 【${dir} /${tmp_dir} 】success"
fi
}
copy_files ( ) {
for i in ${tar_name}
do
cp ${template} /${i} ${dir} /${tmp_dir} -r
done
info2 "源码包拷贝到指定目录下: ${dir} /${tmp_dir} "
info2 "名称是:${tar_name} "
}
add_nginx_service ( ) {
echo "[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT ${MAINPID}
[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/nginx.service
}
install_nginx ( ) {
local log_name = "nginx" rpm_install = ` rpm -qa | egrep "^make|^gcc|^unzip|^tar|^net-tools|^openssl" | wc -l`
cd ${dir} /${tmp_dir}
if [ ${rpm_install} -ne 8 ] ; then
info "安装${log_name} 基础依赖包,请等待"
yum -y install make gcc unzip openssl openssl-devel net-tools tar > ${log_dir} /${lnmp_log} /yum_install_${log_name} .log
fi
tar -xf ${dir} /${tmp_dir} /${lnmp_nginx_name} -C ${dir} /${tmp_dir}
[ $? -eq 0 ] && info "${lnmp_nginx_name} 解压成功,解压到${dir} /${tmp_dir} "
if [ -d ${vts_dir} /${lnmp_vts_dir} ] ; then
rm -rf ${vts_dir} /${lnmp_vts_dir}
unzip -d ${vts_dir} ${dir} /${tmp_dir} /${lnmp_nginx_vts} > ${log_dir} /${lnmp_log} /unzip_vts.log
else
unzip -d ${vts_dir} ${dir} /${tmp_dir} /${lnmp_nginx_vts} > ${log_dir} /${lnmp_log} /unzip_vts.log
fi
[ $? -eq 0 ] && info "${lnmp_nginx_vts} 解压成功,解压到${vts_dir} /${lnmp_vts_dir} "
if [ -d ${vts_dir} ] && [ -d ${dir} /${tmp_dir} /${lnmp_nginx_dir} ] ; then
info "源码编译安装,请等待!!!"
info1 "日志查看:${log_dir_tmp} "
cd ${dir} /${tmp_dir} /${lnmp_nginx_dir}
./configure --prefix= ${nginx_dir} --with-http_ssl_module --with-http_stub_status_module --add-module= ${vts_dir} /${lnmp_vts_dir} > ${log_dir} /${lnmp_log} /configure_nginx.log
[ $? -eq 0 ] && info2 "configure 执行成功,编译中,请等待!!!"
make > ${log_dir} /${lnmp_log} /make_${log_name} .log
[ $? -eq 0 ] && info2 "make 执行成功,编译安装中,请等待!!!"
make install > ${log_dir} /${lnmp_log} /make_install_${log_name} .log
if [ $? -eq 0 ] ; then
info2 "${lnmp_nginx_dir} install success"
cp ${dir} /${tmp_dir} /nginx.conf ${nginx_dir} /conf/nginx.conf
add_nginx_service
info2 "nginx 环境安装成功"
fi
else
info1 "${vts_dir} or${dir} /${tmp_dir} /${lnmp_nginx_dir} not found"
exit 0
fi
}
install_mariadb ( ) {
local rpm_install = ` rpm -qa | egrep "^mariadb" | wc -l`
cd ${dir} /${tmp_dir}
if [ ${rpm_install} -ne 4 ] ; then
info1 "正在安装mariadb数据库服务, 请等待!!!"
yum -y install mariadb-server mariadb > ${log_dir} /${lnmp_log} /yum_mariadb.log
info2 "mariadb install success"
elif [ ${rpm_install} -eq 4 ] ; then
info "\033 [37m mariadb already success\033 [0m"
fi
}
install_php ( ) {
local php_dir = "/usr/local/php72" log_name = "php"
local rpm_install = ` rpm -qa | egrep "^systemd-devel|^libxml2-devel|^libjpeg-devel|^libpng-devel|^libpng|^freetype-devel" | wc -l`
cd ${dir} /${tmp_dir}
if [ ${rpm_install} -ne 5 ] ; then
info "安装${log_name} 基础依赖包,请等待"
yum -y install systemd-devel libxml2-devel libjpeg-devel libcurl-dev libpng-devel libpng freetype-devel> ${log_dir} /${lnmp_log} /yum_install_${log_name} .log
elif [ ${rpm_install} -eq 3 ] ; then
info "\033 [37m PHP dependency package already success\033 [0m"
fi
tar -xf ${dir} /${tmp_dir} /${lnmp_php72_name} -C ${dir} /${tmp_dir}
[ $? -eq 0 ] && info "${lnmp_php72_name} 解压成功,解压到${dir} /${tmp_dir} /${lnmp_php72_dir} "
info "${lnmp_php72_name} 源码编译安装,请等待!!!"
info1 "日志查看:${log_dir_tmp} "
cd ${dir} /${tmp_dir} /${lnmp_php72_dir}
./configure --prefix= ${php_dir} --enable-mbstring --with-openssl --enable-ftp --with-gd --with-jpeg-dir= /usr \
--with-png-dir= /usr --with-mysqli= mysqlnd --with-pdo-mysql= mysqlnd --with-pear --enable-sockets --with-freetype-dir= /usr \
--with-zlib --with-libxml-dir= /usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd \
--with-zlib --with-iconv --enable-zip --with-freetype-dir= /usr/lib/ \
--enable-soap --enable-pcntl --enable-cli --with-curl --enable-bcmath --with-gettext\
> ${log_dir} /${lnmp_log} /configure_${log_name} .log
[ $? -eq 0 ] && info2 "configure 执行成功,编译中,日志:${log_dir_tmp} /configure_${log_name} .log ,请等待!!!"
make > ${log_dir_tmp} /make_${log_name} .log
[ $? -eq 0 ] && info2 "make 执行成功,编译安装中,日志:${log_dir_tmp} /make_${log_name} .log,请等待!!!"
make install > ${log_dir_tmp} /make_install_${log_name} .log
if [ $? -eq 0 ] ; then
info2 "${lnmp_php72_dir} 编译安装成功,日志:${log_dir_tmp} /make_install_${log_name} .log "
info3
info "修改php的配置文件"
cp ${dir} /${tmp_dir} /${lnmp_php72_dir} /sapi/fpm/php-fpm.service /usr/lib/systemd/system/php72-fpm.service
cd ${php_dir} /etc/
cp php-fpm.conf.default php-fpm.conf
cd ${php_dir} /etc/php-fpm.d/
cp www.conf.default www.conf
cp ${dir} /${tmp_dir} /php.ini ${php_dir} /lib/php.ini
sed -i '/pid/s/\;//' ${php_dir} /etc/php-fpm.conf
sed -i '/error_log/s/\;//' ${php_dir} /etc/php-fpm.conf
sed -i '/^user/s/nobody/nginx/' ${php_dir} /etc/php-fpm.d/www.conf
sed -i '/^group/s/nobody/nginx/' ${php_dir} /etc/php-fpm.d/www.conf
info2 "php72 install success"
useradd -s /sbin/nologin nginx
info2 "php 环境安装成功"
fi
}
init_zabbix ( ) {
info "开始初始化数据库,并导入数据库表结构"
mysqladmin -u root password "123456"
mysql -uroot -p123456 -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -uroot -p123456 -e 'grant all privileges on zabbix.* to zabbix@"localhost" identified by "zabbix";'
cd ${dir} /${tmp_dir} /${zabbix_server_dir} /database/mysql/
mysql -uzabbix -pzabbix zabbix < schema.sql
mysql -uzabbix -pzabbix zabbix < images.sql
mysql -uzabbix -pzabbix zabbix < data.sql
}
install_zabbix ( ) {
local zabbix_dir = "${zabbix_worker} " log_name = "zabbix"
local rpm_install = ` rpm -qa | egrep "^make|^gcc|^unzip|^tar|^net-tools|^openssl" | wc -l`
cd ${dir} /${tmp_dir}
if [ ${rpm_install} -eq 8 ] ; then
info "安装${log_name} 基础依赖包,请等待"
yum -y install mysql-devel libcurl libevent sysvinit-tools libevent-devel fping curl-devel libxml2 libxml2-devel > ${zabbix_log_tmp} /yum_zabbix.log
fi
tar -xf ${dir} /${tmp_dir} /${zabbix_server_name} -C ${dir} /${tmp_dir}
[ $? -eq 0 ] && info "${zabbix_server_name} 解压成功,解压到${dir} /${tmp_dir} "
if [ -d ${dir} /${tmp_dir} /${zabbix_server_dir} ] ; then
info "源码编译安装,请等待!!!"
info1 "日志查看:${zabbix_log_tmp} "
if [ [ ` cat /etc/passwd| awk -F: '{print $1}' | grep ^zabbix$` != zabbix ] ] ; then
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitor" zabbix
fi
cd ${dir} /${tmp_dir} /${zabbix_server_dir}
./configure --prefix= ${zabbix_dir} --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2 \
> ${log_dir} /${lnmp_log} /configure_${log_name} .log
[ $? -eq 0 ] && info2 "日志:${zabbix_log_tmp} /configure_${log_name} .log,configure 执行成功,编译中"
make > ${zabbix_log_tmp} /make_${log_name} .log
[ $? -eq 0 ] && info2 "日志:${zabbix_log_tmp} /make_${log_name} .log,make 执行成功,编译安装中 "
make install > ${zabbix_log_tmp} /make_install_${log_name} .log
if [ $? -eq 0 ] ; then
info2 "日志:${log_dir_tmp} /make_install_${log_name} .log ,${zabbix_server_dir} install success,"
info3
info "修改${log_name} 的配置文件"
cp ${dir} /${tmp_dir} /${zabbix_server_dir} /misc/init.d/fedora/core/zabbix_server /etc/init.d/
cp ${dir} /${tmp_dir} /${zabbix_server_dir} /misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp ${dir} /${tmp_dir} /zabbix_server.conf ${zabbix_dir} /etc/zabbix_server.conf
sed -i '/BASEDIR/s#/usr/local#/usr/local/zabbix#' /etc/init.d/zabbix_server
sed -i '/BASEDIR/s#/usr/local#/usr/local/zabbix#' /etc/init.d/zabbix_agentd
cd ${dir} /${tmp_dir} /${zabbix_server_dir}
cp -rp ui/* ${nginx_dir} /html
if [ [ ` cat /etc/passwd| awk -F: '{print $1}' | grep ^nginx$` != nginx ] ] ; then
useradd -s /sbin/nologin nginx
chown -R nginx:nginx ${nginx_dir} /html
fi
Active = ` systemctl status mariadb| grep "Active" | awk '{print $2}' `
if [ $Active == "active" ] ; then
info "清理之前导入的数据库库信息"
rm -rf ${lnmp_mariadb_worker} /*
systemctl restart mariadb
init_zabbix
if [ $? -eq 0 ] ; then
info "${log_name} init success"
systemctl daemon-reload
/etc/init.d/zabbix_server restart
/etc/init.d/zabbix_agentd restart
else
info1 "${log_name} init fail"
fi
else
info1 "mariadb not run"
systemctl restart mariadb
init_zabbix
fi
info2 "zabbix 环境安装成功"
fi
else
info1 "${dir} /${tmp_dir} /${zabbix_server_dir} not found"
exit 0
fi
}
sed_zabbix_agentd_conf ( ) {
sed -i "/^Server/s/127.0.0.1/${zabbix_server_ip} /" ${agentd_conf_dir}
sed -i "/^Hostname/s/Zabbix server/${agent_hostname} /" ${agentd_conf_dir}
}
install_zabbix_agentd ( ) {
local log_name = "zabbix_agentd"
info "使用yum安装agentd,加载yum仓库,请等待!!!"
local zabbix_rpm = ` rpm -qa | grep zabbix-release-5.0-1| wc -l`
if [ [ ${zabbix_rpm} -eq 0 ] ] ; then
info "加载zabbix-release——yum仓库,请等待!!!"
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm > /dev/null
yum clean all > /dev/null
if [ [ ` rpm -qa | grep zabbix-agent| wc -l` -eq 0 ] ] ; then
yum -y install zabbix-agent >> ${zabbix_log_tmp} /agentd/yum_${log_name} .log
[ $? -eq 0 ] && info2 "${log_name} 安装成功"
info "修改${agentd_conf_dir} 文件,请等待!!!"
sed_zabbix_agentd_conf
if [ $? -eq 0 ] ; then
info2 "开始启动${log_name} 服务,并设置开机自启!!!"
systemctl restart zabbix-agent
systemctl enable zabbix-agent
else
info1 "修改${agentd_conf_dir} 文件失败,请手动更改后自行重启"
fi
else
yum -y remove zabbix-release > /dev/null
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm > /dev/null
conf_set = ` grep ^Server /etc/zabbix/zabbix_agentd.conf | grep 127.0 .0.1| wc -`
if [ ${conf_set} -eq 2 ] ; then
info "修改${agentd_conf_dir} 文件,请等待!!!"
sed_zabbix_agentd_conf
if [ $? -eq 0 ] ; then
info2 "开始启动${log_name} 服务,并设置开机自启!!!"
systemctl restart zabbix-agent
systemctl enable zabbix-agent
else
info1 "修改${agentd_conf_dir} 文件失败,请手动更改后自行重启"
fi
else
info1 "${agentd_conf_dir} 文件已修改,不需要更改"
systemctl restart zabbix-agent
exit -1
fi
fi
else
yum clean all > /dev/null
if [ [ ` rpm -qa | grep zabbix-agent| wc -l` -eq 0 ] ] ; then
yum -y install zabbix-agent >> ${zabbix_log_tmp} /agentd/yum_${log_name} .log
[ $? -eq 0 ] && info2 "${log_name} 安装成功"
info "修改${agentd_conf_dir} 文件,请等待!!!"
sed_zabbix_agentd_conf
if [ $? -eq 0 ] ; then
info2 "开始启动${log_name} 服务,并设置开机自启!!!"
systemctl restart zabbix-agent
systemctl enable zabbix-agent
else
info1 "修改${agentd_conf_dir} 文件失败,请手动更改后自行重启"
fi
else
info1 "${zabbix-agent} 已安装,请勿重复安装!!!"
conf_set = ` grep ^Server /etc/zabbix/zabbix_agentd.conf | grep 127.0 .0.1| wc -l`
if [ ${conf_set} -eq 2 ] ; then
info "修改${agentd_conf_dir} 文件,请等待!!!"
sed_zabbix_agentd_conf
if [ $? -eq 0 ] ; then
info2 "开始启动${log_name} 服务,并设置开机自启!!!"
systemctl restart zabbix-agent
systemctl enable zabbix-agent
else
info1 "修改${agentd_conf_dir} 文件失败,请手动更改后自行重启"
fi
else
info1 "${agentd_conf_dir} 文件已修改,不需要更改"
systemctl restart zabbix-agent
exit -1
fi
fi
fi
}
lnmp_install ( ) {
info4
install_nginx
info4
install_mariadb
info4
install_php
}
start_lnmp ( ) {
systemctl daemon-reload
systemctl restart nginx.service
systemctl restart php72-fpm.service
systemctl restart mariadb.service
systemctl enable nginx.service
systemctl enable php72-fpm.service
systemctl enable mariadb.service
}
zabbix_help ( ) {
local tar_name = "$1 "
if [ ${tar_name} == ${lnmp_nginx_name} ] ; then
info5 "${lnmp_nginx_name} 下载地址:http://nginx.org/download/"
elif [ ${tar_name} == ${lnmp_nginx_vts} ] ; then
info5 "${lnmp_nginx_vts} 下载地址:https://github.com/vozlt/nginx-module-vts"
elif [ ${tar_name} == ${lnmp_php72_name} ] ; then
info5 "${lnmp_php72_name} 下载地址:https://www.php.net/distributions/php-7.2.29.tar.gz"
elif [ ${tar_name} == ${zabbix_server_name} ] ; then
info5 "${zabbix_server_name} 下载地址:https://www.zabbix.com/download_sources"
fi
}