docker-mysql

docker-mysql

  1. 自己部署mysql 5.7
docker run -p 3306:3306 --restart=always --name edc-mysql \
-e MYSQL_ROOT_PASSWORD=12345678 \
-d mysql:5.7


docker exec -it edc-mysql bash
mysql -uroot -p12345678
create database if not exists test default character set utf8;
grant all privileges on *.* to root@'%' identified by "12345678";
flush privileges;


grant all privileges on *.* to root@'%' identified by "acsAdmin@2020";
  1. docker-compose.yml 文件部署

参考官网Hub https://registry.hub.docker.com/_/mysql

version: '2'
services:
	mysql:
		image: mysql:8.0.19
		ports:
		  - "3306:3306"
		command: --default-authentication-plugin=mysql_native_password --secure_file_priv=/data
		environment:
		  MYSQL_USER: "sql-demo"
		  MYSQL_PASSWORD: "demo-sql"
		  MYSQL_DATABASE: "sql-demo"
		  MYSQL_ROOT_PASSWORD: "edc12345678."
		volumes:
		  - ../docker/mysql-spend-report-init:/docker-entrypoint-initdb.d
		  - ./data:/data

不用修改直接启动就好

docker-compose up -d

开启binlog

show variables like 'log_%';

vi /etc/my.cnf

[mysqld]
innodb_buffer_pool_size = 38628M
server_id=2
log_bin = mysql-bin
binlog_format = ROW
expire_logs_days = 30
default-time_zone = '+8:00'
default-storage-engine = INNODB
character-set-server = utf8
auto_increment_offset = 1
auto_increment_increment = 2
max_allowed_packet = 20M
max_connections=1024
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
event_scheduler=ON

[mysql]
default-character-set = utf8

[client]
default-character-set = utf8

systemctl restart mysqld
show variables like 'log_%';

部署metabase

docker run -d -p 3000:3000 --name metabase metabase/metabase

rpm部署MySQL8.0



wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server -y

mysqld --initialize

systemctl restart mysqld
chown -R mysql:mysql /var/lib/mysql

systemctl restart mysqld
systemctl enable mysqld.service
systemctl status mysqld.service

grep "A temporary password" /var/log/mysqld.log
mysql -p

ALTER user 'root'@'localhost' IDENTIFIED BY 'Xskj@2021';

install_mysql-8.0.sh

#!/bin/env bash
# =================================================
# Author: renwole.com               #
# See: https://renwole.com/archives/2215  #
# Description: MySQL automatic installation tool  #
# =================================================
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

Install_MySQL() {
	# CentOS 8 mysql: error while loading shared libraries: libncurses.so.5
	yum install ncurses ncurses-compat-libs -y
	# Install dependencies
	setenforce 0
	yum -y install epel-release
	yum -y install wget tar jemalloc jemalloc-devel gcc gcc-c++

	# MySQL configuration
	mysql_version="8.0.27"
	mysql_password="nd.mm#2021"
	mkdir -p /apps/server/mysql/data
	mysql_install_dir="/apps/server/mysql"
	mysql_data_dir="/apps/server/mysql/data"
	download_mysql="https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads"

	# Download MySQL
	cd /mnt
	useradd -M -s /sbin/nologin mysql >/dev/null 2>&1
	wget -c ${download_mysql}/MySQL-8.0/mysql-${mysql_version}-linux-glibc2.12-x86_64.tar.xz
    echo "========== Start installing MySQL ============"
	tar xJf mysql-${mysql_version}-linux-glibc2.12-x86_64.tar.xz
	\mv mysql-${mysql_version}-linux-glibc2.12-x86_64/* ${mysql_install_dir}
	
	if [[ -d "${mysql_install_dir}/support-files" ]]; then
		rm -rf mysql-${mysql_version}-linux-glibc2.12-x86_64
	else
		rm -rf ${mysql_install_dir}
		echo "Error: MySQL install failed, Please contact the author"
		kill -9 $$
	fi

	# Initialize the database
	${mysql_install_dir}/bin/mysqld --initialize-insecure --user=mysql --lower-case-table-names=1 --basedir=${mysql_install_dir} --datadir=${mysql_data_dir}
	chown -R root . ${mysql_install_dir}
	chown -R mysql.mysql ${mysql_data_dir}
	\cp -f ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
	sed -i "s@^basedir=.*@basedir=${mysql_install_dir}@" /etc/init.d/mysqld
	sed -i "s@^datadir=.*@datadir=${mysql_data_dir}@" /etc/init.d/mysqld
	sed -i "s@/usr/local/mysql@${mysql_install_dir}@g" ${mysql_install_dir}/bin/mysqld_safe
	sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/lib64/libjemalloc.so@' ${mysql_install_dir}/bin/mysqld_safe
	echo 'PATH=$PATH:'${mysql_install_dir}'/bin' >/etc/profile.d/mariadb_renwole.com.sh

	# my.conf configuration
	cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash

[mysqld]
port = 3306
socket = /tmp/mysql.sock
default_authentication_plugin = mysql_native_password

basedir = ${mysql_install_dir}
datadir = ${mysql_data_dir}
pid-file = ${mysql_data_dir}/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1

init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
collation-server = utf8mb4_0900_ai_ci
lower-case-table-names = 1

skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M

thread_cache_size = 8

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
binlog_expire_logs_seconds = 604800

log_error = ${mysql_data_dir}/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = ${mysql_data_dir}/mysql-slow.log

performance_schema = 0
explicit_defaults_for_timestamp

lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

[mysqldump]
quick
max_allowed_packet = 500M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
	# Set up MySQL
	chmod 600 /etc/my.cnf
	chmod +x /etc/init.d/mysqld
	systemctl enable mysqld
  	systemctl start mysqld
  	${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "create user root@'127.0.0.1' identified by \"${mysql_password}\";"
  	${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'127.0.0.1' with grant option;"
 	${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'localhost' with grant option;"
  	${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "alter user root@'localhost' identified by \"${mysql_password}\";"
  	${mysql_install_dir}/bin/mysql -uroot -p${mysql_password} -e "reset master;"
  	rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
  	echo "${mysql_install_dir}/lib" > /etc/ld.so.conf.d/mysql_renwole.com.conf
  	ldconfig
  	echo "========== MySQL installing Successfully ====="
  	echo
	echo "=============================================="
	echo "    Thank you for using Renwole.com script"
	echo "=============================================="
	echo "MySQL:"
	echo "account: root"
	echo "password: ${mysql_password}"
	echo "database: ${mysql_data_dir}"
	echo "=============================================="
}

Install_MySQL
source /etc/profile

install_nginx.sh

#!/usr/bin/env bash
yum install -y zlib-devel openssl openssl-devel
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx
make && make install
cd ..
rm -rf nginx-*
echo "export PATH=\$PATH:/usr/local/nginx/sbin" >> /etc/profile
source /etc/profile
nginx

#开机启动
cat > /usr/lib/systemd/system/nginxd.service <<EOF
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
systemctl enable nginxd.service

#!/usr/bin/env bash

set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)

usage() {
  cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]

Script description here.

Available options:

-h, --help      Print this help and exit
-v, --verbose   Print script debug info
-f, --flag      Some flag description
-p, --param     Some param description
EOF
  exit
}

cleanup() {
  trap - SIGINT SIGTERM ERR EXIT
  # script cleanup here
}

setup_colors() {
  if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
    NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
  else
    NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
  fi
}

msg() {
  echo >&2 -e "${1-}"
}

die() {
  local msg=$1
  local code=${2-1} # default exit status 1
  msg "$msg"
  exit "$code"
}

parse_params() {
  # default values of variables set from params
  flag=0
  param=''

  while :; do
    case "${1-}" in
    -h | --help) usage ;;
    -v | --verbose) set -x ;;
    --no-color) NO_COLOR=1 ;;
    -f | --flag) flag=1 ;; # example flag
    -p | --param) # example named parameter
      param="${2-}"
      shift
      ;;
    -?*) die "Unknown option: $1" ;;
    *) break ;;
    esac
    shift
  done

  args=("$@")

  # check required params and arguments
  [[ -z "${param-}" ]] && die "Missing required parameter: param"
  [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"

  return 0
}

parse_params "$@"
setup_colors

# script logic here

msg "${RED}Read parameters:${NOFORMAT}"
msg "- flag: ${flag}"
msg "- param: ${param}"
msg "- arguments: ${args[*]-}"
posted @ 2023-04-03 11:10  edclol  阅读(46)  评论(0编辑  收藏  举报