me小怪兽

导航

zabbix4.0.5自动安装脚本

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

环境: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

posted on 2022-09-02 00:50  me小怪兽  阅读(93)  评论(0编辑  收藏  举报