2020-11-02

#!/bin/bash

#-------------------------------------------------------------------

. /etc/init.d/functions

pwd=`pwd`

#二進(jìn)制安裝mariadb

#-------------------------------------------------------------------

echo -e "\e[1;31m 二進(jìn)制安裝mariadb \e[0m"

#創(chuàng)建mysql用戶

id mysql &> /dev/null || { useradd -r -d /data/mysql -s /sbin/nologin mysql ; action "創(chuàng)建mysql用戶成功"; }

#安裝依賴包

yum install? -y libaio perl-Data-Dumper ncurses-compat-libs mysql &> /dev/null && action "安裝依賴包成功"

#創(chuàng)建mysql的家目錄文件夾

mkdir -pv /data/mysql &> /dev/null && { chown mysql:mysql /data/mysql &> /dev/null; action "創(chuàng)建mysql的家目錄文件夾成功"; }

#解壓二進(jìn)制程序

tar xvf mariadb-10.2.32-linux-glibc_214-x86_64.tar.gz -C /usr/local &> /dev/null && action "解壓二進(jìn)制程序成功"

#將原文件創(chuàng)建為軟鏈接

ln -sv /usr/local/mariadb-10.2.32-linux-glibc_214-x86_64 /usr/local/mysql &> /dev/null && action "將原文件創(chuàng)建為軟鏈接成功"

chown -R mysql.mysql /usr/local/mysql/

#準(zhǔn)備配置文件

cp -a /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf

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

[ -a /etc/my.cnf ] && action "配置文件配置成功"

#創(chuàng)建數(shù)據(jù)庫文件

cd /usr/local/mysql/

./scripts/mysql_install_db --datadir=/data/mysql --user=mysql &> /dev/null && action "創(chuàng)建數(shù)據(jù)庫文件成功"

#服務(wù)啟動(dòng)文件

cp /usr/local/mysql/support-files/mysql.server? /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

#環(huán)境變量

{ echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh; chmod +x /etc/profile.d/mysql.sh; . /etc/profile.d/mysql.sh; } && action "環(huán)境變量創(chuàng)建成功"

#編譯安裝http2.4.46

#-------------------------------------------------------------------

echo -e "\e[1;31m 編譯安裝http2.4.46 \e[0m"

FILE=/apps/httpd

cd $pwd

#依賴包安裝

yum -y install gcc make pcre-devel openssl-devel expat-devel bzip2 &> /dev/null && action "安裝依賴包成功"

#解壓相關(guān)源碼包

tar xf httpd-2.4.46.tar.gz && action "httpd源碼包解壓成功"

tar xf apr-1.7.0.tar.bz2 && mv apr-1.7.0 httpd-2.4.46/srclib/apr && action "apr源碼包解壓成功"

tar xf apr-util-1.6.1.tar.bz2 && mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util && action "apr-util源碼包解壓成功"

#編譯

[ -d $FILE ] || mkdir -p $FILE

cd httpd-2.4.46/

./configure --prefix=$FILE --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 && action "編譯完成" || { action "編譯失敗" false; exit; }

#安裝

make? -j `lscpu | grep "^cpu(s)" | awk '{print $NF}'` &> /dev/null? && { make install &> /dev/null; action "httpd安裝完成"; }

#創(chuàng)建用戶

id apache &> /dev/null || { useradd -s /sbin/nologin -r apache; action "創(chuàng)建apache用戶成功"; }

#修改配置文件中的啟動(dòng)用戶

{ sed -i 's/^User.*/User apache/' ${FILE}/conf/httpd.conf; sed -i 's/^Group.*/Group apache/' ${FILE}/conf/httpd.conf; } && action "啟動(dòng)用戶修改成功"

#配置環(huán)境變量

{ echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh; source /etc/profile.d/httpd.sh; } && action "環(huán)境變量配置成功"

#配置man幫助

echo 'MANDATORY_MANPATH? ? ? ? ? /apps/httpd/man' >> /etc/man_db.conf && action "配置man幫助成功"

#創(chuàng)建服務(wù)啟動(dòng)文件

cat > /lib/systemd/system/httpd.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=$FILE/bin/apachectl start

ExecReload=$FILE/bin/apachectl graceful

ExecStop=$FILE/bin/apachectl stop

KillSignal=SIGCONT

PrivateTmp=true

[Install]

WantedBy=multi-user.target

EOF

[ -a /lib/systemd/system/httpd.service ] && action "創(chuàng)建服務(wù)啟動(dòng)文件成功"

#啟動(dòng)服務(wù)

systemctl daemon-reload

systemctl enable --now httpd.service &> /dev/null && action "httpd服務(wù)啟動(dòng)成功" || action "httpd服務(wù)啟動(dòng)失敗,請(qǐng)檢查配置文件" false

#編譯安裝httpd模塊方式 php-7.3

#-------------------------------------------------------------------

echo -e "\e[1;31m 編譯安裝php-7.3 \e[0m"

FILE1=/apps/php

cd $pwd

#安裝相關(guān)包

yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel &> /dev/null && action "依賴包安裝成功"

#解壓源碼包

tar xf php-7.3.15.tar.xz && action "php源碼包解壓成功"

#編譯

[ -d $FILE1 ] || mkdir -p $FILE1

cd php-7.3.15/

./configure --prefix=$FILE1 --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/httpd/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo &> /dev/null && action "編譯完成" || { action "編譯失敗" false; exit; }

#安裝

make? -j `lscpu | grep "^cpu(s)" | awk '{print $NF}'` &> /dev/null? && { make install &> /dev/null; action "php安裝完成"; }

#為php提供配置文件

cp php.ini-production /etc/php.ini && action "php配置文件配置成功"

#修改配置實(shí)現(xiàn)lamp架構(gòu)

#-------------------------------------------------------------------

echo -e "\e[1;31m 修改配置實(shí)現(xiàn)lamp架構(gòu) \e[0m"

#編輯 apache 配置文件支持 php

{ echo -e "AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps" >> /apps/httpd/conf/httpd.conf; sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /apps/httpd/conf/httpd.conf; } && action "編輯apache配置文件支持php成功"

systemctl restart httpd

#在數(shù)據(jù)庫中創(chuàng)建wordpress數(shù)據(jù)庫和用戶

{ mysql -e "create database wordpress;"; mysql -e "grant all on wordpress.* to wordpress@'10.0.0.%' identified by 'qwe123';"; } && action "wordpress數(shù)據(jù)庫和用戶創(chuàng)建成功"

#部署wordpress

#-------------------------------------------------------------------

echo -e "\e[1;31m 部署wordpress \e[0m"

cd $pwd

#解壓

tar xf wordpress-5.4.2-zh_CN.tar.gz && action "wordpress解壓成功"

#移動(dòng)到wordpress到html文件下

mv wordpress /apps/httpd/htdocs/ && action "移動(dòng)到wordpress到html文件下成功"

#修改wordpress文件權(quán)限

chown -R apache.apache /apps/httpd/htdocs/wordpress && action "修改wordpress文件權(quán)限成功"

echo -e "\e[1;33m LAMP部署wordpress已完成,打開http://`hostname -I`/wordpress頁面進(jìn)行安裝 \e[0m"

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容