tiup playground 如何指定端口号

tiup playground只启动一个实例的时候用的是4000,启动第二个实例的时候端口号似乎就不是固定的了,要如何指定?help里也没有提到端口号。

Examples:
  $ tiup playground nightly                         # Start a TiDB nightly version local cluster
  $ tiup playground v5.0.1 --db 3 --pd 3 --kv 3     # Start a local cluster with 10 nodes
  $ tiup playground nightly --monitor=false         # Start a local cluster and disable monitor system
  $ tiup playground --pd.config ~/config/pd.toml    # Start a local cluster with specified configuration file
  $ tiup playground --db.binpath /xx/tidb-server    # Start a local cluster with component binary path
  $ tiup playground --mode tikv-slim                # Start a local tikv only cluster (No TiDB or TiFlash Available)
  $ tiup playground --mode tikv-slim --kv 3 --pd 3  # Start a local tikv only cluster with 6 nodes

Usage:
  tiup playground [version] [flags]
  tiup [command]

Available Commands:
  display
  help        Help about any command
  scale-in
  scale-out

Flags:
      --db int                   TiDB instance number
      --db.Host host             Playground TiDB host. If not provided, TiDB will still use host flag as its host
      --db.binpath string        TiDB instance binary path
      --db.config string         TiDB instance configuration file
      --db.timeout int           TiDB max wait time in seconds for starting, 0 means no limit
      --drainer int              Drainer instance number
      --drainer.binpath string   Drainer instance binary path
      --drainer.config string    Drainer instance configuration file
  -h, --help                     help for tiup
      --host string              Playground cluster host
      --kv int                   TiKV instance number
      --kv.binpath string        TiKV instance binary path
      --kv.config string         TiKV instance configuration file
      --mode string              TiUP playground mode: 'tidb', 'tikv-slim' (default "tidb")
      --monitor                  Start prometheus and grafana component
      --pd int                   PD instance number
      --pd.Host host             Playground PD host. If not provided, PD will still use host flag as its host
      --pd.binpath string        PD instance binary path
      --pd.config string         PD instance configuration file
      --pump int                 Pump instance number
      --pump.binpath string      Pump instance binary path
      --pump.config string       Pump instance configuration file
      --ticdc int                TiCDC instance number
      --ticdc.binpath string     TiCDC instance binary path
      --ticdc.config string      TiCDC instance configuration file
      --tiflash int              TiFlash instance number
      --tiflash.binpath string   TiFlash instance binary path
      --tiflash.config string    TiFlash instance configuration file
      --tiflash.timeout int      TiFlash max wait time in seconds for starting, 0 means no limit
  -v, --version                  version for tiup
1 个赞

参考一下这里的第5条编辑配置文件的方式,指定端口号

https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb#实施部署

tiup playground --db.config config.toml
Starting component playground: /root/.tiup/components/playground/v1.5.3/tiup-playground --db.config config.toml
Using the version v5.1.1 for version constraint “”.

If you’d like to use a TiDB version other than v5.1.1, cancel and retry with the following arguments:
Specify version manually: tiup playground
Specify version range: tiup playground ^5
The nightly version: tiup playground nightly

Playground Bootstrapping…
Start pd instance
Start tikv instance
Start tidb instance
Waiting for tidb instances ready
127.0.0.1:4000 … Error
To view the dashboard: http://127.0.0.1:2379/dashboard
PD client endpoints: [127.0.0.1:2379]
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000

config.toml 内容
https://github.com/pingcap/tidb/blob/master/config/config.toml.example

没有生效吧?

被你发现了,我今天换台虚机试试,之前用的WSL

终于破案了。
今天看了tiup的源代码发现tiup playground 启动tidb时翻译过来是按照类似如下方式传的参数
tidb -P 4000 --config [ConfigPath]
由于-P参数优先级高,所以这块就意味着tiup playground 启动tidb时是硬编码端口参数为4000
试图使用配置文件的方式是无法修改tidb的端口号的。
我可以尝试提个MR试试修复一下。:smile:

// NewTiDBInstance return a TiDBInstance
func NewTiDBInstance(binPath string, dir, host, configPath string, id int, pds []*PDInstance, enableBinlog bool) *TiDBInstance {
        return &TiDBInstance{
                instance: instance{
                        BinPath:    binPath,
                        ID:         id,
                        Dir:        dir,
                        Host:       host,
                        Port:       utils.MustGetFreePort(host, 4000),
                        StatusPort: utils.MustGetFreePort("0.0.0.0", 10080),
                        ConfigPath: configPath,
                },
                pds:          pds,
                enableBinlog: enableBinlog,
        }
}

// Start calls set inst.cmd and Start
func (inst *TiDBInstance) Start(ctx context.Context, version utils.Version) error {
        endpoints := pdEndpoints(inst.pds, false)

        args := []string{
                "-P", strconv.Itoa(inst.Port),
                "--store=tikv",
                fmt.Sprintf("--host=%s", inst.Host),
                fmt.Sprintf("--status=%d", inst.StatusPort),
                fmt.Sprintf("--path=%s", strings.Join(endpoints, ",")),
                fmt.Sprintf("--log-file=%s", filepath.Join(inst.Dir, "tidb.log")),
        }
        if inst.ConfigPath != "" {
                args = append(args, fmt.Sprintf("--config=%s", inst.ConfigPath))
        }
        if inst.enableBinlog {
                args = append(args, "--enable-binlog=true")
        }

        var err error
        if inst.Process, err = NewComponentProcess(ctx, inst.Dir, inst.BinPath, "tidb", version, args...); err != nil {
                return err
        }
        logIfErr(inst.Process.SetOutputFile(inst.LogFile()))

        return inst.Process.Start()
}

https://github.com/pingcap/tiup/blob/9a1ad59928c00b88c8844ca6aa76ad139be7e6d9/components/playground/instance/tidb.go#L35

4 个赞

不愧是候选人,yyds~:+1:

https://github.com/pingcap/tiup/pull/1511 看到已经修复了

此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。