微前端架构如何改变企业的开发模式与效率提升
768
2022-10-18
Docker MySQL 环境下运行
MySQL安装部署
拉取镜像,访问 MySQL 镜像库地址:-镜像[root@localhost ~]# docker pull mysql:5.7.30[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmysql 5.7.30 9cfcce23593a 4 months ago 448MB
备注:
docker pull [OPTIONS] NAME [:TAG] :此命令的作用是从docker远程的仓库拉取镜像到本地docker images [OPTIONS] [REPOSITORY[:TAG]] :此命令是来查看我们本机都有哪些镜像,也可以验证我们的pull是否执行成功
简单启动 mysql,查看所有container
[root@localhost ~]# docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.308b2e76a2b18fd822520b3cbed45b4e1a8b3d5d40838f09dfa6740d8873d54f6a[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8b2e76a2b18f mysql:5.7.30 "docker-entrypoint.s…" 18 seconds ago Up 16 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
备注:
–name:为容器指定一个名称,此处命名为mysql-e:配置信息,此处配置mysql的root用户的登陆密码-p:端口映射,此处映射 主机3306端口 到 容器的3306端口-d:后台运行容器,并返回容器ID;内部映射的端口改成其他端口时候,需要进入docker内 把对应的端口my-f进行配置
登录mysql
[root@localhost ~]# docker exec -it mysql /bin/bashroot@8b2e76a2b18f:/# mysql -uroot -p123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.30 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
目录映射 主机上创建对应的映射目录:
[root@localhost ~]# mkdir -p /usr/local/docker/mysql/conf[root@localhost ~]# mkdir -p /usr/local/docker/mysql/data[root@localhost ~]# mkdir -p /usr/local/docker/mysql/logs
[root@localhost conf]# chmod 777 /usr/local/docker/mysql/conf/my-f [root@localhost conf]# docker run -p 3306:3306 --name mysql -v /usr/local/docker/mysql/conf/my-f:/etc/mysql/my-f -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.304f06e6f740889a097bbe1c3a4345ef49adba1d9111b54932bb54ae82db69ed2c[root@localhost conf]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4f06e6f74088 mysql:5.7.30 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql[root@localhost conf]# docker exec -it mysql /bin/bashroot@4f06e6f74088:/# cd /etc/mysql/root@4f06e6f74088:/etc/mysql# lsconf.d my-f my-f.fallback mysql-f mysql.conf.droot@4f06e6f74088:/etc/mysql# cat my-f[mysqld]server_id = 1303306character_set_server = utf8mb4collation_server = utf8mb4_unicode_ciport = 3306transaction_isolation = READ-COMMITTEDmax_connections = 1000datadir = /var/lib/mysqlsocket = /var/run/mysqld/mysqld.sockpid_file = /var/run/mysqld/mysqld.pidlog_error = /var/log/mysql/error.log
备注: -v:主机和容器的目录映射关系,":"前为主机目录,之后为容器目录。映射本地目录之后,但MySQL容器出现故障之后,可通过文件迁移,挂载方式,用原有数据搭建新容器,提供服务。
备份 mysqldump备份命令:
[root@ss30 opt]# docker exec mysql sh -c 'exec mysqldump -uroot -p123456 -P3309 --single-transaction --master-data --all-databases' > /opt/all-databases.sql
总结
通过实践,在docker中的MySQL部署和运维,还是比较简单的。实际测试性能损耗也在10%,当然主要个人认为还是网络方面的延迟。IO和CPU 已经不再是瓶颈。
容器方面,更想进一步深入的话,需要理解几个核心点: 1.Docker的数据持久化:目录的映射 和 volume方式 2.资源方面的隔离 Namespace 和 CGroup 3.容器服务编排: Mesos Swarm Kubernetes 4.网络连接方式的选择
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~