首页 > 其他分享 >zabbix4.0.5自动安装脚本

zabbix4.0.5自动安装脚本

时间:2022-09-02 00:55:06浏览次数:56  
标签:脚本 deploy -- nginx zabbix mysql home zabbix4.0 安装

拿包请在下方留言  拿包请在下方留言

环境:centos7

服务器可以上外网即可

 

#自动化部署zabbix脚本
#!/bin/bash
#版本详情
#1. zabbix-4.0.5.tar.gz
#2. nginx-1.16.1.tar.gz
#3. mysql-5.6.17.tar.gz
#4.
#创建软件启动对应用户
useradd -s /sbin/nologin -M zabbix
useradd -s /sbin/nologin -M nginx
useradd -s /sbin/nologin -M mysql
#---------部署mysql------------------------
#创建mysql相关存放目录


mkdir -p /home/deploy/mysql/data
mkdir -p /home/deploy/mysql/logs/error-log
mkdir -p /home/deploy/mysql/logs/slow-log
mkdir -p /home/deploy/mysql/logs/bin-log
mkdir -p /home/deploy/mysql/temp
mkdir -p /home/deploy/mysql/sock
mkdir -p /home/deploy/mysql/pid
#清理mysql环境

rpm -e mariadb-libs --nodeps
rpm -e mariadb-devel --nodeps
rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
rm -rf /etc/init.d/mysql
rm -rf /etc/init.d/zabbix_server
rm -rf /etc/init.d/zabbix_agentd
rm -rf /usr/lib/systemd/system/nginx.service


#相关依赖进行安装
yum -y install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-devel autoconf automake
sleep 5
#解压安装包
tar -zxvf mysql-5.6.17.tar.gz
#编译
cd ./mysql-5.6.17
cmake -DCMAKE_INSTALL_PREFIX=/home/deploy/mysql -DMYSQL_UNIX_ADDR=/home/deploy/mysql/sock/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/deploy/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=20001 -DENABLE_DOWNLOADS=1
#sleep 5
#编译成功后执行安装命令
make -j 8
make install
chown -R mysql:mysql /home/deploy/mysql
cd /home/deploy/mysql
#初始化mysql
scripts/mysql_install_db --user=mysql --basedir=/home/deploy/mysql --datadir=/home/deploy/mysql/data
#mysql添加到系统服务
cp /home/deploy/mysql/support-files/mysql.server /etc/init.d/mysql
#使用安装包中的my.cnf
cp -r /home/deploy/my.cnf /etc
chown mysql:mysql /etc/my.cnf
#启动mysql进程
/etc/init.d/mysql restart
#mysql开机启动
chkconfig mysql on
#检查mysql是否启动
ss -antp |grep 20001
sleep 5
echo "------------------"
echo "mysql部署成功"
echo "mysql部署成功"
echo "mysql部署成功"
echo "------------------"
#设置环境变量
cp -r /home/deploy/mysql/bin/mysql /usr/local/sbin
cp -r /home/deploy/mysql/bin/mysqladmin /usr/local/sbin
#设置root登陆密码
mysqladmin -u root password 'Oq1dQ@mIYU0IfasWi'
echo "密码:Oq1dQ@mIYU0IfasWi"
echo "密码:Oq1dQ@mIYU0IfasWi"

#登陆db创建zabbix库
mysql -uroot -pOq1dQ@mIYU0IfasWi -e "create database zabbix character set utf8;"
mysql -uroot -pOq1dQ@mIYU0IfasWi -e "grant all on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uroot -pOq1dQ@mIYU0IfasWi -e "flush privileges;"
sleep 10

#---------------------------------------------------
#---------------部署zabbix-server-------------------
#安装相关依赖
yum install unixODBC-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel -y

cd /home/deploy
#解压zabbix-server安装包
tar -zxvf zabbix-4.0.5.tar.gz
#休息5秒
sleep 5
echo "解压成功zabbix解压成功"

#初始化zabbix库
sleep 5
echo '将要初始化zabbix库啦,请查看相关db.sql'
cd /home/deploy/zabbix-4.0.5/database/mysql
pwd
sleep 5
mysql -uzabbix -pzabbix -h localhost zabbix < schema.sql
sleep 2
mysql -uzabbix -pzabbix -h localhost zabbix < images.sql
sleep 2
mysql -uzabbix -pzabbix -h localhost zabbix < data.sql
sleep 2
ldconfig -v
#编译zabbix,注意mysql目录
cd /home/deploy/zabbix-4.0.5
./configure --prefix=/home/deploy/zabbix --enable-server --enable-agent --with-mysql=/home/deploy/mysql/bin/mysql_config --enable-ipv6 --with-netsnmp --with-libcurl --with-libxml2
sleep 15
#编译成功后执行安装命令
make install
sleep 10
chown -R zabbix:zabbix /home/deploy/zabbix
#修改zabbix-server相关配置
sed -i 's/# DBPassword=/DBPassword=zabbix/g' /home/deploy/zabbix/etc/zabbix_server.conf
sed -i '/# DBSocket=/a DBSocket=/home/deploy/mysql/sock/mysql.sock' /home/deploy/zabbix/etc/zabbix_server.conf
sed -i '/# StartDiscoverers=1/a StartDiscoverers=50' /home/deploy/zabbix/etc/zabbix_server.conf
sed -i '/# UnavailableDelay=60/a UnavailableDelay=300' /home/deploy/zabbix/etc/zabbix_server.conf
sed -i '/# DBPort=/a DBPort=20001' /home/deploy/zabbix/etc/zabbix_server.conf
#以后进行优化,暂时不影响
# PidFile=/tmp/zabbix_server.pid
#LogFile=/tmp/zabbix/log/zabbix_server.log

sleep 5
#copy命令到系统命令存放处(方便调用)
mkdir -p /home/deploy/zabbix_web/web
cp -R /home/deploy/zabbix-4.0.5/frontends/php/* /home/deploy/zabbix_web/web
chown -R nginx:nginx /home/deploy/zabbix_web/web

#启动zabbix
/home/deploy/zabbix/sbin/zabbix_server
#检查zabbix是否启动成功
netstat -nlutp |grep zabbix_server
sleep 5
echo "---------------------------"
echo "部署成功zabbix-server部署成功"
echo "部署成功zabbix-server部署成功"
echo "部署成功zabbix-server部署成功"
echo "---------------------------"

#zabbix开机自启
#echo /home/deploy/zabbix/sbin/zabbix_server >> /etc/rc.local
cp /home/deploy/zabbix-4.0.5/misc/init.d/fedora/core/zabbix_server /etc/init.d/
cp /home/deploy/zabbix-4.0.5/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/home\/deploy\/zabbix/g' /etc/init.d/zabbix_server
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/home\/deploy\/zabbix/g' /etc/init.d/zabbix_agentd
chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
sleep 5


#--------------------------------
#创建nginx用户
#useradd -s /sbin/nologin -M nginx
#安装编译工具 gcc
yum install -y gcc
#安装PCRE库,pcre提供编译版本的库,pcre-devel提供开发阶段的头文件和编译项目的源代码
yum install -y pcre pcre-devel
#安装OpenSSL加密库,nginx中如果服务器需要提供安全网页则会用到OpenSSL库
yum install -y openssl openssl-devel
#安装OpenSSL加密库,nginx中如果服务器需要提供安全网页则会用到OpenSSL库
yum install -y /usr/bin/unzip
#休息5秒
sleep 5
#解压nginx安装包
cd /home/deploy
tar -zxvf nginx-1.16.1.tar.gz
unzip nginx_upstream_check_module-master.zip

echo "解压成功nginx解压成功"
mv nginx_upstream_check_module-master/ nginx-1.16.1/
sleep 5
cd ./nginx-1.16.1
patch -p1 </home/deploy/nginx-1.16.1/nginx_upstream_check_module-master/check_1.16.1+.patch
./configure --prefix=/home/deploy/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/home/deploy/nginx-1.16.1/nginx_upstream_check_module-master
#编译成功后执行安装命令
make -j 4
make install
sleep 5
rm -rf /home/deploy/nginx/conf/nginx.conf
cp -r /home/deploy/nginx.conf /home/deploy/nginx/conf
chown nginx:nginx -R /home/deploy/nginx
#sed -i 's/#user nobody;/user nginx;/g' /home/deploy/nginx/conf/nginx.conf
#sed -i 's/listen 80;/listen 20002;/g' /home/deploy/nginx/conf/nginx.conf
#sed -i '38 r a.txt' /home/deploy/nginx/conf/nginx.conf

#启动Nginx
cd /home/deploy/nginx/sbin
cp nginx /usr/local/sbin/
./nginx -c /home/deploy/nginx/conf/nginx.conf
#检查nginx是否启动成功
ps aux |grep nginx

echo "---------------------------"
echo "部署成功Nginx部署成功"
echo "部署成功Nginx部署成功"
echo "部署成功Nginx部署成功"
echo "---------------------------"
#Nginx开机自启
#echo sh /home/deploy/nginx/sbin/nginx >> /etc/rc.local
chmod 755 /home/deploy/nginx.service
cp -r /home/deploy/nginx.service /usr/lib/systemd/system/
systemctl enable nginx.service
systemctl daemon-reload

echo "---------------------------"
echo "Nginx开机启动已设置成功"
echo "Nginx开机启动已设置成功"
echo "Nginx开机启动已设置成功"
echo "---------------------------"
sleep 10
#-------------------------------------------------
#安装相关依赖
yum install -y libxml2-devel openssl-devel net-snmp net-snmp-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel bzip2 bzip2-devel freetype-devel gmp-devel readline-devel libxslt-devel fontconfig
#休息5秒
sleep 5
cd /home/deploy
#解压nginx安装包
tar -zxvf php-7.2.27.tar.gz
echo "解压成功php解压成功"
echo "解压成功php解压成功"
#编译php,zabbix5版本以上需要更高版本的php
cd ./php-7.2.27
./configure --prefix=/home/deploy/php --with-mysqli=/home/deploy/mysql/bin/mysql_config --enable-inline-optimization --enable-fpm --enable-soap --enable-pcntl --enable-xml --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --without-pear --with-ldap
#编译成功后执行安装命令
make -j 4
make install
sleep 5
#拷贝服务和配置文件及属主和属组
cp /home/deploy/php-7.2.27/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp /home/deploy/php/etc/{php-fpm.conf.default,php-fpm.conf}
cp /home/deploy/php/etc/php-fpm.d/www.conf{.default,}

cd /home/deploy/php-7.2.27
cp php.ini-production /home/deploy/php/lib/php.ini
chown nginx:nginx -R /home/deploy/php
#优化并启动php
sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /home/deploy/php/lib/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /home/deploy/php/lib/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/g' /home/deploy/php/lib/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /home/deploy/php/lib/php.ini
systemctl enable php-fpm.service
systemctl daemon-reload
systemctl restart php-fpm.service
#检查php是否启动成功
ps aux |grep php
sleep 10
echo "---------------------------"
echo "部署成功php部署成功"
echo "部署成功php部署成功"
echo "部署成功php部署成功"
echo "---------------------------"
echo "zabbix修改字体,解决图形乱码问题"
echo "zabbix修改字体,解决图形乱码问题"
echo "5"
sleep 1
echo "4"
sleep 1
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
sleep 1
rm -rf /home/deploy/zabbix_web/web/fonts/DejaVuSans.ttf
mv home/deploy/simkai.ttf /home/deploy/zabbix_web/web/fonts/
sed -i "s/DejaVuSans/simkai/g" /home/deploy/zabbix_web/web/include/defines.inc.php
echo "我的工作完成啦,拜拜"
echo "我的工作完成啦,拜拜"
echo "我的工作完成啦,拜拜"
echo "我的工作完成啦,拜拜"
echo "5"
sleep 1
echo "4"
sleep 1
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
sleep 1

标签:脚本,deploy,--,nginx,zabbix,mysql,home,zabbix4.0,安装
From: https://www.cnblogs.com/xgsh/p/16648351.html

相关文章

  • 自动填写体温脚本详解
    最近疫情又严重了起来,学校要求每天都要上报我们的早、中、晚体温情况,但是我们居然被要求中午就提供全天的体温,这很明显是一个纯纯欺上瞒下的工程。为了不每天浪费时间来扫......
  • Win下Lua环境搭建及LuaRocks安装
    0.背景Linux比较简单,可以看我这篇文章(还没写),这里记录下win的。本次需要准备下面三个软件:1.Lua安装进入LuaforWindows的下载页面,下载Win下面的Lua安装包。下载后......
  • 安装 anaconda
    目录下载安装换源创建自己的环境在环境里安装自己需要的包启动jupyter下载到官方网站找到需要的安装包https://www.anaconda.com/products/distribution在Ubuntu用......
  • 新机器(禁止上网)安装vscode及公钥方式登陆linux
    1.1 新机器(禁止上网)安装vscode注意:以下三个程序版本必须一至。1) vscodeWin10安装程序2) win10插件(ssh客户端)3) linux里vscode-server-linux-x64.tar.gz(ssh服......
  • Ubuntu1604从0安装CUDA
    港澳2020年12月31日目录通过安装CUDA来安装驱动先安装驱动禁用第三方驱动、卸载初始驱动、关闭图形界面再安装CUDA卸载CUDA安装Tensorflow安装VSCode和Requirements包Int......
  • Javamis 开发环境 - Tomcat安装和配置(超详细图文说明)
     文章目录 二、第二章搭建开发环境(windows环境)2.1、Tomcat安装和配置2.1.1、官网下载2.1.2、开始安装2.1.3、端口配置2.......
  • Grafana安装配置和简单图标实现(使用MySQL数据源)
    grafana介绍Grafana是一个开源的度量分析与可视化套件,纯JavaScript开发的前端工具,通过访问库(如InfluxDB),展示自定义报表、显示图表等。它的UI十分灵活,有丰富的插件和模板,功......
  • 【已解决】element ui版本安装问题
    使用npmielement-ui-S报错使用cnpminstall--saveelement-ui不报错 (注意是:cnpm,这是用淘宝镜像安装的)如果你不能使用cnpm的话,执行下面语句就可以了。npminst......
  • 在maven引入一个maven仓库中不存在的jar,安装本地的仓库
    在maven引入一个maven仓库中不存在的jar,安装本地的仓库公司内部的jar包肯定不会在网络上存在的.问题描述:如果要在一个maven工程中引入一个不存在的jar,即无法通过denpend......
  • Linux环境安装并配置Maven
    Linux环境安装并配置Maven1.进入Maven官网复制下载地址下载mavenmaven官网:http://maven.apache.org/英文状态下:在线下载maven:wgethttps://dlcdn.apache.org/......