2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 20:57:19 +08:00

feat: 优化部分软件多线程编译参数

This commit is contained in:
耗子
2023-11-21 11:13:14 +08:00
parent bb9f629b8e
commit b4ea470099
9 changed files with 110 additions and 53 deletions

59
scripts/calculate_j.sh Normal file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
: '
Copyright (C) 2022 - now HaoZi Technology Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'
# 计算 j 值(通用)
calculate_j() {
export LC_ALL=C
total_mem=$(free -m | awk '/^Mem:/{print $2}')
total_swap=$(free -m | awk '/^Swap:/{print $2}')
total=$((total_mem + total_swap))
j_value=$((total / 1024))
cpu_cores=$(nproc)
if [ $j_value -eq 0 ]; then
j_value=1
fi
if [ $j_value -gt "$cpu_cores" ]; then
j_value=$cpu_cores
fi
echo "$j_value"
}
# 计算 j 值2倍内存
calculate_j2() {
export LC_ALL=C
total_mem=$(free -m | awk '/^Mem:/{print $2}')
total_swap=$(free -m | awk '/^Swap:/{print $2}')
total=$((total_mem + total_swap))
j_value=$((total / 2024))
cpu_cores=$(nproc)
if [ $j_value -eq 0 ]; then
j_value=1
fi
if [ $j_value -gt "$cpu_cores" ]; then
j_value=$cpu_cores
fi
echo "$j_value"
}

View File

@@ -29,8 +29,12 @@ mysqlVersion=""
mysqlPassword=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16)
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
if [[ "${1}" == "80" ]]; then
mysqlVersion="8.0.35"
j=$(calculate_j2)
elif [[ "${1}" == "57" ]]; then
mysqlVersion="5.7.44"
else
@@ -39,12 +43,6 @@ else
exit 1
fi
if [[ "${memTotal}" -lt "4096" ]] && [[ "${1}" == "80" ]]; then
echo -e $HR
echo "错误:这点内存(${memTotal}M)还想装 MySQL 8.0?洗洗睡吧!"
exit 1
fi
# 安装依赖
if [ "${OS}" == "centos" ]; then
dnf makecache -y
@@ -125,11 +123,7 @@ if [ "$?" != "0" ]; then
exit 1
fi
if [[ "${cpuCore}" -gt "1" ]]; then
make -j2
else
make
fi
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误MySQL 编译失败,请截图错误信息寻求帮助。"
@@ -394,6 +388,9 @@ systemctl enable mysqld
systemctl start mysqld
${mysqlPath}/bin/mysqladmin -u root password ${mysqlPassword}
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "DROP DATABASE test;"
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "DELETE FROM mysql.user WHERE user='';"
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "FLUSH PRIVILEGES;"
panel writePlugin mysql${1} ${mysqlVersion}
panel writeMysqlPassword ${mysqlPassword}

View File

@@ -26,11 +26,15 @@ downloadUrl="https://jihulab.com/haozi-team/download/-/raw/main/panel/mysql"
setupPath="/www"
mysqlPath="${setupPath}/server/mysql"
mysqlVersion=""
mysqlPassword=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16)
mysqlPassword=$(panel getSetting mysql_root_password)
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
if [[ "${1}" == "80" ]]; then
mysqlVersion="8.0.35"
j=$(calculate_j2)
elif [[ "${1}" == "57" ]]; then
mysqlVersion="5.7.44"
else
@@ -39,12 +43,6 @@ else
exit 1
fi
if [[ "${memTotal}" -lt "4096" ]] && [[ "${1}" == "80" ]]; then
echo -e $HR
echo "错误:这点内存(${memTotal}M)还想装 MySQL 8.0?洗洗睡吧!"
exit 1
fi
# 安装依赖
if [ "${OS}" == "centos" ]; then
dnf makecache -y
@@ -60,11 +58,8 @@ else
exit 1
fi
mysqlUserCheck=$(cat /etc/passwd | grep mysql)
if [ "${mysqlUserCheck}" == "" ]; then
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
fi
# 停止已有服务
systemctl stop mysqld
# 准备目录
cd ${mysqlPath}
@@ -100,7 +95,7 @@ rm -f openssl-1.1.1u.tar.gz.checksum.txt
mv openssl-1.1.1u openssl
cd openssl
./config --prefix=/usr/local/openssl-1.1 --openssldir=/usr/local/openssl-1.1
make -j$(nproc)
make "-j${j}"
make install
echo "/usr/local/openssl-1.1/lib" > /etc/ld.so.conf.d/openssl-1.1.conf
ldconfig
@@ -118,20 +113,13 @@ if [ "$?" != "0" ]; then
exit 1
fi
if [[ "${cpuCore}" -gt "1" ]]; then
make -j2
else
make
fi
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误MySQL 编译失败,请截图错误信息寻求帮助。"
exit 1
fi
# 停止已有服务
systemctl stop mysqld
# 安装
make install
if [ "$?" != "0" ]; then
@@ -146,8 +134,13 @@ chmod -R 755 ${mysqlPath}
chmod 644 ${mysqlPath}/conf/my.cnf
# 启动服务
systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld
# 执行更新后的初始化
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "DROP DATABASE test;"
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "DELETE FROM mysql.user WHERE user='';"
${mysqlPath}/bin/mysql -uroot -p${mysqlPassword} -e "FLUSH PRIVILEGES;"
${mysqlPath}/bin/mysql_upgrade -uroot -p${mysqlPassword} --force
panel writePlugin mysql${1} ${mysqlVersion}

View File

@@ -27,6 +27,9 @@ openrestyPath="${setupPath}/server/openresty"
openrestyVersion="1.21.4.3"
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
# 安装依赖
if [ "${OS}" == "centos" ]; then
dnf makecache -y
@@ -191,7 +194,7 @@ rm -f libinjection-3.10.0.zip
rm -f libinjection-3.10.0.zip.checksum.txt
cd ../
make -j$(nproc)
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误OpenResty waf拓展初始化失败请截图错误信息寻求帮助。"
@@ -238,11 +241,7 @@ export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
export LIB_UTHASH=${openrestyPath}/src/uthash
./configure --user=www --group=www --prefix=${openrestyPath} --with-luajit --add-module=${openrestyPath}/src/ngx_cache_purge --add-module=${openrestyPath}/src/nginx-sticky-module --with-openssl=${openrestyPath}/src/openssl --with-pcre=${openrestyPath}/src/pcre --with-http_v2_module --with-http_slice_module --with-threads --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --with-cc-opt="-std=gnu99" --with-http_dav_module --add-module=${openrestyPath}/src/nginx-dav-ext-module --add-module=${openrestyPath}/src/ngx_brotli --add-module=${openrestyPath}/ngx_waf
if [[ "${cpuCore}" -gt "1" ]]; then
make -j2
else
make
fi
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误OpenResty编译失败请截图错误信息寻求帮助。"

View File

@@ -28,6 +28,9 @@ phpVersionCode=""
phpPath="${setupPath}/server/php/${phpVersion}"
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
# 安装依赖
if [ "${OS}" == "centos" ]; then
dnf install dnf-plugins-core -y
@@ -103,7 +106,7 @@ if [ "${phpVersion}" -le "80" ]; then
mv openssl-1.1.1u openssl
cd openssl
./config --prefix=/usr/local/openssl-1.1 --openssldir=/usr/local/openssl-1.1
make -j$(nproc)
make "-j${j}"
make install
echo "/usr/local/openssl-1.1/lib" > /etc/ld.so.conf.d/openssl-1.1.conf
ldconfig
@@ -123,11 +126,7 @@ else
fi
# 编译安装
if [[ "${cpuCore}" -gt "1" ]]; then
make -j2
else
make
fi
make "-j${j}"
make install
if [ ! -f "${phpPath}/bin/php" ]; then
echo -e $HR
@@ -144,7 +143,7 @@ mkdir -p ${phpPath}/etc
cd ${phpPath}/src/ext/zip
${phpPath}/bin/phpize
./configure --with-php-config=${phpPath}/bin/php-config
make -j${cpuCore}
make "-j${j}"
make install
if [ "$?" != "0" ]; then
echo -e $HR

View File

@@ -26,7 +26,9 @@ downloadUrl="https://jihulab.com/haozi-team/download/-/raw/main/panel/postgresql
setupPath="/www"
postgresqlPath="${setupPath}/server/postgresql"
postgresqlVersion=""
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
if [[ "${1}" == "15" ]]; then
postgresqlVersion="15.5"
@@ -88,7 +90,7 @@ if [ "$?" != "0" ]; then
rm -rf ${postgresqlPath}
exit 1
fi
make -j${cpuCore}
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误PostgreSQL 编译失败,请截图错误信息寻求帮助。"

View File

@@ -26,7 +26,9 @@ downloadUrl="https://jihulab.com/haozi-team/download/-/raw/main/panel/postgresql
setupPath="/www"
postgresqlPath="${setupPath}/server/postgresql"
postgresqlVersion=""
cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l)
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
if [[ "${1}" == "15" ]]; then
postgresqlVersion="15.5"
@@ -82,7 +84,7 @@ if [ "$?" != "0" ]; then
echo "错误PostgreSQL 编译初始化失败,请截图错误信息寻求帮助。"
exit 1
fi
make -j${cpuCore}
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误PostgreSQL 编译失败,请截图错误信息寻求帮助。"

View File

@@ -25,6 +25,9 @@ setupPath="/www"
pureftpdPath="${setupPath}/server/pure-ftpd"
pureftpdVersion="1.0.50"
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
# 准备安装目录
rm -rf ${pureftpdPath}
mkdir -p ${pureftpdPath}
@@ -53,7 +56,7 @@ if [ "$?" != "0" ]; then
exit 1
fi
make
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误Pure-Ftpd-${pureftpdVersion}编译失败,请截图错误信息寻求帮助。"

View File

@@ -25,6 +25,9 @@ setupPath="/www"
pureftpdPath="${setupPath}/server/pure-ftpd"
pureftpdVersion="1.0.50"
source ${setupPath}/panel/scripts/calculate_j.sh
j=$(calculate_j)
# 准备安装目录
cp ${pureftpdPath}/etc/pureftpd.passwd /tmp/pureftpd.passwd
cp ${pureftpdPath}/etc/pureftpd.pdb /tmp/pureftpd.pdb
@@ -57,7 +60,7 @@ if [ "$?" != "0" ]; then
exit 1
fi
make
make "-j${j}"
if [ "$?" != "0" ]; then
echo -e $HR
echo "错误Pure-Ftpd-${pureftpdVersion}编译失败,请截图错误信息寻求帮助。"