周作业七

  1. 通过编写 shell 脚本实现二进制安装 LAMP 架构的 word press

说明:编译安装基于HTTPD模块的LAMP架构应用
在这里插入图片描述

#在10.0.0.17上编译安装mariadb,事先下好编译包
[root@centos7 ~]# ls install_general_mariadb.sh mariadb-10.5.5-linux-systemd-x86_64.tar.gz 
install_general_mariadb.sh  mariadb-10.5.5-linux-systemd-x86_64.tar.gz
[root@centos7 ~]# cat install_general_mariadb.sh 
#!/bin/bash

# mariadb-10.5.5 URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.5.5/bintar-linux-systemd-x86_64/mariadb-10.5.5-linux-systemd-x86_64.tar.gz

PACK=mariadb-10.5.5-linux-systemd-x86_64.tar.gz
DIR=mariadb-10.5.5-linux-systemd-x86_64
URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.5.5/bintar-linux-systemd-x86_64/mariadb-10.5.5-linux-systemd-x86_64.tar.gz
PASS=centos

echo -e "\e[1;$[RANDOM%7+31]m安装开始...\e[0m"
yum -y install ncurses-compat-libs &> /dev/null
#wget $URL &> /dev/null
groupadd -r mysql
useradd -r -g  mysql -s /sbin/nologin mysql
mkdir /data/mysql
chown mysql.mysql /data/mysql
tar xf $PACK -C /usr/local/
cd /usr/local/
chown -R root.mysql $DIR 
ln -s $DIR mysql
cd mysql
ln -s /usr/local/mysql/bin/* /usr/bin
chown -R root.mysql ./*
scripts/mysql_install_db --datadir=/data/mysql --user=mysql &> /dev/null
cp /etc/my.cnf{,.bak}
cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock
EOF
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
echo -e "\e[1;$[RANDOM%7+31]m安装完毕,请登录并使用数据库!!!\e[0m"

mysqladmin -uroot password $PASS
mysql -uroot -p$PASS -e 'create database wordpress'
mysql -uroot -pcentos -e "grant all on wordpress.* to wordpress@'10.0.0.%' identified by 'centos'"
[root@centos7 ~]# bash install_general_mariadb.sh

#在10.0.0.7上编译安装httpd24,php,以及准备好编译包
[root@centos7 ~]# ls install_LAMP_wordpress.sh php-7.3.24.tar.bz2 wordpress-5.4.2-zh_CN.tar.gz 
install_LAMP_wordpress.sh  php-7.3.24.tar.bz2  wordpress-5.4.2-zh_CN.tar.gz
[root@centos7 ~]# cat install_LAMP_wordpress.sh 
#!/bin/bash

httpd24() {
. /etc/init.d/functions

P1=https://downloads.apache.org//apr/apr-1.7.0.tar.bz2
P2=https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2
P3=https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2
COMP1=`echo $P1|awk -F'/' '{print $NF}'`
COMP2=`echo $P2|awk -F'/' '{print $NF}'`
COMP3=`echo $P3|awk -F'/' '{print $NF}'`
DIR1=`echo $COMP1|sed -nr 's/(.*).tar.*/\1/p'`
DIR2=`echo $COMP2|sed -nr 's/(.*).tar.*/\1/p'`
DIR3=`echo $COMP3|sed -nr 's/(.*).tar.*/\1/p'`
DIR4=/apps/httpd24

wget -q $P1  
wget -q $P2
wget -q $P3

yum -y install gzip2 pcre-devel lbzip2 openssl-devel expat-devel &> /dev/null

tar xf $COMP1 
tar xf $COMP2 
tar xf $COMP3 

mv $DIR1 $DIR3/srclib/apr
mv $DIR2 $DIR3/srclib/apr-util

cd $DIR3
./configure --prefix=${DIR4} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork &> /dev/null

make -j `lscpu |sed -nr 's/^CPU\(s\):(.*)/\1/p'|tr -s ' '` &> /dev/null  && make install &> /dev/null

useradd -r -s /sbin/nologin apache && action "用户创建成功" || action "用户已经存在" false
sed -ri 's/^(User).*/\1 apache/' $DIR4/conf/httpd.conf
sed -ri 's/^(Group).*/\1 apache/' $DIR4/conf/httpd.conf

ln -s $DIR4/bin/* /usr/bin/
echo "MANDATORY_MANPATH $DIR4/man" >> /etc/man_db.conf

cat > /lib/systemd/system/httpd24.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=${DIR4}/bin/apachectl start
ExecReload=${DIR4}/bin/apachectl graceful
ExecStop=${DIR4}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable --now httpd24 &> /dev/null && action "服务启动成功"
cd
}

php73() {

URL=https://www.php.net/distributions/php-7.3.24.tar.bz2
P1=`echo $URL | awk -F'/' '{print $NF}'`
DIR=`echo $P1 | sed -nr 's/(.*).tar.*/\1/p'`

#wget -q $URL

yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel &> /dev/null

tar xf $P1
cd $DIR
./configure --prefix=/apps/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/apps/httpd24/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo &> /dev/null

make -j `lscpu |sed -nr 's/^CPU\(s\):(.*)/\1/p'|tr -s ' '` &> /dev/null  && make install &> /dev/null

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

sed -i -e 's/#AddEncoding x-compress.*/AddType application\/x-httpd-php .php/' -e 's/#AddEncoding x-gzip.*/AddType application\/x-httpd-source .phps/' -e 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /apps/httpd24/conf/httpd.conf

systemctl restart httpd24.service
}

wordpress() {

URL=https://cn.wordpress.org/wordpress-5.4.2-zh_CN.tar.gz
P=`echo $URL | awk -F'/' '{print $NF}'`
DIR1=`echo $P | awk -F'-' '{print $1}'`
DIR2=/apps/httpd24/htdocs

#wget $URL
tar xf $P
mv ${DIR1} ${DIR2}
chown -R apache.apache ${DIR2}

echo -e "\e[1;31m 打开浏览器输入http://LAMP服务器IP/wordpress进行页面安装\e[0m"
}

httpd24
php73
wordpress

[root@centos7 ~]# bash install_LAMP_wordpress.sh 

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值