利用shell 指令碼實現二進位制安裝 LAMP 架構的 word press
阿新 • • 發佈:2020-10-31
#!/bin/bash #------------------------------------------------------------------- . /etc/init.d/functions pwd=`pwd` #二進位制安裝mariadb #------------------------------------------------------------------- echo -e "\e[1;31m 二進位制安裝mariadb \e[0m" #建立mysql使用者 id mysql &> /dev/null || { useradd -r -d /data/mysql -s /sbin/nologin mysql ; action "建立mysql使用者成功"; } #安裝依賴包 yum install -y libaio perl-Data-Dumper ncurses-compat-libs mysql &> /dev/null && action "安裝依賴包成功" #建立mysql的家目錄資料夾 mkdir -pv /data/mysql &> /dev/null && { chown mysql:mysql /data/mysql &> /dev/null; action "建立mysql的家目錄資料夾成功"; } #解壓二進位制程式 tar xvf mariadb-10.2.32-linux-glibc_214-x86_64.tar.gz -C /usr/local &> /dev/null && action "解壓二進位制程式成功" #將原檔案建立為軟連結 ln -sv /usr/local/mariadb-10.2.32-linux-glibc_214-x86_64 /usr/local/mysql &> /dev/null && action "將原檔案建立為軟連結成功" chown -R mysql.mysql /usr/local/mysql/ #準備配置檔案 cp -a /usr/local/mysql/support-files/my-large.cnf /etc/my.cnfcat > /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 "配置檔案配置成功" #建立資料庫檔案 cd /usr/local/mysql/ ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql &> /dev/null && action "建立資料庫檔案成功" #服務啟動檔案 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start #環境變數 { 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 "環境變數建立成功" #編譯安裝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 "安裝依賴包成功" #解壓相關原始碼包 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安裝完成"; } #建立使用者 id apache &> /dev/null || { useradd -s /sbin/nologin -r apache; action "建立apache使用者成功"; } #修改配置檔案中的啟動使用者 { sed -i 's/^User.*/User apache/' ${FILE}/conf/httpd.conf; sed -i 's/^Group.*/Group apache/' ${FILE}/conf/httpd.conf; } && action "啟動使用者修改成功" #配置環境變數 { echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh; source /etc/profile.d/httpd.sh; } && action "環境變數配置成功" #配置man幫助 echo 'MANDATORY_MANPATH /apps/httpd/man' >> /etc/man_db.conf && action "配置man幫助成功" #建立服務啟動檔案 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 "建立服務啟動檔案成功" #啟動服務 systemctl daemon-reload systemctl enable --now httpd.service &> /dev/null && action "httpd服務啟動成功" || action "httpd服務啟動失敗,請檢查配置檔案" false #編譯安裝httpd模組方式 php-7.3 #------------------------------------------------------------------- echo -e "\e[1;31m 編譯安裝php-7.3 \e[0m" FILE1=/apps/php cd $pwd #安裝相關包 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配置檔案配置成功" #修改配置實現lamp架構 #------------------------------------------------------------------- echo -e "\e[1;31m 修改配置實現lamp架構 \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 #在資料庫中建立wordpress資料庫和使用者 { mysql -e "create database wordpress;"; mysql -e "grant all on wordpress.* to wordpress@'10.0.0.%' identified by 'qwe123';"; } && action "wordpress資料庫和使用者建立成功" #部署wordpress #------------------------------------------------------------------- echo -e "\e[1;31m 部署wordpress \e[0m" cd $pwd #解壓 tar xf wordpress-5.4.2-zh_CN.tar.gz && action "wordpress解壓成功" #移動到wordpress到html檔案下 mv wordpress /apps/httpd/htdocs/ && action "移動到wordpress到html檔案下成功" #修改wordpress檔案許可權 chown -R apache.apache /apps/httpd/htdocs/wordpress && action "修改wordpress檔案許可權成功" echo -e "\e[1;33m LAMP部署wordpress已完成,開啟http://`hostname -I`/wordpress頁面進行安裝 \e[0m"