Tencent Cloud Lighthouse Accesses TDSQL-C (Cloud Native Database)

0 Preface

When I saw Alibaba Cloud's advertisement, I found that the first purchase of cloud database is so cheap. Then I looked at Tencent Cloud, and there were similar activities.

Tencent Cloud's popular cloud products have a special discount for the first order, 38 yuan for the first year of a 1-core 2G cloud server, and 9.9 yuan for the first year of a 1-core 1G cloud database
During the configuration process, I thought there would be no problem following the documentation, but it turned out that I couldn't connect to the database at all, so I initiated a work order and completed the configuration with the help of Tencent Cloud customer service.

1. Reset root password

Select the TDSQL-C cluster at https://console.cloud.tencent.com/cynosdb, and click Reset Password of the root account in Account Management.

Note: The default randomly generated root password of the Bt is only lowercase letters + numbers, which does not meet the requirements of Tencent Cloud. It is recommended to set the TDSQL-C password and set the root password in the Bt panel to be the same to facilitate subsequent connections!

2. New cloud networking

The network of the lightweight application server is isolated from the cloud server and cloud database, so cloud networking needs to be used for communication.

2.1, check the intranet IP

Select the specified instance in https://console.cloud.tencent.com/lighthouse/ to view the intranet IP of the lightweight application server.

For example: my lightweight application server intranet IP is 10.0.x.x.

View the database intranet IP in the cloud native database cluster list.

For example: my cloud native database intranet IP is 172.17.x.x.

Tip: The public network access address may not be displayed in the cluster list. I have turned it on and off here, so a line will be displayed.

Note: Please remember the intranet IP, it will be used in the future!

2.2. New cloud networking

Create a new cloud network in the specified region at https://console.cloud.tencent.com/vpc/ccn/.
If the server and database are in the same region, the quality of service is optional, and there is 5Gbps free bandwidth.
The associated instance here selects the VPC of TDSQL-C.

2.3, associated cloud networking

Link cloud networking to the corresponding region at https://console.cloud.tencent.com/lighthouse/ccn/, and connect to the cloud at https://console.cloud.tencent.com/vpc/ccn By agreeing to the application, you can associate the lightweight application server with the cloud-native database network.
Note: After the association, you need to check the routing table to confirm that all are valid!

2.4, check connectivity

Install Telnet inside the server.
Take CentOS as an example, execute:

Bash
1
yum install telnet

Once installed, use:

Bash
1
telnet 172.17.x.x 3306

You can test whether the server can connect to the database.
Tip: Remember to replace IP and port with actual data.

Successful example:

Example of failure:

2.5, Error troubleshooting

If following the above steps, the test is successful, please ignore this section.

If it cannot be connected, please delete the cloud networking and reconfigure it according to the above process.

If still unable to connect, please execute on the server:

Bash
1
iptables - nvL

or

Bash
1
route - n

FAQ: IP segment conflict

From the above, it can be found that the IP segment of the database conflicts with the IP segment of the local Docker, both of which are at 172.17.x.x/16, so the configuration of Docker needs to be modified.
exist

/etc/docker/daemon.json
add:
json
1
    "bip": "172.20.0.1/16"

For example, after adding, the full configuration file is:

Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.

Note: Please check for JSON syntax.
After the addition is complete, save it in the Bt or manually restart Docker. It is recommended to use the Bt Linux panel, which will automatically restart Docker and the container after saving the configuration.

Bt server panel, one-click all-round deployment and management, give you a gift package of 3188 yuan, click me to receive https://www.bt.cn/?invite_code=MV93cm1wcGQ=

If you still cannot connect after checking this problem, please submit a ticket or apply for online support on Tencent Cloud.

3, data migration

Tencent Cloud provides online management, but it is not friendly to mobile terminals and requires a Tencent Cloud account to log in. phpMyAdmin is recommended here.
Note: Before performing the steps below, please log in to the server and export each database individually to .sql or .csv format, you can use phpMyAdmin.

3.1. Use online tools

Visit https://dms.cloud.tencent.com/#/login, select the corresponding instance, and enter the root account password set earlier to log in.

3.1.1, import data

Select Library Management,

Click New Database.

Select Import and Export, and click Import.

Select the database you just created and upload the corresponding .sql file to import.

3.1.2, create user

Back to the cluster management of cloud-native databases,

Create a new account in Account Management.

The account and password are the same as those of the old database.
Note: Please fill in the internal IP of the server viewed above for the host name. If you fill in the external IP, the connection will be refused!

3.1.3, assign permissions

Newly created accounts do not have any permissions by default. Therefore, we have to assign the corresponding permissions.
Go back to Account Management, select the account you just created, and click Modify Permissions.

Select object-level privileges, select corresponding database, and enable all permissions.

3.2, using phpMyAdmin

The installation part can be done with one key in the Bt panel, so only the connection operation is required.
Under phpMyAdmin, the configuration file

/www/server/phpmyadmin/phpmyadmin_.../config.inc.php
about line 32
Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.

You can use the corresponding account password to log in to the phpMyAdmin management database.

I believe everyone is familiar with phpMyAdmin, so the import, export and permission assignment using this method will not be repeated.

4. Conclusion

Although after connecting to the cloud database, the website seems to be faster, the separation of the site and library is safer, and the server load is not so high; however, it is always awkward to not be able to use the Bt panel to manage the database. I tried to modify the Bt panel file, but couldn't find a way to make the Bt's database page connect to the cloud database.

Tencent Cloud Lighthouse Accesses TDSQL-C (Cloud Native Database)

https://blog.tsinbei.com/en/archives/157/

Author
Hsukqi Lee
Posted on

2022-02-07

Edited on

2022-07-28

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet