shell脚本一键部署zabbix监控服务(2)

本文提供了一线大厂Java面试题解析,包括实战项目源码、Apache、PHP和MySQL的配置教程,以及面试时的高频算法题和学习笔记,帮助读者全面准备技术面试。
摘要由CSDN通过智能技术生成

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
[root@192 script]# tree

.

├── lamp+zabbix.sh

└── packages

├── apr-1.7.0.tar.gz

├── apr-util-1.6.1.tar.gz

├── httpd-2.4.51.tar.gz

├── mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

├── php-8.0.12.tar.gz

└── zabbix-5.4.4.tar.gz

1 directory, 7 files

编写脚本

===================================================================

[root@192 script]# cat lamp+zabbix.sh

#!/bin/bash

route=/usr/local

path=/usr/src

data=/opt/data

pass=123

if [ ! -d $path/apr-1.7.0 ];then

tar xf packages/apr-1.7.0.tar.gz -C $path

fi

if [ ! -d $path/apr-util-1.6.1 ];then

tar xf packages/apr-util-1.6.1.tar.gz -C $path

fi

if [ ! -d $path/httpd-2.4.51 ];then

tar xf packages/httpd-2.4.51.tar.gz -C $path

fi

if [ ! -d $route/php-8.0.12 ];then

tar xf packages/php-8.0.12.tar.gz -C $route

fi

if [ ! -d $route/zabbix-5.4.4 ];then

tar xf packages/zabbix-5.4.4.tar.gz -C $route

fi

if [ ! -d $route/mysql-5.7.34-linux-glibc2.12-x86_64 ];then

tar xf packages/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C $route

cd $route

ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql

fi

if [ ! -f /etc/yum.repos.d/CentOS-Base.repo ];then

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

fi

yum -y install epel-release wget make openssl openssl-devel pcre pcre-devel gcc gcc-c++ zlib-devel expat-devel zlib expat net-snmp-devel libevent-devel zlib ncurses-compat-libs perl ncurses-devel cmake libxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd libsqlite3x-devel libzip-devel wget mysql-devel

if [ ! -f ./oniguruma-devel-6.8.2-2.el8.x86_64.rpm ];then

wget http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

yum -y install oniguruma-devel-6.8.2-2.el8.x86_64.rpm

fi

yum groups mark install ‘Development Tools’ -y

id apache &> /dev/null

if [ $? -ne 0 ];then

useradd -r -M -s /sbin/nologin apache

fi

cd $path/apr-1.7.0

if [ ! -d $route/apr ];then

sed -i ‘s/$RM “cfgfile”/d’ configure

./configure --prefix=/usr/local/apr

make && make install

fi

cd $path/apr-util-1.6.1

if [ ! -d $route/apr-util-1.6.1 ];then

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

fi

cd $path/httpd-2.4.51

if [ ! -d $route/httpd-2.4.51 ];then

./configure --prefix=/usr/local/apache \

–enable-so \

–enable-ssl \

–enable-cgi \

–enable-rewrite \

–with-zlib \

–with-pcre \

–with-apr=/usr/local/apr \

–with-apr-util=/usr/local/apr-util/ \

–enable-modules=most \

–enable-mpms-shared=all \

–with-mpm=prefork

make && make install

fi

if [ $? -eq 0 ];then

echo “apache 编译完成”

else

echo “apache 编译失败,请检查”

fi

ln -s /usr/local/apache/include/ /usr/include/httpd

echo ‘export PATH=/usr/local/apache/bin:$PATH’ > /etc/profile.d/httpd.sh

cd $route/apache/conf/

sed -i ‘203s///g’ httpd.conf

touch /usr/lib/systemd/system/httpd.service

sum=$(cat /usr/lib/systemd/system/httpd.service | wc -l)

if [ $sum -lt 2 ];then

cat > /usr/lib/systemd/system/httpd.service << EOF

[Unit]

Description=httpd server daemon

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/apache/bin/apachectl start

ExecStop=/usr/local/apache/bin/apachectl stop

ExecReload=/bin/kill -HUP $MAINPID

[Install]

WantedBy=multi-user.target

EOF

fi

systemctl daemon-reload

systemctl enable --now httpd

echo “安装mysql”

id mysql &> /dev/null

if [ $? -ne 0 ];then

useradd -r -M -s /sbin/nologin mysql

fi

chown -R mysql.mysql $route/mysql

echo ‘export PATH=/usr/local/mysql/bin:$PATH’ > /etc/profile.d/mysql.sh

mkdir -p /opt/data

chown -R mysql.mysql /opt/data/

look=$( ls $data | wc -l)

if [ $look -eq 0 ];then

$route/mysql/bin/mysqld --initialize-insecure --user mysql --datadir /opt/data/

cat > /etc/my.cnf << EOF

[mysqld]

basedir = $route/mysql

datadir = $data

socket = /tmp/mysql.sock

port = 3306

pid-file = /opt/data/mysql.pid

user = mysql

skip-name-resolve

EOF

sed -ri “s^(basedir=).*\1$route/mysqlg” /usr/local/mysql/support-files/mysql.server

sed -ri “s^(datadir=).*\1$datag” /usr/local/mysql/support-files/mysql.server

cat > /usr/lib/systemd/system/mysql.service << EOF

[Unit]

Description=mysql server daemon

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/mysql/support-files/mysql.server start

ExecStop= /usr/local/mysql/support-files/mysql.server stop

ExecReload=/bin/kill -HUP $MAINPID

[Install]

WantedBy=multi-user.target

EOF

fi

systemctl daemon-reload

systemctl enable --now mysql

echo “部署PHP”

cd $route/php-8.0.12

if [ ! -d $route/php8 ];then

./configure --prefix=/usr/local/php8 --with-config-file-path=/etc --enable-fpm --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix && \

make && make install

fi

echo ‘export PATH=/usr/local/php8/bin:$PATH’ > /etc/profile.d/php.sh

cd $route/php-8.0.12

cp php.ini-production /etc/php.ini

cd $route/php-8.0.12/sapi/fpm

cp init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/rc.d/init.d/php-fpm

cp $route/php8/etc/php-fpm.conf.default $route/php8/etc/php-fpm.conf

cp $route/php8/etc/php-fpm.d/www.conf.default $route/php8/etc/php-fpm.d/www.conf

touch /usr/lib/systemd/system/php-fpm.service

view=$(cat /usr/lib/systemd/system/php-fpm.service | wc -l)

if [ $view -lt 2 ];then

cat > /usr/lib/systemd/system/php-fpm.service << EOF

[Unit]

Description=php server daemon

After=network.target

[Service]

Type=forking

ExecStart=/etc/init.d/php-fpm start

ExecStop=/etc/init.d/php-fpm stop

ExecReload=/bin/kill -HUP $MAINPID

[Install]

WantedBy=multi-user.target

EOF

fi

systemctl daemon-reload

systemctl enable --now php-fpm

sed -i ‘120s/#//g’ /usr/local/apache/conf/httpd.conf

sed -i ‘124s/#//g’ /usr/local/apache/conf/httpd.conf

cd $route/apache/htdocs && mkdir -p test

cd $route/apache/htdocs/test

if [ ! -s index.php ];then

cat > index.php << EOF

<?php phpinfo(); ?>

EOF

chown -R apache.apache /usr/local/apache/htdocs/

cd $route/apache/conf

cat >> httpd.conf << EOF

<VirtualHost *:80>

DocumentRoot “/usr/local/apache/htdocs/test”

ServerName www.test.com

ProxyRequests Off

惊喜

最后还准备了一套上面资料对应的面试题(有答案哦)和面试时的高频面试算法题(如果面试准备时间不够,那么集中把这些算法题做完即可,命中率高达85%+)

image.png

image.png

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
OF

chown -R apache.apache /usr/local/apache/htdocs/

cd $route/apache/conf

cat >> httpd.conf << EOF

<VirtualHost *:80>

DocumentRoot “/usr/local/apache/htdocs/test”

ServerName www.test.com

ProxyRequests Off

惊喜

最后还准备了一套上面资料对应的面试题(有答案哦)和面试时的高频面试算法题(如果面试准备时间不够,那么集中把这些算法题做完即可,命中率高达85%+)

[外链图片转存中…(img-NTni6j1b-1714653462662)]

[外链图片转存中…(img-WZXzwBzk-1714653462663)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

  • 10
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值