Setup Mysql cluster
Base environment configuration
Create and connect EC2
Create EC2 is a simple operation, you can follow official guide to complete. Once thing is if you choose create key-pair as authentication method, you need takes some additional steps as below:
- input your preferred name as key-pair name, like 'my-demo'
- A file named my-demo.pem will be downloaded on your local position
- If you use puppty to connect you EC2 instance, you need convert pem file to ppk file, since the former is not supported by puppty client now
- Open puttygen app (it's installed on windows 10 plaftform by default)
- Click
loadbutton to choose your local perm file like my-demo.pem - Click
generatethensave private keyto your local file (.ppk file)
please note you must keep the ppk file name as same as pem file, or puppty will show some error
If you face "software caused connect abord" issue, please try to extend keepavlie time follow below step:
- Open puppt
- select the related session
- expand
connectin the left panel - set "seconds betwenn keepalives" a suitable value, this value represents client will send a empty package to server every x seconds
Reference:
Install docker on aws EC2
Update yum :sudo yum update -y
Install docker :sudo yum install docker -y
Start docker service: sudo service docker start
Check docker version for verification: docker -v
Install MySql image
Install mysql 8.021: docker pull mysql:8.0.21
check if mysql installed: docker images
Run mysql image:
docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:8.0.21
-d:表示后台运行
-p:表示暴露端口
-v 表示挂载
--name 表示设置mysql容器的名称
Enter docker image and create a mysql user with root
Enter docker: docker exec -it mysql01 bash
Logon as root to create a user: mysql uroot -p
Create a user named dbuser
create user 'dbuser'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON '*.*' TO 'dbuser'@'%' WITH GRANT OPTION
in case you have to reset root password :
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[newpassword]';
Connect mysql server
Since mysql 8.0.21 is started, it's time to connect the server. Before connecting, please make sure port 3306 is open on EC2, you can follow below steps:
-
Log into you AWS Console and go to ‘EC2’
-
On the left hand menu under ‘Network & Security’ go to ‘Security Groups’
-
Check the Security Group in question
-
Click on ‘Inbound tab’
-
Choose ‘MYSQL’ from drop down list and click ‘Add Rule’ Then you can try some client tools to connect
Conclusion
In this post, we created an EC2 and installed docker, then installed and started mysql 8 image. Finally we try to connect it via some client tools.