Docker basic instructions:
Update software package
yum -y update
Install docker virtual machine (centos 7)
yum install -y docker
Run, restart, and shut down docker Virtual machine
service docker start service docker stop
Search image
docker search 镜像名称
Download image
docker pull 镜像名称
View image
docker images
Delete image
docker rmi 镜像名称
Run container
docker run 启动参数 镜像名称
View the container list
docker ps -a
When we want to use the java environment, we can do this:
搜索: [root@vm_71_225_centos ~]# docker search java index name description stars official automated docker.io docker.io/node node.js is a javascript-based platform for... 5752 [ok] docker.io docker.io/tomcat apache tomcat is an open source implementa... 1891 [ok] docker.io docker.io/java java is a concurrent, class-based, and obj... 1745 [ok] docker.io docker.io/openjdk openjdk is an open-source implementation o... 1031 [ok]
下载: [root@vm_71_225_centos ~]# docker pull docker.io/java using default tag: latest trying to pull repository docker.io/library/java ... latest: pulling from docker.io/library/java 5040bd298390: downloading [=> ] 1.572 mb/51.36 mb
运行: [root@vm_71_225_centos ~]# docker run -it --name myjava docker.io/java bash root@25623e12b759:/# java -i: 以交互模式运行容器,通常与 -t 同时使用; -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
Install the pxc cluster (no mysql pxc cluster and replication here) The advantages and disadvantages of the cluster solution are explained. Here we choose the pxc cluster solution [multi-node backup and strong federation]):
Install the pxc image
docker pull percona/percona-xtradb-cluster
View the local image
[root@vm_71_225_centos ~]# docker images repository tag image id created size docker.io/hello-world latest e38bc07ac18e 2 months ago 1.85 kb docker.io/percona/percona-xtradb-cluster latest f1439de62087 3 months ago 413 mb docker.io/java latest d23bdf5b1b1b 17 months ago 643 mb
docker.io/percona/percona-xtradb-cluster is too long, change the name:
[root@vm_71_225_centos ~]# docker tag percona/percona-xtradb-cluster pxc [root@vm_71_225_centos ~]# docker images repository tag image id created size docker.io/hello-world latest e38bc07ac18e 2 months ago 1.85 kb docker.io/percona/percona-xtradb-cluster latest f1439de62087 3 months ago 413 mb pxc latest f1439de62087 3 months ago 413 mb docker.io/java latest d23bdf5b1b1b 17 months ago 643 mb
Create net1 network segment:
docker network create --subnet=172.18.0.0/16 net1
Create five data volumes (pxc cannot be accessed directly The data of the host group machine, so create five docker data volumes)
docker volume create v1 docker volume create v2 docker volume create v3 docker volume create v4 docker volume create v5
Check the data volume location:
[root@vm_71_225_centos code]# docker inspect v1 [ { "driver": "local", "labels": {}, "mountpoint": "/var/lib/docker/volumes/v1/_data", "name": "v1", "options": {}, "scope": "local" } ]
Create a 5-node pxc cluster
#创建第1个mysql节点 docker run -d -p 3306:3306 -e mysql_root_password=abc123456 -e cluster_name=pxc -e xtrabackup_password=abc123456 -v v1:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=net1 --ip 172.18.0.2 pxc
Wait for 2 minutes , then create a second node, and wait until the first node is instantiated before opening the second node instance, otherwise it will stop instantly
Create other nodes:
#创建第2个mysql节点 docker run -d -p 3307:3306 -e mysql_root_password=abc123456 -e cluster_name=pxc -e xtrabackup_password=abc123456 -e cluster_join=node1 -v v2:/var/lib/mysql -v backup:/data --privileged --name=node2 --net=net1 --ip 172.18.0.3 pxc #创建第3个mysql节点 docker run -d -p 3308:3306 -e mysql_root_password=abc123456 -e cluster_name=pxc -e xtrabackup_password=abc123456 -e cluster_join=node1 -v v3:/var/lib/mysql --privileged --name=node3 --net=net1 --ip 172.18.0.4 pxc #创建第4个mysql节点 docker run -d -p 3309:3306 -e mysql_root_password=abc123456 -e cluster_name=pxc -e xtrabackup_password=abc123456 -e cluster_join=node1 -v v4:/var/lib/mysql --privileged --name=node4 --net=net1 --ip 172.18.0.5 pxc #创建第5个mysql节点 docker run -d -p 3310:3306 -e mysql_root_password=abc123456 -e cluster_name=pxc -e xtrabackup_password=abc123456 -e cluster_join=node1 -v v5:/var/lib/mysql -v backup:/data --privileged --name=node5 --net=net1 --ip 172.18.0.6 pxc
Test at any time Mysql node creates a database:
mysql -h 172.18.0.3 -uroot -pabc123456 mysql> create database test; query ok, 1 row affected (0.03 sec)
Log in to other node databases and you can see that synchronization has been carried out to form a simple mysql cluster
Install haproxy for high availability and load balancing
Pull haproxy
docker pull haproxy
Write haproxy configuration file
vi /home/soft/haproxy.cfg
The configuration file is as follows:
global #工作目录 chroot /usr/local/etc/haproxy #日志文件,使用rsyslog服务中local5日志设备(/var/log/local5),等级info log 127.0.0.1 local5 info #守护进程运行 daemon defaults log global mode http #日志格式 option httplog #日志中不记录负载均衡的心跳检测记录 option dontlognull #连接超时(毫秒) timeout connect 5000 #客户端超时(毫秒) timeout client 50000 #服务器超时(毫秒) timeout server 50000 #监控界面 listen admin_stats #监控界面的访问的ip和端口 bind 0.0.0.0:8888 #访问协议 mode http #uri相对地址 stats uri /dbs #统计报告格式 stats realm global\ statistics #登陆帐户信息 stats auth admin:abc123456 #数据库负载均衡 listen proxy-mysql #访问的ip和端口 bind 0.0.0.0:3306 #网络协议 mode tcp #负载均衡算法(轮询算法) #轮询算法:roundrobin #权重算法:static-rr #最少连接算法:leastconn #请求源ip算法:source balance roundrobin #日志格式 option tcplog #在mysql中创建一个没有权限的haproxy用户,密码为空。haproxy使用这个账户对mysql数据库心跳检测 option mysql-check user haproxy server mysql_1 172.18.0.2:3306 check weight 1 maxconn 2000 server mysql_2 172.18.0.3:3306 check weight 1 maxconn 2000 server mysql_3 172.18.0.4:3306 check weight 1 maxconn 2000 server mysql_4 172.18.0.5:3306 check weight 1 maxconn 2000 server mysql_5 172.18.0.6:3306 check weight 1 maxconn 2000 #使用keepalive检测死链 option tcpka
Create the first haproxy load balancing server
Copy code The code is as follows:
docker run -it -d -p 4001:8888 -p 4002:3306 -v /home/soft/haproxy:/usr/local/etc/haproxy --name h1 --privileged --net=net1 --ip 172.18.0.7 haproxy
Enter the h1 container and start haproxy
docker exec -it h1 bash haproxy -f /usr/local/etc/haproxy/haproxy.cfg
Check whether the startup is successful:
Visit http:// ip:4001/dbs
Install keepalive to achieve double-click hot backup
The above is the detailed content of What is the method for building a Mysql cluster with docker?. For more information, please follow other related articles on the PHP Chinese website!

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
