parent
cd6ae929e8
commit
f87fe5049b
@ -0,0 +1,437 @@ |
|||||||
|
#!/bin/bash |
||||||
|
set -eo pipefail |
||||||
|
shopt -s nullglob |
||||||
|
|
||||||
|
# logging functions |
||||||
|
mysql_log() { |
||||||
|
local type="$1"; shift |
||||||
|
# accept argument string or stdin |
||||||
|
local text="$*"; if [ "$#" -eq 0 ]; then text="$(cat)"; fi |
||||||
|
local dt; dt="$(date --rfc-3339=seconds)" |
||||||
|
printf '%s [%s] [Entrypoint]: %s\n' "$dt" "$type" "$text" |
||||||
|
} |
||||||
|
mysql_note() { |
||||||
|
mysql_log Note "$@" |
||||||
|
} |
||||||
|
mysql_warn() { |
||||||
|
mysql_log Warn "$@" >&2 |
||||||
|
} |
||||||
|
mysql_error() { |
||||||
|
mysql_log ERROR "$@" >&2 |
||||||
|
exit 1 |
||||||
|
} |
||||||
|
|
||||||
|
# usage: file_env VAR [DEFAULT] |
||||||
|
# ie: file_env 'XYZ_DB_PASSWORD' 'example' |
||||||
|
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of |
||||||
|
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) |
||||||
|
file_env() { |
||||||
|
local var="$1" |
||||||
|
local fileVar="${var}_FILE" |
||||||
|
local def="${2:-}" |
||||||
|
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then |
||||||
|
mysql_error "Both $var and $fileVar are set (but are exclusive)" |
||||||
|
fi |
||||||
|
local val="$def" |
||||||
|
if [ "${!var:-}" ]; then |
||||||
|
val="${!var}" |
||||||
|
elif [ "${!fileVar:-}" ]; then |
||||||
|
val="$(< "${!fileVar}")" |
||||||
|
fi |
||||||
|
export "$var"="$val" |
||||||
|
unset "$fileVar" |
||||||
|
} |
||||||
|
|
||||||
|
# check to see if this file is being run or sourced from another script |
||||||
|
_is_sourced() { |
||||||
|
# https://unix.stackexchange.com/a/215279 |
||||||
|
[ "${#FUNCNAME[@]}" -ge 2 ] \ |
||||||
|
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \ |
||||||
|
&& [ "${FUNCNAME[1]}" = 'source' ] |
||||||
|
} |
||||||
|
|
||||||
|
# usage: docker_process_init_files [file [file [...]]] |
||||||
|
# ie: docker_process_init_files /always-initdb.d/* |
||||||
|
# process initializer files, based on file extensions |
||||||
|
docker_process_init_files() { |
||||||
|
# mysql here for backwards compatibility "${mysql[@]}" |
||||||
|
mysql=( docker_process_sql ) |
||||||
|
|
||||||
|
echo |
||||||
|
local f |
||||||
|
for f; do |
||||||
|
case "$f" in |
||||||
|
*.sh) |
||||||
|
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 |
||||||
|
# https://github.com/docker-library/postgres/pull/452 |
||||||
|
if [ -x "$f" ]; then |
||||||
|
mysql_note "$0: running $f" |
||||||
|
"$f" |
||||||
|
else |
||||||
|
mysql_note "$0: sourcing $f" |
||||||
|
. "$f" |
||||||
|
fi |
||||||
|
;; |
||||||
|
*.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;; |
||||||
|
*.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; |
||||||
|
*.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; |
||||||
|
*) mysql_warn "$0: ignoring $f" ;; |
||||||
|
esac |
||||||
|
echo |
||||||
|
done |
||||||
|
} |
||||||
|
|
||||||
|
# arguments necessary to run "mysqld --verbose --help" successfully (used for testing configuration validity and for extracting default/configured values) |
||||||
|
_verboseHelpArgs=( |
||||||
|
--verbose --help |
||||||
|
--log-bin-index="$(mktemp -u)" # https://github.com/docker-library/mysql/issues/136 |
||||||
|
) |
||||||
|
|
||||||
|
mysql_check_config() { |
||||||
|
local toRun=( "$@" "${_verboseHelpArgs[@]}" ) errors |
||||||
|
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then |
||||||
|
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Fetch value from server config |
||||||
|
# We use mysqld --verbose --help instead of my_print_defaults because the |
||||||
|
# latter only show values present in config files, and not server defaults |
||||||
|
mysql_get_config() { |
||||||
|
local conf="$1"; shift |
||||||
|
"$@" "${_verboseHelpArgs[@]}" 2>/dev/null \ |
||||||
|
| awk -v conf="$conf" '$1 == conf && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }' |
||||||
|
# match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)" |
||||||
|
} |
||||||
|
|
||||||
|
# Do a temporary startup of the MySQL server, for init purposes |
||||||
|
docker_temp_server_start() { |
||||||
|
if [ "${MYSQL_MAJOR}" = '5.6' ] || [ "${MYSQL_MAJOR}" = '5.7' ]; then |
||||||
|
"$@" --skip-networking --default-time-zone=SYSTEM --socket="${SOCKET}" & |
||||||
|
mysql_note "Waiting for server startup" |
||||||
|
local i |
||||||
|
for i in {30..0}; do |
||||||
|
# only use the root password if the database has already been initialized |
||||||
|
# so that it won't try to fill in a password file when it hasn't been set yet |
||||||
|
extraArgs=() |
||||||
|
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then |
||||||
|
extraArgs+=( '--dont-use-mysql-root-password' ) |
||||||
|
fi |
||||||
|
if docker_process_sql "${extraArgs[@]}" --database=mysql <<<'SELECT 1' &> /dev/null; then |
||||||
|
break |
||||||
|
fi |
||||||
|
sleep 1 |
||||||
|
done |
||||||
|
if [ "$i" = 0 ]; then |
||||||
|
mysql_error "Unable to start server." |
||||||
|
fi |
||||||
|
else |
||||||
|
# For 5.7+ the server is ready for use as soon as startup command unblocks |
||||||
|
if ! "$@" --daemonize --skip-networking --default-time-zone=SYSTEM --socket="${SOCKET}"; then |
||||||
|
mysql_error "Unable to start server." |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Stop the server. When using a local socket file mysqladmin will block until |
||||||
|
# the shutdown is complete. |
||||||
|
docker_temp_server_stop() { |
||||||
|
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then |
||||||
|
mysql_error "Unable to shut down server." |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Verify that the minimally required password settings are set for new databases. |
||||||
|
docker_verify_minimum_env() { |
||||||
|
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then |
||||||
|
mysql_error <<-'EOF' |
||||||
|
Database is uninitialized and password option is not specified |
||||||
|
You need to specify one of the following: |
||||||
|
- MYSQL_ROOT_PASSWORD |
||||||
|
- MYSQL_ALLOW_EMPTY_PASSWORD |
||||||
|
- MYSQL_RANDOM_ROOT_PASSWORD |
||||||
|
EOF |
||||||
|
fi |
||||||
|
|
||||||
|
# This will prevent the CREATE USER from failing (and thus exiting with a half-initialized database) |
||||||
|
if [ "$MYSQL_USER" = 'root' ]; then |
||||||
|
mysql_error <<-'EOF' |
||||||
|
MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user |
||||||
|
Remove MYSQL_USER="root" and use one of the following to control the root user password: |
||||||
|
- MYSQL_ROOT_PASSWORD |
||||||
|
- MYSQL_ALLOW_EMPTY_PASSWORD |
||||||
|
- MYSQL_RANDOM_ROOT_PASSWORD |
||||||
|
EOF |
||||||
|
fi |
||||||
|
|
||||||
|
# warn when missing one of MYSQL_USER or MYSQL_PASSWORD |
||||||
|
if [ -n "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then |
||||||
|
mysql_warn 'MYSQL_USER specified, but missing MYSQL_PASSWORD; MYSQL_USER will not be created' |
||||||
|
elif [ -z "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ]; then |
||||||
|
mysql_warn 'MYSQL_PASSWORD specified, but missing MYSQL_USER; MYSQL_PASSWORD will be ignored' |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# creates folders for the database |
||||||
|
# also ensures permission for user mysql of run as root |
||||||
|
docker_create_db_directories() { |
||||||
|
local user; user="$(id -u)" |
||||||
|
|
||||||
|
# TODO other directories that are used by default? like /var/lib/mysql-files |
||||||
|
# see https://github.com/docker-library/mysql/issues/562 |
||||||
|
mkdir -p "$DATADIR" |
||||||
|
|
||||||
|
if [ "$user" = "0" ]; then |
||||||
|
# this will cause less disk access than `chown -R` |
||||||
|
find "$DATADIR" \! -user mysql -exec chown mysql '{}' + |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# initializes the database directory |
||||||
|
docker_init_database_dir() { |
||||||
|
mysql_note "Initializing database files" |
||||||
|
if [ "$MYSQL_MAJOR" = '5.6' ]; then |
||||||
|
mysql_install_db --datadir="$DATADIR" --rpm --keep-my-cnf "${@:2}" --default-time-zone=SYSTEM |
||||||
|
else |
||||||
|
"$@" --initialize-insecure --default-time-zone=SYSTEM |
||||||
|
fi |
||||||
|
mysql_note "Database files initialized" |
||||||
|
|
||||||
|
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then |
||||||
|
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84 |
||||||
|
mysql_note "Initializing certificates" |
||||||
|
mysql_ssl_rsa_setup --datadir="$DATADIR" |
||||||
|
mysql_note "Certificates initialized" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Loads various settings that are used elsewhere in the script |
||||||
|
# This should be called after mysql_check_config, but before any other functions |
||||||
|
docker_setup_env() { |
||||||
|
# Get config |
||||||
|
declare -g DATADIR SOCKET |
||||||
|
DATADIR="$(mysql_get_config 'datadir' "$@")" |
||||||
|
SOCKET="$(mysql_get_config 'socket' "$@")" |
||||||
|
|
||||||
|
# Initialize values that might be stored in a file |
||||||
|
file_env 'MYSQL_ROOT_HOST' '%' |
||||||
|
file_env 'MYSQL_DATABASE' |
||||||
|
file_env 'MYSQL_USER' |
||||||
|
file_env 'MYSQL_PASSWORD' |
||||||
|
file_env 'MYSQL_ROOT_PASSWORD' |
||||||
|
|
||||||
|
declare -g DATABASE_ALREADY_EXISTS |
||||||
|
if [ -d "$DATADIR/mysql" ]; then |
||||||
|
DATABASE_ALREADY_EXISTS='true' |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Execute sql script, passed via stdin |
||||||
|
# usage: docker_process_sql [--dont-use-mysql-root-password] [mysql-cli-args] |
||||||
|
# ie: docker_process_sql --database=mydb <<<'INSERT ...' |
||||||
|
# ie: docker_process_sql --dont-use-mysql-root-password --database=mydb <my-file.sql |
||||||
|
docker_process_sql() { |
||||||
|
passfileArgs=() |
||||||
|
if [ '--dont-use-mysql-root-password' = "$1" ]; then |
||||||
|
passfileArgs+=( "$1" ) |
||||||
|
shift |
||||||
|
fi |
||||||
|
# args sent in can override this db, since they will be later in the command |
||||||
|
if [ -n "$MYSQL_DATABASE" ]; then |
||||||
|
set -- --database="$MYSQL_DATABASE" "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
mysql --defaults-extra-file=<( _mysql_passfile "${passfileArgs[@]}") --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" --comments "$@" |
||||||
|
} |
||||||
|
|
||||||
|
# Initializes database with timezone info and root password, plus optional extra db/user |
||||||
|
docker_setup_db() { |
||||||
|
# Load timezone info into database |
||||||
|
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then |
||||||
|
# sed is for https://bugs.mysql.com/bug.php?id=20545 |
||||||
|
mysql_tzinfo_to_sql /usr/share/zoneinfo \ |
||||||
|
| sed 's/Local time zone must be set--see zic manual page/FCTY/' \ |
||||||
|
| docker_process_sql --dont-use-mysql-root-password --database=mysql |
||||||
|
# tell docker_process_sql to not use MYSQL_ROOT_PASSWORD since it is not set yet |
||||||
|
fi |
||||||
|
# Generate random root password |
||||||
|
if [ -n "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then |
||||||
|
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)" |
||||||
|
mysql_note "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD" |
||||||
|
fi |
||||||
|
# Sets root password and creates root users for non-localhost hosts |
||||||
|
local rootCreate= |
||||||
|
# default root to listen for connections from anywhere |
||||||
|
if [ -n "$MYSQL_ROOT_HOST" ] && [ "$MYSQL_ROOT_HOST" != 'localhost' ]; then |
||||||
|
# no, we don't care if read finds a terminating character in this heredoc |
||||||
|
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151 |
||||||
|
read -r -d '' rootCreate <<-EOSQL || true |
||||||
|
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; |
||||||
|
GRANT ALL ON *.* TO 'root'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ; |
||||||
|
EOSQL |
||||||
|
fi |
||||||
|
|
||||||
|
local passwordSet= |
||||||
|
if [ "$MYSQL_MAJOR" = '5.6' ]; then |
||||||
|
# no, we don't care if read finds a terminating character in this heredoc (see above) |
||||||
|
read -r -d '' passwordSet <<-EOSQL || true |
||||||
|
DELETE FROM mysql.user WHERE user NOT IN ('mysql.sys', 'mysqlxsys', 'root') OR host NOT IN ('localhost') ; |
||||||
|
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ; |
||||||
|
|
||||||
|
-- 5.5: https://github.com/mysql/mysql-server/blob/e48d775c6f066add457fa8cfb2ebc4d5ff0c7613/scripts/mysql_secure_installation.sh#L192-L210 |
||||||
|
-- 5.6: https://github.com/mysql/mysql-server/blob/06bc670db0c0e45b3ea11409382a5c315961f682/scripts/mysql_secure_installation.sh#L218-L236 |
||||||
|
-- 5.7: https://github.com/mysql/mysql-server/blob/913071c0b16cc03e703308250d795bc381627e37/client/mysql_secure_installation.cc#L792-L818 |
||||||
|
-- 8.0: https://github.com/mysql/mysql-server/blob/b93c1661d689c8b7decc7563ba15f6ed140a4eb6/client/mysql_secure_installation.cc#L726-L749 |
||||||
|
DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%' ; |
||||||
|
-- https://github.com/docker-library/mysql/pull/479#issuecomment-414561272 ("This is only needed for 5.5 and 5.6") |
||||||
|
EOSQL |
||||||
|
else |
||||||
|
# no, we don't care if read finds a terminating character in this heredoc (see above) |
||||||
|
read -r -d '' passwordSet <<-EOSQL || true |
||||||
|
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; |
||||||
|
EOSQL |
||||||
|
fi |
||||||
|
|
||||||
|
# tell docker_process_sql to not use MYSQL_ROOT_PASSWORD since it is just now being set |
||||||
|
docker_process_sql --dont-use-mysql-root-password --database=mysql <<-EOSQL |
||||||
|
-- What's done in this file shouldn't be replicated |
||||||
|
-- or products like mysql-fabric won't work |
||||||
|
SET @@SESSION.SQL_LOG_BIN=0; |
||||||
|
|
||||||
|
${passwordSet} |
||||||
|
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ; |
||||||
|
FLUSH PRIVILEGES ; |
||||||
|
${rootCreate} |
||||||
|
DROP DATABASE IF EXISTS test ; |
||||||
|
EOSQL |
||||||
|
|
||||||
|
# Creates a custom database and user if specified |
||||||
|
if [ -n "$MYSQL_DATABASE" ]; then |
||||||
|
mysql_note "Creating database ${MYSQL_DATABASE}" |
||||||
|
docker_process_sql --database=mysql <<<"CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ]; then |
||||||
|
mysql_note "Creating user ${MYSQL_USER}" |
||||||
|
docker_process_sql --database=mysql <<<"CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" |
||||||
|
|
||||||
|
if [ -n "$MYSQL_DATABASE" ]; then |
||||||
|
mysql_note "Giving user ${MYSQL_USER} access to schema ${MYSQL_DATABASE}" |
||||||
|
docker_process_sql --database=mysql <<<"GRANT ALL ON \`${MYSQL_DATABASE//_/\\_}\`.* TO '$MYSQL_USER'@'%' ;" |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
# 创建replication用户并授权 |
||||||
|
if [ -n "$MYSQL_REPLICATION_USER" ] && [ -n "$MYSQL_REPLICATION_PASSWORD" ]; then |
||||||
|
mysql_note "Creating user $MYSQL_REPLICATION_USER" |
||||||
|
docker_process_sql --database=mysql <<<"CREATE USER '$MYSQL_REPLICATION_USER'@'%' IDENTIFIED BY '$MYSQL_REPLICATION_PASSWORD';" |
||||||
|
docker_process_sql --database=mysql <<<"GRANT REPLICATION SLAVE,SUPER ON *.* TO '$MYSQL_REPLICATION_USER'@'%';" |
||||||
|
docker_process_sql --database=mysql <<<"FLUSH PRIVILEGES ;" |
||||||
|
fi |
||||||
|
# 创建monitor用户并授权 |
||||||
|
if [ -n "$MYSQL_MONITOR_USER" ] && [ -n "$MYSQL_MONITOR_PASSWORD" ]; then |
||||||
|
mysql_note "Creating user $MYSQL_MONITOR_USER" |
||||||
|
docker_process_sql --database=mysql <<<"CREATE USER '$MYSQL_MONITOR_USER'@'%' IDENTIFIED BY '$MYSQL_MONITOR_PASSWORD' WITH MAX_USER_CONNECTIONS 3;" |
||||||
|
docker_process_sql --database=mysql <<<"GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO '$MYSQL_MONITOR_USER'@'%';" |
||||||
|
docker_process_sql --database=mysql <<<"FLUSH PRIVILEGES ;" |
||||||
|
fi |
||||||
|
# 创建xbk用户并授权 |
||||||
|
if [ -n "$MYSQL_XBK_USER" ] && [ -n "$MYSQL_XBK_PASSWORD" ]; then |
||||||
|
mysql_note "Creating user $MYSQL_XBK_USER" |
||||||
|
docker_process_sql --database=mysql <<<"CREATE USER '$MYSQL_XBK_USER'@'%' IDENTIFIED BY '$MYSQL_XBK_PASSWORD';" |
||||||
|
docker_process_sql --database=mysql <<<"GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT,SUPER ON *.* TO '$MYSQL_XBK_USER'@'%';" |
||||||
|
docker_process_sql --database=mysql <<<"FLUSH PRIVILEGES ;" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
_mysql_passfile() { |
||||||
|
# echo the password to the "file" the client uses |
||||||
|
# the client command will use process substitution to create a file on the fly |
||||||
|
# ie: --defaults-extra-file=<( _mysql_passfile ) |
||||||
|
if [ '--dont-use-mysql-root-password' != "$1" ] && [ -n "$MYSQL_ROOT_PASSWORD" ]; then |
||||||
|
cat <<-EOF |
||||||
|
[client] |
||||||
|
password="${MYSQL_ROOT_PASSWORD}" |
||||||
|
EOF |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# Mark root user as expired so the password must be changed before anything |
||||||
|
# else can be done (only supported for 5.6+) |
||||||
|
mysql_expire_root_user() { |
||||||
|
if [ -n "$MYSQL_ONETIME_PASSWORD" ]; then |
||||||
|
docker_process_sql --database=mysql <<-EOSQL |
||||||
|
ALTER USER 'root'@'%' PASSWORD EXPIRE; |
||||||
|
EOSQL |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# check arguments for an option that would cause mysqld to stop |
||||||
|
# return true if there is one |
||||||
|
_mysql_want_help() { |
||||||
|
local arg |
||||||
|
for arg; do |
||||||
|
case "$arg" in |
||||||
|
-'?'|--help|--print-defaults|-V|--version) |
||||||
|
return 0 |
||||||
|
;; |
||||||
|
esac |
||||||
|
done |
||||||
|
return 1 |
||||||
|
} |
||||||
|
|
||||||
|
_main() { |
||||||
|
# if command starts with an option, prepend mysqld |
||||||
|
if [ "${1:0:1}" = '-' ]; then |
||||||
|
set -- mysqld "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
# skip setup if they aren't running mysqld or want an option that stops mysqld |
||||||
|
if [ "$1" = 'mysqld' ] && ! _mysql_want_help "$@"; then |
||||||
|
mysql_note "Entrypoint script for MySQL Server ${MYSQL_VERSION} started." |
||||||
|
|
||||||
|
mysql_check_config "$@" |
||||||
|
# Load various environment variables |
||||||
|
docker_setup_env "$@" |
||||||
|
docker_create_db_directories |
||||||
|
|
||||||
|
# If container is started as root user, restart as dedicated mysql user |
||||||
|
if [ "$(id -u)" = "0" ]; then |
||||||
|
mysql_note "Switching to dedicated user 'mysql'" |
||||||
|
exec gosu mysql "$BASH_SOURCE" "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
# there's no database, so it needs to be initialized |
||||||
|
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then |
||||||
|
docker_verify_minimum_env |
||||||
|
|
||||||
|
# check dir permissions to reduce likelihood of half-initialized database |
||||||
|
ls /docker-entrypoint-initdb.d/ > /dev/null |
||||||
|
|
||||||
|
docker_init_database_dir "$@" |
||||||
|
|
||||||
|
mysql_note "Starting temporary server" |
||||||
|
docker_temp_server_start "$@" |
||||||
|
mysql_note "Temporary server started." |
||||||
|
|
||||||
|
docker_setup_db |
||||||
|
docker_process_init_files /docker-entrypoint-initdb.d/* |
||||||
|
|
||||||
|
mysql_expire_root_user |
||||||
|
|
||||||
|
mysql_note "Stopping temporary server" |
||||||
|
docker_temp_server_stop |
||||||
|
mysql_note "Temporary server stopped" |
||||||
|
|
||||||
|
echo |
||||||
|
mysql_note "MySQL init process done. Ready for start up." |
||||||
|
echo |
||||||
|
fi |
||||||
|
fi |
||||||
|
exec "$@" |
||||||
|
} |
||||||
|
|
||||||
|
# If we are sourced from elsewhere, don't perform any further actions |
||||||
|
if ! _is_sourced; then |
||||||
|
_main "$@" |
||||||
|
fi |
@ -0,0 +1,52 @@ |
|||||||
|
# |
||||||
|
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" |
||||||
|
# |
||||||
|
# PLEASE DO NOT EDIT IT DIRECTLY. |
||||||
|
# |
||||||
|
|
||||||
|
FROM arm64v8/centos:centos7.9.2009 |
||||||
|
|
||||||
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
||||||
|
RUN groupadd -r mysql && useradd -r -g mysql mysql |
||||||
|
|
||||||
|
|
||||||
|
# add gosu for easy step-down from root |
||||||
|
# https://github.com/tianon/gosu/releases |
||||||
|
ENV GOSU_VERSION 1.14 |
||||||
|
RUN set -eux; \ |
||||||
|
# TODO find a better userspace architecture detection method than querying the kernel |
||||||
|
arch="$(uname -m)"; \ |
||||||
|
case "$arch" in \ |
||||||
|
aarch64) gosuArch='arm64' ;; \ |
||||||
|
x86_64) gosuArch='amd64' ;; \ |
||||||
|
*) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \ |
||||||
|
esac; \ |
||||||
|
curl -fL -o /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch.asc"; \ |
||||||
|
curl -fL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch"; \ |
||||||
|
export GNUPGHOME="$(mktemp -d)"; \ |
||||||
|
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ |
||||||
|
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ |
||||||
|
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ |
||||||
|
chmod +x /usr/local/bin/gosu; \ |
||||||
|
gosu --version; \ |
||||||
|
gosu nobody true |
||||||
|
|
||||||
|
|
||||||
|
RUN yum install -y wget && mkdir /docker-entrypoint-initdb.d |
||||||
|
COPY install-db.sh /usr/local/bin/ |
||||||
|
RUN bash /usr/local/bin/install-db.sh |
||||||
|
RUN mkdir -p /etc/mysql/conf.d/ && echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf \ |
||||||
|
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \ |
||||||
|
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \ |
||||||
|
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime |
||||||
|
&& chmod 1777 /var/run/mysqld /var/lib/mysql |
||||||
|
|
||||||
|
VOLUME /var/lib/mysql |
||||||
|
ENV MYSQL_MAJOR 5.7 |
||||||
|
ENV MYSQL_VERSION 5.7.40-1debian10 |
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/ |
||||||
|
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat |
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"] |
||||||
|
#CMD ["/bin/bash","-c","sleep 3600"] |
||||||
|
EXPOSE 3306 33060 |
||||||
|
CMD ["mysqld"] |
@ -0,0 +1,13 @@ |
|||||||
|
FROM ubuntu:20.4 |
||||||
|
MAINTAINER 1793360097@qq.com |
||||||
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
||||||
|
RUN groupadd -r mysql && useradd -r -g mysql mysql && apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr wget curl && rm -rf /var/lib/apt/lists/* && mkdir /docker-entrypoint-initdb.d |
||||||
|
|
||||||
|
COPY install-db.sh /usr/local/bin/ |
||||||
|
RUN bash /usr/local/bin/install-db.sh |
||||||
|
RUN mkdir -p /etc/mysql/conf.d/ && echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf \ |
||||||
|
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \ |
||||||
|
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \ |
||||||
|
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime |
||||||
|
&& chmod 1777 /var/run/mysqld /var/lib/mysql \ |
||||||
|
&& rm -rf /usr/local/src/* |
@ -0,0 +1,977 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
Install_LSB() { |
||||||
|
echo "[+] Installing lsb..." |
||||||
|
if [ "$PM" = "yum" ]; then |
||||||
|
yum -y install redhat-lsb |
||||||
|
elif [ "$PM" = "apt" ]; then |
||||||
|
apt-get update |
||||||
|
apt-get --no-install-recommends install -y lsb-release |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Get_Dist_Version() { |
||||||
|
if command -v lsb_release >/dev/null 2>&1; then |
||||||
|
DISTRO_Version=$(lsb_release -sr) |
||||||
|
elif [ -f /etc/lsb-release ]; then |
||||||
|
. /etc/lsb-release |
||||||
|
DISTRO_Version="$DISTRIB_RELEASE" |
||||||
|
elif [ -f /etc/os-release ]; then |
||||||
|
. /etc/os-release |
||||||
|
DISTRO_Version="$VERSION_ID" |
||||||
|
fi |
||||||
|
if [[ "${DISTRO}" == "" || "${DISTRO_Version}" == "" ]]; then |
||||||
|
if command -v python2 >/dev/null 2>&1; then |
||||||
|
DISTRO_Version=$(python2 -c 'import platform; print platform.linux_distribution()[1]') |
||||||
|
elif command -v python3 >/dev/null 2>&1; then |
||||||
|
DISTRO_Version=$(python3 -c 'import platform; print(platform.linux_distribution()[1])') |
||||||
|
else |
||||||
|
Install_LSB |
||||||
|
DISTRO_Version=$(lsb_release -rs) |
||||||
|
fi |
||||||
|
fi |
||||||
|
printf -v "${DISTRO}_Version" '%s' "${DISTRO_Version}" |
||||||
|
} |
||||||
|
|
||||||
|
Get_RHEL_Version() { |
||||||
|
Get_Dist_Name |
||||||
|
if [ "${DISTRO}" = "RHEL" ]; then |
||||||
|
if grep -Eqi "release 5." /etc/redhat-release; then |
||||||
|
echo "Current Version: RHEL Ver 5" |
||||||
|
RHEL_Ver='5' |
||||||
|
elif grep -Eqi "release 6." /etc/redhat-release; then |
||||||
|
echo "Current Version: RHEL Ver 6" |
||||||
|
RHEL_Ver='6' |
||||||
|
elif grep -Eqi "release 7." /etc/redhat-release; then |
||||||
|
echo "Current Version: RHEL Ver 7" |
||||||
|
RHEL_Ver='7' |
||||||
|
elif grep -Eqi "release 8." /etc/redhat-release; then |
||||||
|
echo "Current Version: RHEL Ver 8" |
||||||
|
RHEL_Ver='8' |
||||||
|
fi |
||||||
|
RHEL_Version="$(cat /etc/redhat-release | sed 's/.*release\ //' | sed 's/\ .*//')" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Get_OS_Bit() { |
||||||
|
if [[ $(getconf WORD_BIT) == '32' && $(getconf LONG_BIT) == '64' ]]; then |
||||||
|
Is_64bit='y' |
||||||
|
ARCH='x86_64' |
||||||
|
DB_ARCH='x86_64' |
||||||
|
else |
||||||
|
Is_64bit='n' |
||||||
|
ARCH='i386' |
||||||
|
DB_ARCH='i686' |
||||||
|
fi |
||||||
|
|
||||||
|
if uname -m | grep -Eqi "arm|aarch64"; then |
||||||
|
Is_ARM='y' |
||||||
|
if uname -m | grep -Eqi "armv7|armv6"; then |
||||||
|
ARCH='armhf' |
||||||
|
elif uname -m | grep -Eqi "aarch64"; then |
||||||
|
ARCH='aarch64' |
||||||
|
else |
||||||
|
ARCH='arm' |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Get_Dist_Name() { |
||||||
|
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then |
||||||
|
DISTRO='CentOS' |
||||||
|
PM='yum' |
||||||
|
if grep -Eq "CentOS Stream" /etc/*-release; then |
||||||
|
isCentosStream='y' |
||||||
|
fi |
||||||
|
elif grep -Eqi "Alibaba" /etc/issue || grep -Eq "Alibaba Cloud Linux" /etc/*-release; then |
||||||
|
DISTRO='Alibaba' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun Linux" /etc/*-release; then |
||||||
|
DISTRO='Aliyun' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; then |
||||||
|
DISTRO='Amazon' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then |
||||||
|
DISTRO='Fedora' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Oracle Linux" /etc/issue || grep -Eq "Oracle Linux" /etc/*-release; then |
||||||
|
DISTRO='Oracle' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; then |
||||||
|
DISTRO='RHEL' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "rockylinux" /etc/issue || grep -Eq "Rocky Linux" /etc/*-release; then |
||||||
|
DISTRO='Rocky' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "almalinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then |
||||||
|
DISTRO='Alma' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "openEuler" /etc/issue || grep -Eq "openEuler" /etc/*-release; then |
||||||
|
DISTRO='openEuler' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Anolis OS" /etc/issue || grep -Eq "Anolis OS" /etc/*-release; then |
||||||
|
DISTRO='Anolis' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Kylin Linux Advanced Server" /etc/issue || grep -Eq "Kylin Linux Advanced Server" /etc/*-release; then |
||||||
|
DISTRO='Kylin' |
||||||
|
PM='yum' |
||||||
|
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then |
||||||
|
DISTRO='Debian' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then |
||||||
|
DISTRO='Ubuntu' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then |
||||||
|
DISTRO='Raspbian' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then |
||||||
|
DISTRO='Deepin' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "Mint" /etc/issue || grep -Eq "Mint" /etc/*-release; then |
||||||
|
DISTRO='Mint' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "Kali" /etc/issue || grep -Eq "Kali" /etc/*-release; then |
||||||
|
DISTRO='Kali' |
||||||
|
PM='apt' |
||||||
|
elif grep -Eqi "UnionTech OS" /etc/issue || grep -Eq "UnionTech OS" /etc/*-release; then |
||||||
|
DISTRO='UOS' |
||||||
|
if command -v apt >/dev/null 2>&1; then |
||||||
|
PM='apt' |
||||||
|
elif command -v yum >/dev/null 2>&1; then |
||||||
|
PM='yum' |
||||||
|
fi |
||||||
|
elif grep -Eqi "Kylin Linux Desktop" /etc/issue || grep -Eq "Kylin Linux Desktop" /etc/*-release; then |
||||||
|
DISTRO='Kylin' |
||||||
|
PM='yum' |
||||||
|
else |
||||||
|
DISTRO='unknow' |
||||||
|
fi |
||||||
|
Get_OS_Bit |
||||||
|
} |
||||||
|
|
||||||
|
Check_DB() { |
||||||
|
if [[ -s /usr/local/mariadb/bin/mysql && -s /usr/local/mariadb/bin/mysqld_safe && -s /etc/my.cnf ]]; then |
||||||
|
MySQL_Bin="/usr/local/mariadb/bin/mysql" |
||||||
|
MySQL_Config="/usr/local/mariadb/bin/mysql_config" |
||||||
|
MySQL_Dir="/usr/local/mariadb" |
||||||
|
Is_MySQL="n" |
||||||
|
DB_Name="mariadb" |
||||||
|
elif [[ -s /usr/local/mysql/bin/mysql && -s /usr/local/mysql/bin/mysqld_safe && -s /etc/my.cnf ]]; then |
||||||
|
MySQL_Bin="/usr/local/mysql/bin/mysql" |
||||||
|
MySQL_Config="/usr/local/mysql/bin/mysql_config" |
||||||
|
MySQL_Dir="/usr/local/mysql" |
||||||
|
Is_MySQL="y" |
||||||
|
DB_Name="mysql" |
||||||
|
else |
||||||
|
Is_MySQL="None" |
||||||
|
DB_Name="None" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Press_Install() { |
||||||
|
Boost_Ver='boost_1_59_0' |
||||||
|
Boost_New_Ver='boost_1_67_0' |
||||||
|
Openssl_Ver='openssl-1.0.2u' |
||||||
|
Openssl_New_Ver='openssl-1.1.1o' |
||||||
|
if [ "${DBSelect}" = "1" ]; then |
||||||
|
Mysql_Ver='mysql-5.1.73' |
||||||
|
elif [ "${DBSelect}" = "2" ]; then |
||||||
|
Mysql_Ver='mysql-5.5.62' |
||||||
|
elif [ "${DBSelect}" = "3" ]; then |
||||||
|
Mysql_Ver='mysql-5.6.51' |
||||||
|
elif [ "${DBSelect}" = "4" ]; then |
||||||
|
Mysql_Ver='mysql-5.7.38' |
||||||
|
elif [ "${DBSelect}" = "5" ]; then |
||||||
|
Mysql_Ver='mysql-8.0.30' |
||||||
|
elif [ "${DBSelect}" = "6" ]; then |
||||||
|
Mariadb_Ver='mariadb-5.5.68' |
||||||
|
elif [ "${DBSelect}" = "7" ]; then |
||||||
|
Mariadb_Ver='mariadb-10.3.35' |
||||||
|
elif [ "${DBSelect}" = "8" ]; then |
||||||
|
Mariadb_Ver='mariadb-10.4.25' |
||||||
|
elif [ "${DBSelect}" = "9" ]; then |
||||||
|
Mariadb_Ver='mariadb-10.5.16' |
||||||
|
elif [ "${DBSelect}" = "10" ]; then |
||||||
|
Mariadb_Ver='mariadb-10.6.8' |
||||||
|
fi |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
Database_Selection() { |
||||||
|
#which MySQL Version do you want to install? |
||||||
|
if [ -z ${DBSelect} ]; then |
||||||
|
Echo_Yellow "You have 11 options for your DataBase install." |
||||||
|
echo "1: Install ${DB_Info[0]}" |
||||||
|
echo "2: Install ${DB_Info[1]}" |
||||||
|
echo "3: Install ${DB_Info[2]}" |
||||||
|
echo "4: Install ${DB_Info[3]}" |
||||||
|
echo "5: Install ${DB_Info[4]}" |
||||||
|
echo "6: Install ${DB_Info[5]}" |
||||||
|
echo "7: Install ${DB_Info[6]}" |
||||||
|
echo "8: Install ${DB_Info[7]}" |
||||||
|
echo "9: Install ${DB_Info[8]}" |
||||||
|
echo "10: Install ${DB_Info[9]}" |
||||||
|
echo "0: DO NOT Install MySQL/MariaDB" |
||||||
|
#read -p "Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 0): " DBSelect |
||||||
|
DBSelect='4' |
||||||
|
Bin='n' |
||||||
|
fi |
||||||
|
|
||||||
|
case "${DBSelect}" in |
||||||
|
1) |
||||||
|
echo "You will install ${DB_Info[0]}" |
||||||
|
;; |
||||||
|
2) |
||||||
|
echo "You will install ${DB_Info[1]}" |
||||||
|
;; |
||||||
|
3) |
||||||
|
echo "You will Install ${DB_Info[2]}" |
||||||
|
;; |
||||||
|
4) |
||||||
|
if [[ "${ARCH}" == "x86_64" || "${ARCH}" == "i386" ]]; then |
||||||
|
if [ -z ${Bin} ]; then |
||||||
|
read -p "Using Generic Binaries [y/n]: " Bin |
||||||
|
fi |
||||||
|
case "${Bin}" in |
||||||
|
[yY][eE][sS] | [yY]) |
||||||
|
echo "You will install ${DB_Info[3]} Using Generic Binaries." |
||||||
|
Bin="y" |
||||||
|
;; |
||||||
|
[nN][oO] | [nN]) |
||||||
|
echo "You will install ${DB_Info[3]} from Source." |
||||||
|
Bin="n" |
||||||
|
;; |
||||||
|
*) |
||||||
|
if [ "${CheckMirror}" != "n" ]; then |
||||||
|
echo "Default install ${DB_Info[3]} Using Generic Binaries." |
||||||
|
Bin="y" |
||||||
|
else |
||||||
|
echo "Default install ${DB_Info[3]} from Source." |
||||||
|
Bin="n" |
||||||
|
fi |
||||||
|
;; |
||||||
|
esac |
||||||
|
else |
||||||
|
Bin="n" |
||||||
|
fi |
||||||
|
;; |
||||||
|
5) |
||||||
|
if [[ "${ARCH}" == "x86_64" || "${ARCH}" == "i386" ]]; then |
||||||
|
if [ -z ${Bin} ]; then |
||||||
|
read -p "Using Generic Binaries [y/n]: " Bin |
||||||
|
fi |
||||||
|
case "${Bin}" in |
||||||
|
[yY][eE][sS] | [yY]) |
||||||
|
echo "You will install ${DB_Info[4]} Using Generic Binaries." |
||||||
|
Bin="y" |
||||||
|
;; |
||||||
|
[nN][oO] | [nN]) |
||||||
|
echo "You will install ${DB_Info[4]} from Source." |
||||||
|
Bin="n" |
||||||
|
;; |
||||||
|
*) |
||||||
|
if [ "${CheckMirror}" != "n" ]; then |
||||||
|
echo "Default install ${DB_Info[4]} Using Generic Binaries." |
||||||
|
Bin="y" |
||||||
|
else |
||||||
|
echo "Default install ${DB_Info[4]} from Source." |
||||||
|
Bin="n" |
||||||
|
fi |
||||||
|
;; |
||||||
|
esac |
||||||
|
else |
||||||
|
Bin="n" |
||||||
|
fi |
||||||
|
;; |
||||||
|
6) |
||||||
|
echo "You will install ${DB_Info[5]}" |
||||||
|
;; |
||||||
|
7) |
||||||
|
echo "You will install ${DB_Info[6]}" |
||||||
|
;; |
||||||
|
8) |
||||||
|
echo "You will install ${DB_Info[7]}" |
||||||
|
;; |
||||||
|
9) |
||||||
|
echo "You will install ${DB_Info[8]}" |
||||||
|
;; |
||||||
|
10) |
||||||
|
echo "You will install ${DB_Info[9]}" |
||||||
|
;; |
||||||
|
0) |
||||||
|
echo "Do not install MySQL/MariaDB!" |
||||||
|
;; |
||||||
|
*) |
||||||
|
echo "No input,You will install ${DB_Info[1]}" |
||||||
|
DBSelect="2" |
||||||
|
;; |
||||||
|
esac |
||||||
|
|
||||||
|
if [ "${Bin}" != "y" ] && [[ "${DBSelect}" =~ ^5|[7-9]|10$ ]] && [ $(free -m | grep Mem | awk '{print $2}') -le 1024 ]; then |
||||||
|
echo "Memory less than 1GB, can't install MySQL 8.0 or MairaDB 10.3+!" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
if [[ "${DBSelect}" =~ ^[6789]|10$ ]]; then |
||||||
|
MySQL_Bin="/usr/local/mariadb/bin/mysql" |
||||||
|
MySQL_Config="/usr/local/mariadb/bin/mysql_config" |
||||||
|
MySQL_Dir="/usr/local/mariadb" |
||||||
|
elif [[ "${DBSelect}" =~ ^[12345]$ ]]; then |
||||||
|
MySQL_Bin="/usr/local/mysql/bin/mysql" |
||||||
|
MySQL_Config="/usr/local/mysql/bin/mysql_config" |
||||||
|
MySQL_Dir="/usr/local/mysql" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Download_Files() { |
||||||
|
local URL=$1 |
||||||
|
local FileName=$2 |
||||||
|
if [ -s "${FileName}" ]; then |
||||||
|
echo "${FileName} [found]" |
||||||
|
else |
||||||
|
echo "Notice: ${FileName} not found!!!download now..." |
||||||
|
wget -c --progress=bar:force --prefer-family=IPv4 --no-check-certificate ${URL} |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Check_PowerTools() { |
||||||
|
if ! yum -v repolist all | grep "PowerTools"; then |
||||||
|
echo "PowerTools repository not found!" |
||||||
|
fi |
||||||
|
repo_id=$(yum repolist all | grep -Ei "PowerTools" | head -n 1 | awk '{print $1}') |
||||||
|
} |
||||||
|
|
||||||
|
Check_Codeready() { |
||||||
|
repo_id=$(yum repolist all | grep -E "CodeReady" | head -n 1 | awk '{print $1}') |
||||||
|
[ -z "${repo_id}" ] && repo_id="ol8_codeready_builder" |
||||||
|
} |
||||||
|
|
||||||
|
Tar_Cd() { |
||||||
|
local FileName=$1 |
||||||
|
local DirName=$2 |
||||||
|
cd ${cur_dir}/src |
||||||
|
[[ -d "${DirName}" ]] && rm -rf ${DirName} |
||||||
|
echo "Uncompress ${FileName}..." |
||||||
|
tar zxf ${FileName} |
||||||
|
if [ -n "${DirName}" ]; then |
||||||
|
echo "cd ${DirName}..." |
||||||
|
cd ${DirName} |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Color_Text() { |
||||||
|
echo -e " \e[0;$2m$1\e[0m" |
||||||
|
} |
||||||
|
|
||||||
|
Echo_Red() { |
||||||
|
echo $(Color_Text "$1" "31") |
||||||
|
} |
||||||
|
|
||||||
|
Echo_Green() { |
||||||
|
echo $(Color_Text "$1" "32") |
||||||
|
} |
||||||
|
|
||||||
|
Echo_Yellow() { |
||||||
|
echo $(Color_Text "$1" "33") |
||||||
|
} |
||||||
|
|
||||||
|
Echo_Blue() { |
||||||
|
echo $(Color_Text "$1" "34") |
||||||
|
} |
||||||
|
|
||||||
|
DB_Dependent() { |
||||||
|
if [ "$PM" = "yum" ]; then |
||||||
|
yum -y remove mysql-server mysql mysql-libs mariadb-server mariadb mariadb-libs |
||||||
|
rpm -qa | grep mysql |
||||||
|
if [ $? -ne 0 ]; then |
||||||
|
rpm -e mysql mysql-libs --nodeps |
||||||
|
rpm -e mariadb mariadb-libs --nodeps |
||||||
|
fi |
||||||
|
for packages in make cmake gcc gcc-c++ gcc-g77 flex bison wget zlib zlib-devel openssl openssl-devel ncurses ncurses-devel libaio-devel rpcgen libtirpc-devel patch cyrus-sasl-devel pkg-config pcre-devel libxml2-devel hostname ncurses-libs numactl-devel libxcrypt; do yum -y install $packages; done |
||||||
|
if echo "${CentOS_Version}" | grep -Eqi "^8" || echo "${RHEL_Version}" | grep -Eqi "^8" || echo "${Rocky_Version}" | grep -Eqi "^8" || echo "${Alma_Version}" | grep -Eqi "^8"; then |
||||||
|
Check_PowerTools |
||||||
|
dnf --enablerepo=${repo_id} install rpcgen -y |
||||||
|
dnf install libarchive -y |
||||||
|
|
||||||
|
dnf install gcc-toolset-10 -y |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "${DISTRO}" = "Oracle" ] && echo "${Oracle_Version}" | grep -Eqi "^8"; then |
||||||
|
Check_Codeready |
||||||
|
dnf --enablerepo=${repo_id} install rpcgen re2c -y |
||||||
|
dnf install libarchive -y |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "${DISTRO}" = "Fedora" ] || echo "${CentOS_Version}" | grep -Eqi "^9" || echo "${Alma_Version}" | grep -Eqi "^9" || echo "${Rocky_Version}" | grep -Eqi "^9"; then |
||||||
|
dnf install chkconfig -y |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -s /usr/lib64/libtinfo.so.6 ]; then |
||||||
|
ln -sf /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5 |
||||||
|
elif [ -s /usr/lib/libtinfo.so.6 ]; then |
||||||
|
ln -sf /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5 |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -s /usr/lib64/libncurses.so.6 ]; then |
||||||
|
ln -sf /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5 |
||||||
|
elif [ -s /usr/lib/libncurses.so.6 ]; then |
||||||
|
ln -sf /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5 |
||||||
|
fi |
||||||
|
elif [ "$PM" = "apt" ]; then |
||||||
|
export DEBIAN_FRONTEND=noninteractive |
||||||
|
apt-get update -y |
||||||
|
[[ $? -ne 0 ]] && apt-get update --allow-releaseinfo-change -y |
||||||
|
for removepackages in mysql-client mysql-server mysql-common mysql-server-core-5.5 mysql-client-5.5 mariadb-client mariadb-server mariadb-common; do apt-get purge -y $removepackages; done |
||||||
|
dpkg -l | grep mysql |
||||||
|
dpkg -P mysql-server mysql-common libmysqlclient15off libmysqlclient15-dev |
||||||
|
dpkg -P mariadb-client mariadb-server mariadb-common |
||||||
|
for packages in debian-keyring debian-archive-keyring build-essential gcc g++ make cmake autoconf automake wget openssl libssl-dev zlib1g zlib1g-dev libncurses5 libncurses5-dev bison libaio-dev libtirpc-dev libsasl2-dev pkg-config libpcre2-dev libxml2-dev libtinfo-dev libnuma-dev gnutls-dev; do apt-get --no-install-recommends install -y $packages; done |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Check_Openssl() { |
||||||
|
if ! command -v openssl >/dev/null 2>&1; then |
||||||
|
Echo_Blue "[+] Installing openssl..." |
||||||
|
if [ "${PM}" = "yum" ]; then |
||||||
|
yum install -y ntpdate |
||||||
|
elif [ "${PM}" = "apt" ]; then |
||||||
|
apt-get update -y |
||||||
|
[[ $? -ne 0 ]] && apt-get update --allow-releaseinfo-change -y |
||||||
|
apt-get install -y openssl |
||||||
|
fi |
||||||
|
fi |
||||||
|
openssl version |
||||||
|
if openssl version | grep -Eqi "OpenSSL 3.*"; then |
||||||
|
isOpenSSL3='y' |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Download_Boost() { |
||||||
|
echo "[+] Download or use exist boost..." |
||||||
|
if [ "${DBSelect}" = "4" ] || echo "${mysql_version}" | grep -Eqi '^5.7.'; then |
||||||
|
if [ -s "${cur_dir}/src/${Boost_Ver}.tar.bz2" ]; then |
||||||
|
[[ -d "${cur_dir}/src/${Boost_Ver}" ]] && rm -rf "${cur_dir}/src/${Boost_Ver}" |
||||||
|
tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2 -C ${cur_dir}/src |
||||||
|
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}" |
||||||
|
else |
||||||
|
cd ${cur_dir}/src/ |
||||||
|
Download_Files ${Download_Mirror}/lib/boost/${Boost_Ver}.tar.bz2 ${Boost_Ver}.tar.bz2 |
||||||
|
tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2 |
||||||
|
cd - |
||||||
|
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}" |
||||||
|
fi |
||||||
|
elif [ "${DBSelect}" = "5" ] || echo "${mysql_version}" | grep -Eqi '^8.0.'; then |
||||||
|
Get_Boost_Ver=$(grep 'SET(BOOST_PACKAGE_NAME' cmake/boost.cmake | grep -oP '\d+(\_\d+){2}') |
||||||
|
if [ -s "${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2" ]; then |
||||||
|
[[ -d "${cur_dir}/src/boost_${Get_Boost_Ver}" ]] && rm -rf "${cur_dir}/src/boost_${Get_Boost_Ver}" |
||||||
|
tar jxf ${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2 -C ${cur_dir}/src |
||||||
|
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/boost_${Get_Boost_Ver}" |
||||||
|
else |
||||||
|
MySQL_WITH_BOOST="-DDOWNLOAD_BOOST=1 -DWITH_BOOST=${cur_dir}/src" |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Install_Boost() { |
||||||
|
echo "[+] Download or use exist boost..." |
||||||
|
if [ "${DBSelect}" = "4" ] || [ "${DBSelect}" = "5" ]; then |
||||||
|
if [ -d "${cur_dir}/src/${Mysql_Ver}/boost" ]; then |
||||||
|
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Mysql_Ver}/boost" |
||||||
|
else |
||||||
|
Download_Boost |
||||||
|
fi |
||||||
|
elif echo "${mysql_version}" | grep -Eqi '^5.7.' || echo "${mysql_version}" | grep -Eqi '^8.0.'; then |
||||||
|
if [ -d "${cur_dir}/src/mysql-${mysql_version}/boost" ]; then |
||||||
|
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/mysql-${mysql_version}/boost" |
||||||
|
else |
||||||
|
Download_Boost |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Make_Install() { |
||||||
|
make -j $(grep 'processor' /proc/cpuinfo | wc -l) |
||||||
|
if [ $? -ne 0 ]; then |
||||||
|
make |
||||||
|
fi |
||||||
|
make install |
||||||
|
} |
||||||
|
|
||||||
|
MySQL_Sec_Setting() { |
||||||
|
if [ -d "/proc/vz" ]; then |
||||||
|
ulimit -s unlimited |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -d "/etc/mysql" ]; then |
||||||
|
mv /etc/mysql /etc/mysql.backup.$(date +%Y%m%d) |
||||||
|
fi |
||||||
|
ln -sf /usr/local/mysql/bin/* /usr/local/bin/ |
||||||
|
#ln -sf /usr/local/mysql/bin/mysqld /usr/bin/mysqld |
||||||
|
#ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql |
||||||
|
#ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump |
||||||
|
#ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk |
||||||
|
# ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe |
||||||
|
# ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck |
||||||
|
} |
||||||
|
|
||||||
|
Check_MySQL_Data_Dir() { |
||||||
|
if [ -d "${MySQL_Data_Dir}" ]; then |
||||||
|
datetime=$(date +"%Y%m%d%H%M%S") |
||||||
|
mkdir -p /root/mysql-data-dir-backup${datetime}/ |
||||||
|
\cp ${MySQL_Data_Dir}/* /root/mysql-data-dir-backup${datetime}/ |
||||||
|
rm -rf ${MySQL_Data_Dir}/* |
||||||
|
else |
||||||
|
mkdir -p ${MySQL_Data_Dir} |
||||||
|
fi |
||||||
|
} |
||||||
|
Install_MySQL_51() { |
||||||
|
echo "[+] Installing ${Mysql_Ver}..." |
||||||
|
rm -f /etc/my.cnf |
||||||
|
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver} |
||||||
|
MySQL_Gcc7_Patch |
||||||
|
if [ "${InstallInnodb}" = "y" ]; then |
||||||
|
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase ${MySQL51MAOpt} |
||||||
|
else |
||||||
|
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile ${MySQL51MAOpt} |
||||||
|
fi |
||||||
|
sed -i '/set -ex;/,/done/d' Makefile |
||||||
|
Make_Install |
||||||
|
Check_MySQL_Data_Dir |
||||||
|
chown -R mysql:mysql /usr/local/mysql |
||||||
|
chown -R mysql:mysql ${MySQL_Data_Dir} |
||||||
|
|
||||||
|
cat >/etc/ld.so.conf.d/mysql.conf <<EOF |
||||||
|
/usr/local/mysql/lib/mysql |
||||||
|
/usr/local/lib |
||||||
|
EOF |
||||||
|
ldconfig |
||||||
|
|
||||||
|
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql |
||||||
|
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql |
||||||
|
|
||||||
|
MySQL_Sec_Setting |
||||||
|
} |
||||||
|
|
||||||
|
Install_MySQL_55() { |
||||||
|
echo "[+] Installing ${Mysql_Ver}..." |
||||||
|
rm -f /etc/my.cnf |
||||||
|
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver} |
||||||
|
MySQL_ARM_Patch |
||||||
|
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 |
||||||
|
Make_Install |
||||||
|
|
||||||
|
Check_MySQL_Data_Dir |
||||||
|
cat >/etc/ld.so.conf.d/mysql.conf <<EOF |
||||||
|
/usr/local/mysql/lib |
||||||
|
/usr/local/lib |
||||||
|
EOF |
||||||
|
ldconfig |
||||||
|
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql |
||||||
|
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql |
||||||
|
|
||||||
|
MySQL_Sec_Setting |
||||||
|
} |
||||||
|
|
||||||
|
Install_MySQL_56() { |
||||||
|
echo "[+] Installing ${Mysql_Ver}..." |
||||||
|
rm -f /etc/my.cnf |
||||||
|
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver} |
||||||
|
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 |
||||||
|
Make_Install |
||||||
|
|
||||||
|
Check_MySQL_Data_Dir |
||||||
|
chown -R mysql:mysql /usr/local/mysql |
||||||
|
cat >/etc/ld.so.conf.d/mysql.conf <<EOF |
||||||
|
/usr/local/mysql/lib |
||||||
|
/usr/local/lib |
||||||
|
EOF |
||||||
|
ldconfig |
||||||
|
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql |
||||||
|
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql |
||||||
|
|
||||||
|
MySQL_Sec_Setting |
||||||
|
} |
||||||
|
|
||||||
|
Install_MySQL_57() { |
||||||
|
rm -f /etc/my.cnf |
||||||
|
if [ "${Bin}" = "y" ]; then |
||||||
|
echo "[+] Installing ${Mysql_Ver} Using Generic Binaries..." |
||||||
|
Tar_Cd ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz |
||||||
|
mkdir /usr/local/mysql |
||||||
|
mv ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}/* /usr/local/mysql/ |
||||||
|
else |
||||||
|
echo "[+] Installing ${Mysql_Ver} Using Source code..." |
||||||
|
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver} |
||||||
|
Install_Boost |
||||||
|
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 ${MySQL_WITH_BOOST} |
||||||
|
Make_Install |
||||||
|
fi |
||||||
|
Check_MySQL_Data_Dir |
||||||
|
chown -R mysql:mysql /usr/local/mysql |
||||||
|
cat >/etc/ld.so.conf.d/mysql.conf <<EOF |
||||||
|
/usr/local/mysql/lib |
||||||
|
/usr/local/lib |
||||||
|
EOF |
||||||
|
ldconfig |
||||||
|
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql |
||||||
|
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql |
||||||
|
|
||||||
|
MySQL_Sec_Setting |
||||||
|
} |
||||||
|
|
||||||
|
Install_MySQL_80() { |
||||||
|
rm -f /etc/my.cnf |
||||||
|
if [ "${Bin}" = "y" ]; then |
||||||
|
echo "[+] Installing ${Mysql_Ver} Using Generic Binaries..." |
||||||
|
TarJ_Cd ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz |
||||||
|
mkdir /usr/local/mysql |
||||||
|
mv ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}/* /usr/local/mysql/ |
||||||
|
else |
||||||
|
echo "[+] Installing ${Mysql_Ver} Using Source code..." |
||||||
|
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver} |
||||||
|
if openssl version | grep -Eqi "OpenSSL 3.*"; then |
||||||
|
echo "OpenSSL 3.x" |
||||||
|
patch -p1 <${cur_dir}/src/patch/mysql-openssl3.patch |
||||||
|
fi |
||||||
|
Install_Boost |
||||||
|
mkdir build && cd build |
||||||
|
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 ${MySQL_WITH_BOOST} |
||||||
|
Make_Install |
||||||
|
fi |
||||||
|
Check_MySQL_Data_Dir |
||||||
|
chown -R mysql:mysql /usr/local/mysql |
||||||
|
|
||||||
|
cat >/etc/ld.so.conf.d/mysql.conf <<EOF |
||||||
|
/usr/local/mysql/lib |
||||||
|
/usr/local/lib |
||||||
|
EOF |
||||||
|
ldconfig |
||||||
|
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql |
||||||
|
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql |
||||||
|
|
||||||
|
MySQL_Sec_Setting |
||||||
|
} |
||||||
|
|
||||||
|
TempMycnf_Clean() { |
||||||
|
if [ -s ~/.my.cnf ]; then |
||||||
|
rm -f ~/.my.cnf |
||||||
|
fi |
||||||
|
if [ -s /tmp/.mysql.tmp ]; then |
||||||
|
rm -f /tmp/.mysql.tmp |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Modify_Source() |
||||||
|
{ |
||||||
|
if [ "${DISTRO}" = "RHEL" ]; then |
||||||
|
RHEL_Modify_Source |
||||||
|
elif [ "${DISTRO}" = "Ubuntu" ]; then |
||||||
|
Ubuntu_Modify_Source |
||||||
|
elif [ "${DISTRO}" = "CentOS" ]; then |
||||||
|
CentOS6_Modify_Source |
||||||
|
CentOS8_Modify_Source |
||||||
|
fi |
||||||
|
} |
||||||
|
RHEL_Modify_Source() |
||||||
|
{ |
||||||
|
Get_RHEL_Version |
||||||
|
if [ "${RHELRepo}" = "local" ]; then |
||||||
|
echo "DO NOT change RHEL repository, use the repository you set." |
||||||
|
else |
||||||
|
echo "RHEL ${RHEL_Ver} will use aliyun centos repository..." |
||||||
|
if [ ! -s "/etc/yum.repos.d/Centos-${RHEL_Ver}.repo" ]; then |
||||||
|
if command -v curl >/dev/null 2>&1; then |
||||||
|
curl http://mirrors.aliyun.com/repo/Centos-${RHEL_Ver}.repo -o /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
else |
||||||
|
wget --prefer-family=IPv4 http://mirrors.aliyun.com/repo/Centos-${RHEL_Ver}.repo -O /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
fi |
||||||
|
fi |
||||||
|
if echo "${RHEL_Version}" | grep -Eqi "^6"; then |
||||||
|
sed -i "s#centos/\$releasever#centos-vault/\$releasever#g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
sed -i "s/\$releasever/${RHEL_Version}/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
elif echo "${RHEL_Version}" | grep -Eqi "^7"; then |
||||||
|
sed -i "s/\$releasever/7/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
elif echo "${RHEL_Version}" | grep -Eqi "^8"; then |
||||||
|
sed -i "s#centos/\$releasever#centos-vault/8.5.2111#g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo |
||||||
|
fi |
||||||
|
yum clean all |
||||||
|
yum makecache |
||||||
|
fi |
||||||
|
sed -i "s/^enabled[ ]*=[ ]*1/enabled=0/" /etc/yum/pluginconf.d/subscription-manager.conf |
||||||
|
} |
||||||
|
|
||||||
|
Ubuntu_Modify_Source() |
||||||
|
{ |
||||||
|
if [ "${country}" = "CN" ]; then |
||||||
|
OldReleasesURL='http://mirrors.aliyun.com/oldubuntu-releases/ubuntu/' |
||||||
|
else |
||||||
|
OldReleasesURL='http://old-releases.ubuntu.com/ubuntu/' |
||||||
|
fi |
||||||
|
CodeName='' |
||||||
|
if grep -Eqi "10.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.10'; then |
||||||
|
CodeName='maverick' |
||||||
|
elif grep -Eqi "11.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.04'; then |
||||||
|
CodeName='natty' |
||||||
|
elif grep -Eqi "11.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.10'; then |
||||||
|
CodeName='oneiric' |
||||||
|
elif grep -Eqi "12.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.10'; then |
||||||
|
CodeName='quantal' |
||||||
|
elif grep -Eqi "13.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.04'; then |
||||||
|
CodeName='raring' |
||||||
|
elif grep -Eqi "13.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.10'; then |
||||||
|
CodeName='saucy' |
||||||
|
elif grep -Eqi "10.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.04'; then |
||||||
|
CodeName='lucid' |
||||||
|
elif grep -Eqi "14.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.10'; then |
||||||
|
CodeName='utopic' |
||||||
|
elif grep -Eqi "15.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.04'; then |
||||||
|
CodeName='vivid' |
||||||
|
elif grep -Eqi "12.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.04'; then |
||||||
|
CodeName='precise' |
||||||
|
elif grep -Eqi "15.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.10'; then |
||||||
|
CodeName='wily' |
||||||
|
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then |
||||||
|
CodeName='yakkety' |
||||||
|
elif grep -Eqi "14.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.04'; then |
||||||
|
Ubuntu_Deadline trusty |
||||||
|
elif grep -Eqi "17.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.04'; then |
||||||
|
CodeName='zesty' |
||||||
|
elif grep -Eqi "17.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.10'; then |
||||||
|
CodeName='artful' |
||||||
|
elif grep -Eqi "16.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.04'; then |
||||||
|
Ubuntu_Deadline xenial |
||||||
|
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then |
||||||
|
CodeName='yakkety' |
||||||
|
elif grep -Eqi "14.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.04'; then |
||||||
|
Ubuntu_Deadline trusty |
||||||
|
elif grep -Eqi "17.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.04'; then |
||||||
|
CodeName='zesty' |
||||||
|
elif grep -Eqi "17.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.10'; then |
||||||
|
CodeName='artful' |
||||||
|
elif grep -Eqi "16.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.04'; then |
||||||
|
Ubuntu_Deadline xenial |
||||||
|
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then |
||||||
|
CodeName='yakkety' |
||||||
|
elif grep -Eqi "18.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^18.10'; then |
||||||
|
CodeName='cosmic' |
||||||
|
elif grep -Eqi "19.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.04'; then |
||||||
|
CodeName='disco' |
||||||
|
elif grep -Eqi "19.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.10'; then |
||||||
|
CodeName='eoan' |
||||||
|
elif grep -Eqi "20.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^20.10'; then |
||||||
|
CodeName='groovy' |
||||||
|
elif grep -Eqi "21.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^21.04'; then |
||||||
|
Ubuntu_Deadline hirsute |
||||||
|
elif grep -Eqi "21.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^21.10'; then |
||||||
|
Ubuntu_Deadline impish |
||||||
|
fi |
||||||
|
if [ "${CodeName}" != "" ]; then |
||||||
|
\cp /etc/apt/sources.list /etc/apt/sources.list.$(date +"%Y%m%d") |
||||||
|
cat > /etc/apt/sources.list<<EOF |
||||||
|
deb ${OldReleasesURL} ${CodeName} main restricted universe multiverse |
||||||
|
deb ${OldReleasesURL} ${CodeName}-security main restricted universe multiverse |
||||||
|
deb ${OldReleasesURL} ${CodeName}-updates main restricted universe multiverse |
||||||
|
deb ${OldReleasesURL} ${CodeName}-proposed main restricted universe multiverse |
||||||
|
deb ${OldReleasesURL} ${CodeName}-backports main restricted universe multiverse |
||||||
|
deb-src ${OldReleasesURL} ${CodeName} main restricted universe multiverse |
||||||
|
deb-src ${OldReleasesURL} ${CodeName}-security main restricted universe multiverse |
||||||
|
deb-src ${OldReleasesURL} ${CodeName}-updates main restricted universe multiverse |
||||||
|
deb-src ${OldReleasesURL} ${CodeName}-proposed main restricted universe multiverse |
||||||
|
deb-src ${OldReleasesURL} ${CodeName}-backports main restricted universe multiverse |
||||||
|
EOF |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Check_Old_Releases_URL() |
||||||
|
{ |
||||||
|
OR_Status=`wget --spider --server-response ${OldReleasesURL}/dists/$1/Release 2>&1 | awk '/^ HTTP/{print $2}'` |
||||||
|
if [ "${OR_Status}" = "200" ]; then |
||||||
|
echo "Ubuntu old-releases status: ${OR_Status}"; |
||||||
|
CodeName="$1" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Ubuntu_Deadline() |
||||||
|
{ |
||||||
|
trusty_deadline=`date -d "2022-4-30 00:00:00" +%s` |
||||||
|
xenial_deadline=`date -d "2024-4-30 00:00:00" +%s` |
||||||
|
hirsute_deadline=`date -d "2022-1-30 00:00:00" +%s` |
||||||
|
impish_deadline=`date -d "2022-7-30 00:00:00" +%s` |
||||||
|
cur_time=`date +%s` |
||||||
|
case "$1" in |
||||||
|
trusty) |
||||||
|
if [ ${cur_time} -gt ${trusty_deadline} ]; then |
||||||
|
echo "${cur_time} > ${trusty_deadline}" |
||||||
|
Check_Old_Releases_URL trusty |
||||||
|
fi |
||||||
|
;; |
||||||
|
xenial) |
||||||
|
if [ ${cur_time} -gt ${xenial_deadline} ]; then |
||||||
|
echo "${cur_time} > ${xenial_deadline}" |
||||||
|
Check_Old_Releases_URL xenial |
||||||
|
fi |
||||||
|
;; |
||||||
|
eoan) |
||||||
|
if [ ${cur_time} -gt ${eoan_deadline} ]; then |
||||||
|
echo "${cur_time} > ${eoan_deadline}" |
||||||
|
Check_Old_Releases_URL eoan |
||||||
|
fi |
||||||
|
;; |
||||||
|
hirsute) |
||||||
|
if [ ${cur_time} -gt ${hirsute_deadline} ]; then |
||||||
|
echo "${cur_time} > ${hirsute_deadline}" |
||||||
|
Check_Old_Releases_URL hirsute |
||||||
|
fi |
||||||
|
;; |
||||||
|
impish) |
||||||
|
if [ ${cur_time} -gt ${impish_deadline} ]; then |
||||||
|
echo "${cur_time} > ${impish_deadline}" |
||||||
|
Check_Old_Releases_URL impish |
||||||
|
fi |
||||||
|
;; |
||||||
|
esac |
||||||
|
} |
||||||
|
|
||||||
|
CentOS6_Modify_Source() |
||||||
|
{ |
||||||
|
if echo "${CentOS_Version}" | grep -Eqi "^6"; then |
||||||
|
echo "CentOS 6 is now end of life, use vault repository." |
||||||
|
mkdir /etc/yum.repos.d/backup |
||||||
|
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ |
||||||
|
\cp ${cur_dir}/conf/CentOS6-Base-Vault.repo /etc/yum.repos.d/CentOS-Base.repo |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
CentOS8_Modify_Source() |
||||||
|
{ |
||||||
|
if echo "${CentOS_Version}" | grep -Eqi "^8" && [ "${isCentosStream}" != "y" ]; then |
||||||
|
echo "CentOS 8 is now end of life, use vault repository." |
||||||
|
if [ ! -s /etc/yum.repos.d/CentOS8-vault.repo ]; then |
||||||
|
mkdir /etc/yum.repos.d/backup |
||||||
|
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ |
||||||
|
\cp ${cur_dir}/conf/CentOS8-vault.repo /etc/yum.repos.d/CentOS8-vault.repo |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
Install_Database() { |
||||||
|
echo "============================check files==================================" |
||||||
|
cd ${cur_dir}/src |
||||||
|
if [[ "${DBSelect}" =~ ^[12345]$ ]]; then |
||||||
|
if [[ "${Bin}" == "y" && "${DBSelect}" == "4" ]]; then |
||||||
|
Get_Country |
||||||
|
if [ "${country}" = "CN" ]; then |
||||||
|
Download_Files http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz |
||||||
|
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz |
||||||
|
else |
||||||
|
Download_Files https://cdn.mysql.com/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz |
||||||
|
fi |
||||||
|
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/archives/mysql-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz |
||||||
|
if [ ! -s ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ]; then |
||||||
|
Echo_Red "Error! Unable to download MySQL 5.7 Generic Binaries, please download it to src directory manually." |
||||||
|
sleep 5 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
elif [[ "${Bin}" == "y" && "${DBSelect}" == "5" ]]; then |
||||||
|
Get_Country |
||||||
|
if [ "${country}" = "CN" ]; then |
||||||
|
Download_Files http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz |
||||||
|
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz |
||||||
|
else |
||||||
|
Download_Files https://cdn.mysql.com/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz |
||||||
|
fi |
||||||
|
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/archives/mysql-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz |
||||||
|
if [ ! -s ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ]; then |
||||||
|
Echo_Red "Error! Unable to download MySQL 8.0 Generic Binaries, please download it to src directory manually." |
||||||
|
sleep 5 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
else |
||||||
|
Download_Files ${Download_Mirror}/datebase/mysql/${Mysql_Ver}.tar.gz ${Mysql_Ver}.tar.gz |
||||||
|
if [ ! -s ${Mysql_Ver}.tar.gz ]; then |
||||||
|
Echo_Red "Error! Unable to download MySQL source code, please download it to src directory manually." |
||||||
|
sleep 5 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
fi |
||||||
|
elif [[ "${DBSelect}" =~ ^[6789]|10$ ]]; then |
||||||
|
Download_Files ${Download_Mirror}/datebase/mariadb/${Mariadb_Ver}.tar.gz ${Mariadb_Ver}.tar.gz |
||||||
|
if [ ! -s ${Mariadb_Ver}.tar.gz ]; then |
||||||
|
Echo_Red "Error! Unable to download MariaDB source code, please download it to src directory manually." |
||||||
|
sleep 5 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
fi |
||||||
|
echo "============================check files==================================" |
||||||
|
|
||||||
|
Echo_Blue "Install dependent packages..." |
||||||
|
Get_Dist_Version |
||||||
|
Modify_Source |
||||||
|
DB_Dependent |
||||||
|
Check_Openssl |
||||||
|
if [ "${DBSelect}" = "1" ]; then |
||||||
|
Install_MySQL_51 |
||||||
|
elif [ "${DBSelect}" = "2" ]; then |
||||||
|
Install_MySQL_55 |
||||||
|
elif [ "${DBSelect}" = "3" ]; then |
||||||
|
Install_MySQL_56 |
||||||
|
elif [ "${DBSelect}" = "4" ]; then |
||||||
|
Install_MySQL_57 |
||||||
|
elif [ "${DBSelect}" = "5" ]; then |
||||||
|
Install_MySQL_80 |
||||||
|
elif [ "${DBSelect}" = "6" ]; then |
||||||
|
Install_MariaDB_5 |
||||||
|
elif [ "${DBSelect}" = "7" ]; then |
||||||
|
Install_MariaDB_103 |
||||||
|
elif [ "${DBSelect}" = "8" ]; then |
||||||
|
Install_MariaDB_104 |
||||||
|
elif [ "${DBSelect}" = "9" ]; then |
||||||
|
Install_MariaDB_105 |
||||||
|
elif [ "${DBSelect}" = "10" ]; then |
||||||
|
Install_MariaDB_106 |
||||||
|
fi |
||||||
|
TempMycnf_Clean |
||||||
|
} |
||||||
|
|
||||||
|
Install_Only_Database() { |
||||||
|
clear |
||||||
|
echo "+-----------------------------------------------------------------------+" |
||||||
|
echo "| Install MySQL/MariaDB database for LNMP, Written by Licess |" |
||||||
|
echo "+-----------------------------------------------------------------------+" |
||||||
|
echo "| A tool to install MySQL/MariaDB for LNMP |" |
||||||
|
echo "+-----------------------------------------------------------------------+" |
||||||
|
echo "| For more information please visit https://lnmp.org |" |
||||||
|
echo "+-----------------------------------------------------------------------+" |
||||||
|
|
||||||
|
Get_Dist_Name |
||||||
|
Check_DB |
||||||
|
if [ "${DB_Name}" != "None" ]; then |
||||||
|
echo "You have install ${DB_Name}!" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
DB_Info=('MySQL 5.1.73' 'MySQL 5.5.62' 'MySQL 5.6.51' 'MySQL 5.7.38' 'MySQL 8.0.30' 'MariaDB 5.5.68' 'MariaDB 10.3.35' 'MariaDB 10.4.25' 'MariaDB 10.5.16' 'MariaDB 10.6.8') |
||||||
|
Database_Selection |
||||||
|
|
||||||
|
if [ "${DBSelect}" = "0" ]; then |
||||||
|
echo "DO NOT Install MySQL or MariaDB." |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
Echo_Red "The script will REMOVE MySQL/MariaDB installed via yum or apt-get and it's databases!!!" |
||||||
|
Press_Install |
||||||
|
Install_Database 2>&1 | tee /root/install_database.log |
||||||
|
} |
||||||
|
|
||||||
|
# Check if user is root |
||||||
|
if [ $(id -u) != "0" ]; then |
||||||
|
echo "Error: You must be root to run this script, please use root to install db" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
mkdir -p /usr/local/src/src |
||||||
|
cd /usr/local/src |
||||||
|
cur_dir=$(pwd) |
||||||
|
Download_Mirror='https://soft.vpser.net' |
||||||
|
MySQL_Data_Dir='/var/lib/mysql' |
||||||
|
|
||||||
|
Install_Only_Database |
||||||
|
|
Loading…
Reference in new issue