作者:皇家城市_579 | 来源:互联网 | 2023-08-23 20:10
1:shell脚本实现二进制安装LAMP架构的wordpressmysql_packagemariadb-10.2.31-linux-x86_64.tar.gzm
1: shell 脚本实现二进制安装 LAMP 架构的 word press
mysql_package=mariadb-10.2.31-linux-x86_64.tar.gz
mysql_dir=/data/mysql
php_dir=/data/php74
uncompress_dir=/usr/local
install_dir=/data/httpd
download_urls=("https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2" "https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.bz2" "https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2")
PHP='php-7.4.3.tar.xz'
WORDPRESS='wordpress-5.4.2-zh_CN.tar.gz'
mysql_pass=123456
MYSQL_WORDPRESS_PASSWD=123456
discuz=Discuz_X3.4_SC_UTF8【20191201】.zip
install_mysql () {yum -y install libaio perl-Data-Dumper autoconf ncurses-compat-libs &> /dev/nullid mysql &> /dev/null || (groupadd -r -g 306 mysql;useradd -r -g 306 -u 306 -d $mysql_dir mysql) mkdir /data/mysql chown -R mysql.mysql $mysql_dirtar xf ${mysql_package} -C $uncompress_dirln -s $uncompress_dir/${mysql_package%.tar.gz} $uncompress_dir/mysqlchown -R root.root $uncompress_dir/mysqlln -sv $uncompress_dir/mysql/bin/* /usr/bincat > /etc/my.cnf << EOF
[mysqld]
server-id&#61;1
log-bin
socket&#61;$mysql_dir/mysql.sock
datadir &#61;$mysql_dir
log-error&#61;$mysql_dir/mysql.log
pid-file&#61;$mysql_dir/mysql.pid
skip_name_resolve &#61; on[client]
socket&#61;/data/mysql/mysql.sockEOF
$uncompress_dir/mysql/scripts/mysql_install_db --user&#61;mysql --datadir&#61;$mysql_dir
cp $uncompress_dir/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
def_passwd&#61;&#96; awk &#39;/A temporary password /{print $NF }&#39; /data/mysql/mysql.log&#96;
mysqladmin -uroot -p${def_passwd} password $mysql_pass &> /dev/null
}
install_httpd () {yum -y install gcc make pcre-devel openssl-devel expat-devel wgetfor i in ${download_urls[*]};dowget $i tar xf ${idoneid apache || useradd -s /sbin/nologin -r apachecd $uncompress_dirmv &#96;basename -s .tar.bz2 ${download_urls[1]} &#96; &#96;basename -s .tar.bz2 ${download_urls[0]}&#96;/srclib/aprmv &#96;basename -s .tar.bz2 ${download_urls[2]}&#96; &#96;basename -s .tar.bz2 ${download_urls[0]}&#96;/srclib/apr-utilcd $uncompress_dir/&#96;basename -s .tar.bz2 ${download_urls[0]}&#96;/
./configure --prefix&#61;${install_dir} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules&#61;most --enable-mpms-shared&#61;all --with-mpm&#61;prefork
make -j 2 && make install sed -i -e &#39;s/^User.*/User apache/&#39; -e &#39; s/^Group.*/Group apache/&#39; -e &#39;s/^#\(ServerName ww.*\)/\1/&#39; ${install_dir}/conf/httpd.conf
ln -s ${install_dir}/bin/* /usr/bin/
cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description&#61;The apache HTTP Server
After&#61;network.target remote-fs.target nss-lookup.target[Service]
Type&#61;forking
ExecStart&#61;${install_dir}/bin/apachectl start
ExecReload&#61;${install_dir}/bin/apachectl graceful
ExecStop&#61;${install_dir}/bin/apachectl stop
KillSignal&#61;SIGCONT
PrivateTmp&#61;true[Install]
WantedBy&#61;multi-user.target
EOF
cat >> $install_dir/conf/httpd.conf << EOF
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000$install_dir/htdocs/$1
EOF
sed -i "/[^#] DirectoryIndex/c DirectoryIndex index.html index.php " $install_dir/conf/httpd.conf
systemctl daemon-reload
systemctl enable --now httpd.service
}
install_php () {cd /rootyum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel openssl-devel oniguruma-develtar xf $PHP -C $uncompress_dir[ -d /data/www ] || mkdir -pv /data/wwwcd $uncompress_dir/${PHP%.tar.xz}./configure --prefix&#61;$php_dir --enable-mysqlnd --with-mysqli&#61;mysqlnd --with-pdo-mysql&#61;mysqlnd --with-openssl --with-zlib --with-config-file-path&#61;/etc --with-config-file-scan-dir&#61;/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfomake -j 2 && make installmkdir /etc/php.d/cp php.ini-production /etc/php.inicat > /etc/php.d/opcache.ini <<EOF
[opcache]
zend_extension&#61;opcache.so
opcache.enable&#61;1
EOF
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cp $php_dir/etc/php-fpm.conf.default $php_dir/etc/php-fpm.conf
cp $php_dir/etc/php-fpm.d/www.conf.default $php_dir/etc/php-fpm.d/www.conf
id apache &> /dev/null || useradd -s /sbin/nologin -r apache;sed -i.bak -e &#39;s/^user.*/user &#61; apache/&#39; -e &#39;s/^group.*/group &#61; apache/&#39; $php_dir/etc/php-fpm.d/www.conf
systemctl daemon-reload
systemctl start php-fpm
}
install_wordpress () {cd /roottar -xf $WORDPRESS -C $uncompress_dirmv $uncompress_dir/wordpress $install_dir/htdocs/wpchown -R apache.apache $install_dir/htdocs/wpmv $install_dir/htdocs/wp/wp-config-sample.php $install_dir/htdocs/wp/wp-config.phpmysql -uroot -p"$mysql_pass" -e "create database wordpress;create user wordpress&#64;&#39;127.0.0.1&#39; identified by &#39;$MYSQL_WORDPRESS_PASSWD&#39;; grant all on wordpress.* to wordpress&#64;&#39;127.0.0.1&#39;" &>/dev/nullsed -i.bak -e &#39;s/database_name_here/wordpress/&#39; -e &#39;s/username_here/wordpress/&#39; -e &#39;s/password_here/&#39;&#39;&#39;$MYSQL_WORDPRESS_PASSWD&#39;&#39;&#39;/&#39; -e &#39;s/localhost/127.0.0.1/&#39; $install_dir/htdocs/wp/wp-config.php
cat >> $install_dir/conf/httpd.conf << EOF
customlog "logs/access_wordpress_log" common
EOF
systemctl restart httpd
}
install_discuz () {cd /rootunzip $discuz -d $uncompress_dirmv $uncompress_dir/DiscuzX/upload/ $install_dir/htdocs/forumchown -R apache:apache $install_dir/htdocs/forummysql -uroot -p"$mysql_pass" -e "create database ultrax;create user ultrax&#64;&#39;10.0.0.%&#39; identified by &#39;$MYSQL_WORDPRESS_PASSWD&#39;; grant all on ultrax.* to ultrax&#64;&#39;10.0.0.%&#39;" &>/dev/null
cat >> $install_dir/conf/httpd.conf << EOF
customlog "logs/access_forum_log" common
EOF
systemctl restart httpd
}install_mysql
install_httpd
install_php
install_wordpress