写点什么

闲来无事,写脚本,install_wordpress

用户头像
陈迪
关注
发布于: 2021 年 04 月 25 日
闲来无事,写脚本,install_wordpress

脚本特点

应用 bash 的高级变量赋值,关联数组,变量切片等特性实现一键安装 wordpress。

安装的 wordpress 基于 lamp 架构实现。(linux apache mysql/mariadb php)

安装完成后,使用者可以根据自己需求进行调试,优化。

例如 mysql 数据库的备份等。

wordpress 介绍

应用最广泛的个人博客软件。

脚本内容

#!/bin/bashyum install  gcc pcre-devel  openssl-devel expat-devel libaio gcc openssl-devel libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel lbzip2 -ySWdir=/var/software/APuser=apacheAPgroup=apacheWPname=wordpressdeclare -A soft_namedeclare -A tar_namedeclare -A dir_namedeclare -A Enddir_name#soft_name[mysql]='https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-8.5.4/bintar-linux-x86_64/mariadb-10.5.4-linux-x86_64.tar.gz'soft_name[apr]='https://downloads.apache.org//apr/apr-1.7.0.tar.bz2' soft_name[apru]='https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2' soft_name[http]='https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2'soft_name[php]='http://mirrors.sohu.com/php/php-7.4.7.tar.gz'soft_name[wordpress]='https://cn.wordpress.org/wordpress-5.4.2-zh_CN.tar.gz'
#取后缀文件名#第一种方式#echo ${soft_name[*]}#SoftTar=${SoftURL##*/}#SoftDir=${SoftTar%%.tar*}#第二种方式for Name in ${!soft_name[@]};do tar_name[$Name]=${soft_name[$Name]##*/} dir_name[$Name]=${tar_name[$Name]%%.tar*} if [ $Name = 'apru' ];then Enddir_name[$Name]=${dir_name[$Name]%\-*} else Enddir_name[$Name]=${dir_name[$Name]%%\-*} fidone
function Fwget(){ [[ -d $SWdir ]] || mkdir $SWdir wget -P $SWdir $1}function Uadd(){ for user in $@;do useradd -r -s /sbin/nologin $user done}function Unzip(){ tar -xf ${SWdir}$1 -C /usr/local/}function Ln(){ if [[ $2 =~ (apr|apr-util) ]];then mv $1 /usr/local/httpd/srclib/$2 else ln -s $1 /usr/local/$2 fi}function Source(){ Cpunum=$(lscpu|awk -F' ' '/CPU\(s\)/{print $2}'|head -n1) cd ${1}${2} if [[ $2 == 'httpd' ]];then ./configure \--prefix=/apps/httpd24 \--enable-so \--enable-ssl \--enable-cgi \--enable-rewrite \--with-zlib \--with-pcre \--enable-modules=most \--enable-mpms-shared=all \--with-mpm=prefork \--with-included-apr make -j ${Cpunum} && make install cat > /usr/lib/systemd/system/httpd.service <<EOF[Unit]Description=The Apache HTTP ServerAfter=network.target remote-fs.target nss-lookup.targetDocumentation=man:httpd(8)Documentation=man:apachectl(8)[Service]Type=forking#EnvironmentFile=/etc/sysconfig/httpdExecStart=/apps/httpd24/bin/apachectl start#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k startExecReload=/apps/httpd24/bin/apachectl graceful#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k gracefulExecStop=/apps/httpd24/bin/apachectl stopKillSignal=SIGCONTPrivateTmp=true[Install]WantedBy=multi-user.targetEOF systemctl daemon-reload ln -s /apps/httpd24/bin/* /usr/local/bin/ elif [[ $2 == 'php' ]];then./configure \--prefix=/apps/php74 \--enable-mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-openssl \--with-zlib \--with-config-file-path=/etc \--with-config-file-scan-dir=/etc/php.d \--enable-mbstring \--enable-xml \--enable-sockets \--enable-fpm \--enable-maintainer-zts \--disable-fileinfo make -j ${Cpunum} && make install cp ${1}${2}/php.ini-production /etc/php.ini cp ${1}${2}/sapi/fpm/php-fpm.service /usr/lib/systemd/system/ systemctl daemon-reload elif [[ $2 == 'mariadb' ]];then Datadir=/data/mysql [[ -d $Datadir ]] || mkdir -p $Datadir# chown -R mysql.root ${Datadir} cat > /etc/my.cnf <<MYSQL[mysqld]datadir=${Datadir}skip_name_resolve=1socket=${Datadir}/mysql.socklog-error=${Datadir}/mysql_error.logpid-file=${Datadir}/mysql.pid
[client]port=3306socket=${Datadir}/mysql.sockMYSQL sed -Ei "s@/usr/local/mysql@${1}${2}@g" ${1}${2}/support-files/mysql.server cp ${1}${2}/support-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld ${1}${2}/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --datadir=${Datadir} ln -s /usr/local/mariadb/bin/* /usr/local/bin/ service mysqld start mysqladmin -u root password 123.com mysql -u root -p123.com -e "CREATE DATABASE wordpress CHARACTER SET=utf8mb4; DROP USER ''@'localhost'; GRANT ALL ON wordpress.* TO wordpress@'%' IDENTIFIED BY 'wordpress';" else echo 附加包 fi}function ConfWP(){ site=/apps/httpd24/htdocs mv /usr/local/${Enddir_name[wordpress]} ${site}/$WPname cp ${site}/$WPname/wp-config-sample.php ${site}/$WPname/wp-config.php sed -Ei "/DB_NAME/s@(.*, ').*('.*)@\1wordpress\2@g" ${site}/${WPname}/wp-config.php sed -Ei "/DB_USER/s@(.*, ').*('.*)@\1wordpress\2@g" ${site}/${WPname}/wp-config.php sed -Ei "/DB_PASSWORD/s@(.*, ').*('.*)@\1wordpress\2@g" ${site}/${WPname}/wp-config.php sed -Ei "/DB_HOST/s@(.*, ').*('.*)@\1127.0.0.1\2@g" ${site}/${WPname}/wp-config.php chown apache.root -R ${site}/${WPname}}function ConfPHP(){ Phpdir=/apps/php74/ cp -f ${Phpdir}etc/php-fpm.conf.default ${Phpdir}etc/php-fpm.conf mkdir -p /etc/php.d/ cp -f ${Phpdir}etc/php-fpm.d/www.conf.default ${Phpdir}etc/php-fpm.d/www.conf sed -Ei "/user /s@(user =).*@\1${APuser}@" ${Phpdir}etc/php-fpm.d/www.conf sed -Ei "/group /s@(group =).*@\1${APgroup}@" ${Phpdir}etc/php-fpm.d/www.conf cat > /etc/php.d/opcache.ini <<PHP[opcache]zend_extension=opcache.soopcache.enable=1PHP}function ConfApache(){ local Apachedir=/apps/httpd24 #取消下面两行的注释 #sed -i "s@#LoadModule proxy_module modules/mod_proxy.so@LoadModule proxy_module modules/mod_proxy.so@g" ${Apachedir}/conf/httpd.conf #sed -i "s@#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@g" ${Apachedir}/conf/httpd.conf sed -Ei -e '/mod_proxy.so/s/#(.*)/\1/g' -e '/mod_proxy_fcgi.so/s/#(.*)/\1/g' ${Apachedir}/conf/httpd.conf sed -Ei "s@(User ).*@\1apache@g" ${Apachedir}/conf/httpd.conf sed -Ei "s@(Group ).*@\1apache@g" ${Apachedir}/conf/httpd.conf #修改下面行 sed -Ei "/DirectoryIndex /s@([^ ]+)(.*)@\1 index.php\2@gp" ${Apachedir}/conf/httpd.conf #加下面三行 sed -i "s@(DocumentRoot) \".*\"@\1 \"${Apachedir}/htdocs/${WPname}\"@" ${Apachedir}/conf/httpd.conf sed -i "/AddType text\/html /a AddType application/x-httpd-php .php" ${Apachedir}/conf/httpd.conf echo "ProxyRequests Off" >> ${Apachedir}/conf/httpd.conf echo "ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000${Apachedir}/htdocs/${WPname}/\$1" >> ${Apachedir}/conf/httpd.conf}
function Start(){ systemctl start $@}
function main(){ Uadd mysql apache #下载安装包 for paName in ${!soft_name[@]};do Fwget ${soft_name[$paName]} done #解压安装包 for paName in ${!soft_name[@]};do Unzip ${tar_name[$paName]} done #创建软连接 for paName in ${!soft_name[@]};do Ln /usr/local/${dir_name[$paName]} ${Enddir_name[$paName]} done #编译安装 for paName in ${!soft_name[@]};do Source /usr/local/ ${Enddir_name[$paName]} done #php 配置 ConfPHP
#wordpress 配置 ConfWP #apache配置 ConfApache #启用服务 Start httpd php-fpm}
main
复制代码


发布于: 2021 年 04 月 25 日阅读数: 8
用户头像

陈迪

关注

期望 2021.03.29 加入

容器云方向 正在学习Go......

评论

发布
暂无评论
闲来无事,写脚本,install_wordpress