Why not deploy the database in the docker container

osc_ chra83mb 2021-01-21 12:10:07
deploy database docker container



near 2 year Docker It's very hot , Developers would like to put all the applications 、 The software is deployed in Docker In the container , But are you sure you want to deploy the database in the container as well ? This problem is not a myth , Because we can find many kinds of operation manuals and video tutorials on the Internet , Here we sort out some reasons why the database is not suitable for containerization for your reference , At the same time, I hope you can use it with a little caution . So far, it is unreasonable to container the database , But the advantages of containerization are believed to be enjoyed by all developers , I hope that with the development of technology, more perfect solutions will emerge .

Docker Not suitable for database deployment 7 The big reason

1、 Data security issues

Do not store data in containers , This is also Docker One of the official container tips . The container can stop at any time 、 Or delete . When the container is rm fall , The data in the container will be lost . To avoid data loss , Users can use data volume mount to store data . But the container Volumes Design is about Union FS The image layer provides persistent storage , Data security is not guaranteed . If the container suddenly collapses , The database is not shut down properly , Could damage data . in addition , Shared data volume group in container , The damage to physical machine hardware is also relatively large . Even if you want to put Docker Data is stored on the host , It's still not guaranteed to lose data . Use the current storage driver ,Docker There is still a risk of unreliability . If the container crashes and the database does not shut down properly , It can damage the data .

2、 Performance issues

Everybody knows ,MySQL Belongs to relational database , Yes IO The demand is higher . When a physical machine runs more than one ,IO It will add up , Lead to IO bottleneck , Greatly reduced MySQL Read and write performance of . In a Docker Ten difficulties in application , An architect of a state-owned bank once proposed :“ The performance bottleneck of database usually appears in IO above , If the Docker The idea of , So many docker Final IO The request will appear on the store again . Now the Internet database is mostly share nothing The architecture of , Maybe it's not about moving to Docker A factor of ”.

Some students may have corresponding solutions for performance problems :

(1) Database program is separated from data

If you use Docker run MySQL, Database program and data need to be separated , Store data in shared storage , Put the program in the container . If the container is abnormal or MySQL Service exception , Automatically start a new container . in addition , It is recommended not to store the data in the host computer , Host and container share volume group , It has a great impact on the damage of the host .

(2) Run lightweight or distributed databases

Docker Deployment of lightweight or distributed databases ,Docker Recommend the service itself and hang up , Start new container automatically , Instead of continuing to restart the container service .

(3) Reasonable layout and application

about IO Applications or services with high requirements , Deploy the database on a physical machine or KVM It's more suitable . at present TX The cloud TDSQL Ali Oceanbase They are all deployed directly on physical machines , Instead of Docker .

3、 Network problems

To understand Docker The Internet , You have to have an in-depth understanding of network virtualization . Databases need dedicated and persistent throughput , To achieve a higher load . Unresolved Docker The problem with the Internet is 1.9 The version is still unresolved . Put these questions together , Containerization makes database containers difficult to manage . How long will it take you to solve Docker Network problems ? Wouldn't it be better to keep the database in a dedicated environment ? Save time to focus on really important business goals .

4、 state

stay Docker It's cool to pack stateless services in , It can be used to arrange containers and solve single point of failure . But the database ? Put the database in the same environment , It will be stateful , And make the scope of system failure larger . Next time your application instance or application crashes , May affect the database . Knowledge point : stay Docker Medium level scaling can only be used for stateless computing services , Not a database .Docker An important feature of rapid expansion is statelessness , Those with data status are not suitable to be placed directly in Docker Inside , If Docker Install database in , Storage services need to be provided separately . at present ,TX The cloud TDSQL( Financial distributed database ) And Alibaba cloud Oceanbase( Distributed database system ) Are all running directly on the physical machine , It's not easy to manage Docker On .

5、 Resource isolation

In terms of resource isolation ,Docker It's not as good as a virtual machine KVM,Docker It's using Cgroup To achieve resource limitation , You can only limit the maximum consumption of resources , Instead of isolating other programs from using their own resources . If other applications take up physical machine resources , It will affect the container MySQL Reading and writing efficiency of . The more isolation levels you need , The more resources are spent . Compared to a dedicated environment , Easy horizontal expansion is Docker A big advantage of . However, in Docker Medium level scaling can only be used for stateless computing services , The database doesn't work . We don't see any isolation for the database , Then why should we put it in a container ?

6、 The inapplicability of cloud platform

Most people start projects through shared cloud . Cloud simplifies the complexity of virtual machine operation and replacement , So there is no need to test the new hardware environment at night or on weekends when no one is working . When we can start an instance quickly , Why do we need to worry about the running environment of this instance ? That's why we pay a lot of fees to cloud providers . When we place the database container for the instance , These conveniences mentioned above do not exist . Because the data are inconsistent , The new instance will not be compatible with the honest one , If you want to restrict the use of stand-alone services by instances , Should let DB Use a non containerized environment , We just need to keep the elastic expansion capability for the computing service layer .

7、 Environment requirements for running database

Often seen DBMS Containers and other services run on the same host . However, these services have very different hardware requirements . database ( Especially relational databases ) Yes IO The requirements are high . In general, database engine uses special environment to avoid concurrent resource competition . If you put your database in a container , Then it will waste the resources of your project . Because you need to configure a lot of extra resources for this instance . In public , When you need 34G Memory time , The instance you started must be opened 64G Memory . In practice , These resources are not fully used . How to solve ? You can design in layers , And use fixed resources to start multiple instances at different levels . Horizontal scaling is always better than vertical scaling .

summary

In view of the above problems, does it mean that the database must not be deployed in the container ? The answer is : It's not that we can lose data to insensitive businesses ( Search for 、 Buried point ) It can be containerized , Use database fragmentation to increase the number of instances , Thus increasing throughput .docker Suitable for running lightweight or distributed databases , When docker Service hangs up , Will automatically start a new container , Instead of continuing to restart the container service . The database can automatically scale by using middleware and containerization system 、 disaster 、 Switch 、 With multiple nodes , It can also be containerized .

Link to the original text :http://l.wz2.in/0AC
author : Macy loves cycling


END



Focus on Brother Wu talks about programming

Make a little progress every day



Praise is the biggest support  

版权声明
本文为[osc_ chra83mb]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121115816842x.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云