How to change the TiDB server port from 4000 to 4001 using Ansible

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: ansible 如何修改tidb server端口4000为4001

| username: kuweilong666

【TiDB Usage Environment】Production Environment
【TiDB Version】4.0
【Reproduction Path】What operations were performed when the issue occurred
【Encountered Issue: Issue Phenomenon and Impact】
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots/Logs/Monitoring】

| username: tidb菜鸟一只 | Original post link

Just modify the configuration file directly, and reload it after the modification.

| username: kuweilong666 | Original post link

I can’t find which configuration file it is in.

| username: caiyfc | Original post link

To be safe, you can scale out a TiDB node with port 4001 on the same machine, and then scale in the TiDB node with port 4000.

| username: 裤衩儿飞上天 | Original post link

Two methods:

  1. Modify by first scaling in and then scaling out.
  2. Modify using the following method (execute after production testing):
    https://docs.pingcap.com/zh/tidb/stable/maintain-tidb-using-tiup#修改配置参数
| username: kuweilong666 | Original post link

How to use ansible-playbook?

| username: tidb菜鸟一只 | Original post link

You can directly modify it using tiup cluster edit-config ${cluster-name}.

| username: wink | Original post link

You can change the TiDB port by modifying the TiDB configuration file. On the machine where TiDB is deployed, locate the TiDB configuration file conf/tidb.toml and modify the port configuration item. For example, to change the TiDB port to 4000:

[server]
port = 4000

After making the changes, you need to restart the TiDB service for the configuration to take effect. You can use the following command to restart TiDB:

ansible-playbook start.yml --tags=tidb

For more information about the TiDB configuration file, you can refer to the official documentation: https://docs.pingcap.com/zh/tidb/stable/config-file-description#tidb-configuration-file

| username: kuweilong666 | Original post link

tidb.toml did not find port
tidb.toml (1.4 KB)

| username: 裤衩儿飞上天 | Original post link

If the port is not specified in the configuration file, the default port 4000 will be used. If not configured, you can explicitly specify the port, and it will use the specified port.

| username: Amy_Jing | Original post link

You can use the tidb_server_config module provided by Ansible. Here are the steps to use this module:

  1. Open the Ansible playbook file and add the following task in the tasks section:

    - name: Modify TiDB server port
      tidb_server_config:
        state: present
        tidb_server_port: new_port_number
    

    This will use the tidb_server_config module to update the port number in the tidb-server.toml configuration file to the new port number you specify.

  2. Include the tidb_topology execution in the deployment process.

    - name: Deploy TiDB cluster
      hosts: tidb_servers
      become: true
      roles:
        - tidb-deploy
    
  3. Specify vars in the playbook file to pass the port number you want to change to tidb_server_port.

    - name: Deploy TiDB cluster
      hosts: tidb_servers
      become: true
      vars:
        tidb_server_port: 4001
      roles:
        - tidb-deploy
    

    In this example, the new port number is set to 4001.

  4. Run the Ansible playbook file to deploy the TiDB cluster and change the port number.

    ansible-playbook deploy.yml
    

This way, you can use Ansible to change the TiDB server port number to the new port number you specify.

| username: kuweilong666 | Original post link

Solved, directly modified the port in scripts/run_tidb.sh.

| username: Kongdom | Original post link

:+1: :+1: :+1:

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.