From afb12dd664bcef3e01e2f944e5438f37fe681f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 28 Sep 2023 13:20:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20MySQL=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/plugins/mysql57/mysql57.go | 2 +- app/plugins/mysql80/mysql80.go | 2 +- scripts/mysql/install.sh | 6 +- scripts/mysql/uninstall.sh | 2 +- scripts/mysql/update.sh | 133 +++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 scripts/mysql/update.sh diff --git a/app/plugins/mysql57/mysql57.go b/app/plugins/mysql57/mysql57.go index 14c6395f..454bb423 100644 --- a/app/plugins/mysql57/mysql57.go +++ b/app/plugins/mysql57/mysql57.go @@ -4,7 +4,7 @@ var ( Name = "MySQL-5.7" Description = "MySQL 是最流行的关系型数据库管理系统之一,Oracle 旗下产品。" Slug = "mysql57" - Version = "5.7.42" + Version = "5.7.43" Requires = []string{} Excludes = []string{"mysql80"} Install = `bash /www/panel/scripts/mysql/install.sh 57` diff --git a/app/plugins/mysql80/mysql80.go b/app/plugins/mysql80/mysql80.go index a15f4067..44d16418 100644 --- a/app/plugins/mysql80/mysql80.go +++ b/app/plugins/mysql80/mysql80.go @@ -4,7 +4,7 @@ var ( Name = "MySQL-8.0" Description = "MySQL 是最流行的关系型数据库管理系统之一,Oracle 旗下产品。(内存 < 4G 无法安装)" Slug = "mysql80" - Version = "8.0.33" + Version = "8.0.34" Requires = []string{} Excludes = []string{"mysql57"} Install = `bash /www/panel/scripts/mysql/install.sh 80` diff --git a/scripts/mysql/install.sh b/scripts/mysql/install.sh index 1008243b..28d0dfc9 100644 --- a/scripts/mysql/install.sh +++ b/scripts/mysql/install.sh @@ -29,9 +29,9 @@ mysqlPassword=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16) cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l) if [[ "${1}" == "80" ]]; then - mysqlVersion="8.0.33" + mysqlVersion="8.0.34" elif [[ "${1}" == "57" ]]; then - mysqlVersion="5.7.42" + mysqlVersion="5.7.43" else echo -e $HR echo "错误:不支持的 MySQL 版本!" @@ -287,7 +287,7 @@ chmod 644 ${mysqlPath}/conf/my.cnf ${mysqlPath}/bin/mysqld --initialize-insecure --user=mysql --basedir=${mysqlPath} --datadir=${mysqlPath}/data -echo "export PATH=${mysqlPath}/bin:\$PATH" >> /etc/profile +echo "export PATH=${mysqlPath}/bin:\$PATH" >> /etc/profile.d/mysql.sh source /etc/profile # 检查 systemd 文件是否存在 diff --git a/scripts/mysql/uninstall.sh b/scripts/mysql/uninstall.sh index 63ea1b72..45ccc892 100644 --- a/scripts/mysql/uninstall.sh +++ b/scripts/mysql/uninstall.sh @@ -33,7 +33,7 @@ rm -f /usr/lib64/libmysql* userdel -r mysql groupdel mysql -sed -i '/export PATH=\/www\/server\/mysql/d' /etc/profile +rm -f /etc/profile.d/mysql.sh source /etc/profile panel deletePlugin mysql${1} diff --git a/scripts/mysql/update.sh b/scripts/mysql/update.sh new file mode 100644 index 00000000..4fcc8717 --- /dev/null +++ b/scripts/mysql/update.sh @@ -0,0 +1,133 @@ +#!/bin/bash +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH + +: ' +Copyright 2022 HaoZi Technology Co., Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +' + +HR="+----------------------------------------------------" +ARCH=$(uname -m) +memTotal=$(LC_ALL=C free -m | grep Mem | awk '{print $2}') +OS=$(source /etc/os-release && { [[ "$ID" == "debian" ]] && echo "debian"; } || { [[ "$ID" == "centos" ]] || [[ "$ID" == "rhel" ]] || [[ "$ID" == "rocky" ]] || [[ "$ID" == "almalinux" ]] && echo "centos"; } || echo "unknown") +downloadUrl="https://dl.cdn.haozi.net/panel/mysql" +setupPath="/www" +mysqlPath="${setupPath}/server/mysql" +mysqlVersion="" +mysqlPassword=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16) +cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l) + +if [[ "${1}" == "80" ]]; then + mysqlVersion="8.0.34" +elif [[ "${1}" == "57" ]]; then + mysqlVersion="5.7.43" +else + echo -e $HR + echo "错误:不支持的 MySQL 版本!" + 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 + dnf groupinstall "Development Tools" -y + dnf install cmake bison ncurses-devel libtirpc-devel openssl-devel pkg-config openldap-devel libudev-devel cyrus-sasl-devel patchelf rpcgen rpcsvc-proto-devel -y + dnf install gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc -y +elif [ "${OS}" == "debian" ]; then + apt-get update + apt-get install build-essential cmake bison libncurses5-dev libtirpc-dev libssl-dev pkg-config libldap2-dev libudev-dev libsasl2-dev patchelf -y +else + echo -e $HR + echo "错误:耗子Linux面板不支持该系统" + exit 1 +fi + +mysqlUserCheck=$(cat /etc/passwd | grep mysql) +if [ "${mysqlUserCheck}" == "" ]; then + groupadd mysql + useradd -s /sbin/nologin -g mysql mysql +fi + +# 准备目录 +rm -rf ${mysqlPath} +mkdir -p ${mysqlPath} +cd ${mysqlPath} + +# 下载源码 +wget -T 120 -O ${mysqlPath}/mysql-${mysqlVersion}.tar.gz ${downloadUrl}/mysql-boost-${mysqlVersion}.tar.gz +tar -zxvf mysql-${mysqlVersion}.tar.gz +rm -f mysql-${mysqlVersion}.tar.gz +mv mysql-${mysqlVersion} src + +# openssl +wget -T 120 -O ${mysqlPath}/openssl-1.1.1u.tar.gz ${downloadUrl}/openssl/openssl-1.1.1u.tar.gz +tar -zxvf openssl-1.1.1u.tar.gz +rm -f openssl-1.1.1u.tar.gz +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 install +echo "/usr/local/openssl-1.1/lib" > /etc/ld.so.conf.d/openssl-1.1.conf +ldconfig +cd .. +rm -rf openssl + +# 编译 +cd src +mkdir build +cd build +cmake .. -DCMAKE_INSTALL_PREFIX=${mysqlPath} -DMYSQL_DATADIR=${mysqlPath}/data -DSYSCONFDIR=${mysqlPath}/conf -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DENABLED_LOCAL_INFILE=1 -DWITH_SYSTEMD=1 -DSYSTEMD_PID_DIR=${mysqlPath} -DWITH_SSL=/usr/local/openssl-1.1 -DWITH_BOOST=../boost +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:MySQL 编译初始化失败,请截图错误信息寻求帮助。" + rm -rf ${mysqlPath} + exit 1 +fi + +if [[ "${cpuCore}" -gt "1" ]]; then + make -j2 +else + make +fi +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:MySQL 编译失败,请截图错误信息寻求帮助。" + rm -rf ${mysqlPath} + exit 1 +fi + +# 停止已有服务 +systemctl stop mysqld + +# 安装 +make install +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:MySQL 安装失败,请截图错误信息寻求帮助。" + rm -rf ${mysqlPath} + exit 1 +fi + +# 启动服务 +systemctl daemon-reload +systemctl enable mysqld + +echo -e "${HR}\nMySQL-${1} 升级完成\n${HR}"