我的云文档怎么没有了(我的云文档怎么找)
864
2022-05-29
提示
:本文的操作是在基础环境搭建完成的基础上进行的,基础环境搭建请参阅上一篇文章:
鲲鹏服务器快速部署docker+docker-compose环境:
https://bbs.huaweicloud.com/forum/thread-60765-1-1.html
或:
https://bbs.huaweicloud.com/blogs/176180
docker环境搭建完成,可以进行本文的操作。
系统环境:CentOS 7.6 64bit with ARM
构建Mysql 8.0.19镜像
构建准备
# clone 官方Dockerfile
git clone https://github.com/mysql/mysql-docker.git
# 进入8.0路径
cd mysql-docker/8.0
# 修改原版Dockerfile,mysql版本号修改为8.0.19,其他不动
# mysql版本号修改为8.0.19是我方项目需要,如果需要其版本,请参考执行
vim Dockerfile
# 内容如下:
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
FROM oraclelinux:7-slim
# 版本号改为8.0.19
ARG MYSQL_SERVER_PACKAGE=mysql-community-server-minimal-8.0.19
ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.19
# Install server
RUN yum install -y https://repo.mysql.com/mysql-community-minimal-release-el7.rpm \
https://repo.mysql.com/mysql-community-release-el7.rpm \
&& yum-config-manager --enable mysql80-server-minimal \
&& yum install -y \
$MYSQL_SERVER_PACKAGE \
$MYSQL_SHELL_PACKAGE \
libpwquality \
&& yum clean all \
&& mkdir /docker-entrypoint-initdb.d
# Data Volume
VOLUME /var/lib/mysql
COPY docker-entrypoint.sh /entrypoint.sh
COPY healthcheck.sh /healthcheck.sh
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK CMD /healthcheck.sh
EXPOSE 3306 33060
CMD ["mysqld"]
修改完成,保存、退出。
构建镜像
# 构建镜像,注意末尾有个空格,还有个.
docker build -t cehc/mysql-arm:8.0.19 .
# 查看镜像
docker images
# cehc/mysql-arm:8.0.19镜像大小438M
发布镜像
docker login
# 输入在docker-hub注册的用户名密码登录
docker tag cehc/mysql-arm:8.0.19 cehc/mysql-arm:8.0.19
docker push cehc/mysql-arm:8.0.19
# 推送成功
说明
:cehc/mysql-arm:8.0.19镜像已经发布为公共镜像。
测试镜像
# 测试运行,不挂载数据目录和自定义配置
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d cehc/mysql-arm:8.0.19
# 查看启动日志
docker logs -f -t --tail 100 mysql
# 启动成功后,可进入 mysql 容器
docker exec -it mysql /bin/bash
# 在容器内登录mysql
mysql -uroot -p
# 查看 lower_case_table_names 参数设置
mysql> show variables like 'lower%';
# 查看mysql当前时间,检查当前时区
mysql> select curtime();
# 退出mysql
mysql> exit;
# 退出容器
exit
# 停止容器
docker stop mysql
# 删除容器
docker rm mysql
实测通过
镜像编排
# 部署前,主机挂载数据盘到/data,准备数据目录
mkdir -p /data/mysql/conf
cd /data/mysql
mkdir data log run backup mysql-files tmp
chmod -R 777 /data/mysql
chmod -R 644 /data/mysql/conf
# 说明:容器挂载 /data/mysql:/data/mysql 为了方便进行备份/恢复操作
# 根据容器内置my.cnf,编制自定义配置
vim /data/mysql/conf/my.cnf
# 内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
# 自定义配置
# tmpdir=/tmp
port=3306
# 默认时区设置为东8区
default-time_zone='+8:00'
# 默认编码utf8mb4
character-set-server=utf8mb4
character-set-client-handshake=FALSE
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
secure_file_priv=/var/lib/mysql
default_authentication_plugin=mysql_native_password
default-storage-engine=INNODB
# 设置数据库大小写不敏感,根据实际项目需求设置,默认值是0
lower_case_table_names=1
# 最大连接数,默认设置是100
max_connections=1000
# SQL数据包发送的大小,如果有BLOB对象建议修改成1G
max_allowed_packet=128M
# MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭
# MySQL默认的 wait_timeout 值为8个小时
# interactive_timeout 参数需要同时配置才能生效
interactive_timeout=28800
wait_timeout=28800
[mysql]
no-auto-rehash
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
[client]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
port=3306
[mysqld_safe]
log-error=/logs/mysql.log
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
[mysqldump]
quick
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
socket=/var/lib/mysql/mysql.sock
保存、退出。
# 编制docker-compose脚本
vim docker-compose.yml
# 内容如下:
version: '2'
services:
cehc-mysql:
image: cehc/mysql-arm:8.0.19
container_name: cehc-mysql
privileged: true
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: yourpassword # 设置 mysql root 密码
volumes:
- /data/mysql:/data/mysql
- /data/mysql/data:/var/lib/mysql
- /data/mysql/log:/logs
- /data/mysql/conf/mysql/my.cnf:/etc/my.cnf
- /etc/localtime:/etc/localtime:ro
command: --lower_case_table_names=1 # 注:该设置是我方项目需要
保存、退出。
# 后台启动镜像
docker-compose up -d
# 启动成功后,可进入 mysql 容器
docker exec -it cehc-mysql /bin/bash
# 在容器内登录mysql
mysql -u root -p
# 输入自定义密码
-- 查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
-- 查看 lower_case_table_names 参数设置
mysql> show variables like 'lower%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
2 rows in set (0.00 sec)
-- 查看是否启用了二进制日志
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.01 sec)
-- 查看二进制日志详细设置
mysql> show variables like '%binlog%';
+------------------------------------------------+----------------------+
| Variable_name | Value |
+------------------------------------------------+----------------------+
| binlog_cache_size | 32768 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_encryption | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_expire_logs_seconds | 2592000 |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_rotate_encryption_master_key_at_startup | OFF |
| binlog_row_event_max_size | 8192 |
| binlog_row_image | FULL |
| binlog_row_metadata | MINIMAL |
| binlog_row_value_options | |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| binlog_transaction_dependency_history_size | 25000 |
| binlog_transaction_dependency_tracking | COMMIT_ORDER |
| innodb_api_enable_binlog | OFF |
| log_statements_unsafe_for_binlog | ON |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_size | 1073741824 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| sync_binlog | 1 |
+------------------------------------------------+----------------------+
27 rows in set (0.00 sec)
-- 查看 log_bin 存储位置
mysql> show variables like '%log_bin%';
+---------------------------------+-----------------------------+
| Variable_name | Value |
+---------------------------------+-----------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/binlog |
| log_bin_index | /var/lib/mysql/binlog.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+-----------------------------+
6 rows in set (0.00 sec)
-- 退出
mysql> exit;
实测通过
构建自定义mysql镜像
在前面操作的基础上集成自定义配置,根据我方项目开发实际需求,构建自定义mysql镜像。
# 编制自定义脚本
vim Dockerfile
# 内容如下:
FROM cehc/mysql-arm:8.0.19
MAINTAINER from www.ceht.com.cn by cehc(humengjie@ceht.com.cn)
# 设置编码,防止中文乱码
ENV LANG C.UTF-8
# 设置时区
ENV TZ=Asia/Shanghai
# 添加自定义配置
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
echo -e "\n# 自定义配置\n# tmpdir=/tmp\nport=3306\n# 默认时区设置为东8区\ndefault-time_zone='+8:00'\n\n# 默认编码utf8mb4\ncharacter-set-server=utf8mb4\ncharacter-set-client-handshake=FALSE\ncollation-server=utf8mb4_general_ci\ninit_connect='SET NAMES utf8mb4'\nsecure_file_priv=/var/lib/mysql\ndefault_authentication_plugin=mysql_native_password\ndefault-storage-engine=INNODB\n# 设置数据库大小写不敏感,根据实际项目需求设置,默认值是0\nlower_case_table_names=1\n\n# 最大连接数,默认设置是100\nmax_connections=1000\n# SQL数据包发送的大小,如果有BLOB对象建议修改成1G\nmax_allowed_packet=128M\n# MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭\n# MySQL默认的 wait_timeout 值为8个小时\n# interactive_timeout 参数需要同时配置才能生效\ninteractive_timeout=28800\nwait_timeout=28800\n\n[mysql]\nno-auto-rehash\ndefault-character-set=utf8mb4\nsocket=/var/lib/mysql/mysql.sock\n\n[client]\ndefault-character-set=utf8mb4\nsocket=/var/lib/mysql/mysql.sock\nport=3306\n\n[mysqld_safe]\nlog-error=/logs/mysql.log\npid-file=/var/run/mysqld/mysqld.pid\nsocket=/var/lib/mysql/mysql.sock\n\n[mysqldump]\nquick\nsocket=/var/lib/mysql/mysql.sock\n\n[mysqladmin]\nsocket=/var/lib/mysql/mysql.sock" >> /etc/my.cnf
# 构建镜像
docker build -t cehc/cehc-mysql-arm:8.0.19 .
其他操作内容,不再赘述。
以上内容均在北京四区鲲鹏服务器实测通过,供参考。
鲲鹏 软件开发
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。