From 0d2584c9db49495f94e28ab144c080efad7096b9 Mon Sep 17 00:00:00 2001 From: MiG Date: Sun, 19 Mar 2023 00:51:15 +0800 Subject: [PATCH] fix(install mariadb script): Unable to install mariadb for arm64 issue --- scripts/install/mariadb_for_arm64.sh | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 scripts/install/mariadb_for_arm64.sh diff --git a/scripts/install/mariadb_for_arm64.sh b/scripts/install/mariadb_for_arm64.sh new file mode 100755 index 00000000..74ee216c --- /dev/null +++ b/scripts/install/mariadb_for_arm64.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +# Copyright 2020 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. + + +# The root of the build/dist directory +IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. + +[[ -z ${COMMON_SOURCED} ]] && source ${IAM_ROOT}/scripts/install/common.sh + +# 安装后打印必要的信息 +function iam::mariadb::info() { +cat << EOF +MariaDB Login: mysql -h127.0.0.1 -u${MARIADB_ADMIN_USERNAME} -p'${MARIADB_ADMIN_PASSWORD}' +EOF +} + +# 安装 +function iam::mariadb::install() +{ + # 1. 配置 MariaDB 10.5 Yum 源 + echo ${LINUX_PASSWORD} | sudo -S bash -c "cat << 'EOF' > /etc/yum.repos.d/mariadb-10.5.repo +# MariaDB 10.5 CentOS repository list - created 2020-10-23 01:54 UTC +# http://downloads.mariadb.org/mariadb/repositories/ +[mariadb] +name = MariaDB +baseurl = https://mirrors.aliyun.com/mariadb/yum/10.5/centos8-aarch64/ +module_hotfixes=1 +gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB +gpgcheck=0 +EOF" + + # 2. 安装 boost-program-options-1.66.0-13.el8.aarch64.rpm 否则会报错 + iam::common::sudo wget https://repo.almalinux.org/almalinux/8/AppStream/aarch64/os/Packages/boost-program-options-1.66.0-13.el8.aarch64.rpm + iam::common::sudo "yum install boost-program-options-1.66.0-13.el8.aarch64.rpm" + + # 3. 安装 MariaDB 和 MariaDB 客户端 + iam::common::sudo "yum -y install MariaDB-server MariaDB-client" + + # 4. 启动 MariaDB,并设置开机启动 + iam::common::sudo "systemctl enable mariadb" + iam::common::sudo "systemctl start mariadb" + + # 5. 设置 root 初始密码 + iam::common::sudo "mysqladmin -u${MARIADB_ADMIN_USERNAME} password ${MARIADB_ADMIN_PASSWORD}" + + iam::mariadb::status || return 1 + iam::mariadb::info + iam::log::info "install MariaDB successfully" +} + +# 卸载 +function iam::mariadb::uninstall() +{ + set +o errexit + iam::common::sudo "systemctl stop mariadb" + iam::common::sudo "systemctl disable mariadb" + iam::common::sudo "yum -y remove MariaDB-server MariaDB-client" + iam::common::sudo "rm -rf /var/lib/mysql" + iam::common::sudo "rm -f /etc/yum.repos.d/mariadb-10.5.repo" + set -o errexit + iam::log::info "uninstall MariaDB successfully" +} + +# 状态检查 +function iam::mariadb::status() +{ + # 查看 mariadb 运行状态,如果输出中包含 active (running) 字样说明 mariadb 成功启动。 + systemctl status mariadb |grep -q 'active' || { + iam::log::error "mariadb failed to start, maybe not installed properly" + return 1 + } + + mysql -u${MARIADB_ADMIN_USERNAME} -p${MARIADB_ADMIN_PASSWORD} -e quit &>/dev/null || { + iam::log::error "can not login with root, mariadb maybe not initialized properly" + return 1 + } +} + +if [[ "$*" =~ iam::mariadb:: ]];then + eval $* +fi