Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add listen_host for TiDB/TiKV/PD to specified the listen host #495

Merged
merged 10 commits into from
Jun 15, 2020
4 changes: 2 additions & 2 deletions pkg/cluster/embed/autogen_pkger.go

Large diffs are not rendered by default.

60 changes: 37 additions & 23 deletions pkg/cluster/meta/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ func PortStopped(e executor.TiOpsExecutor, port int, timeout int64) error {
type instance struct {
InstanceSpec

name string
host string
port int
sshp int
topo *ClusterSpecification
name string
host string
listenAddress string
port int
sshp int
topo *ClusterSpecification

usedPorts []int
usedDirs []string
Expand Down Expand Up @@ -248,6 +249,14 @@ func (i *instance) GetHost() string {
return i.host
}

// GetListenAddress implements Instance interface
func (i *instance) GetListenAddress() string {
if len(i.listenAddress) == 0 {
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
return "0.0.0.0"
}
return i.listenAddress
}

// GetSSHPort implements Instance interface
func (i *instance) GetSSHPort() int {
return i.sshp
Expand Down Expand Up @@ -357,12 +366,13 @@ func (c *TiDBComponent) Instances() []Instance {
for _, s := range c.TiDBServers {
s := s
ins = append(ins, &TiDBInstance{instance{
InstanceSpec: s,
name: c.Name(),
host: s.Host,
port: s.Port,
sshp: s.SSHPort,
topo: c.ClusterSpecification,
InstanceSpec: s,
name: c.Name(),
host: s.Host,
listenAddress: s.ListenAddress,
port: s.Port,
sshp: s.SSHPort,
topo: c.ClusterSpecification,

usedPorts: []int{
s.Port,
Expand Down Expand Up @@ -391,6 +401,7 @@ func (i *TiDBInstance) InitConfig(e executor.TiOpsExecutor, clusterName, cluster
spec := i.InstanceSpec.(TiDBSpec)
cfg := scripts.NewTiDBScript(
i.GetHost(),
i.GetListenAddress(),
paths.Deploy,
paths.Log,
).WithPort(spec.Port).WithNumaNode(spec.NumaNode).WithStatusPort(spec.StatusPort).AppendEndpoints(i.instance.topo.Endpoints(deployUser)...)
Expand Down Expand Up @@ -462,12 +473,13 @@ func (c *TiKVComponent) Instances() []Instance {
for _, s := range c.TiKVServers {
s := s
ins = append(ins, &TiKVInstance{instance{
InstanceSpec: s,
name: c.Name(),
host: s.Host,
port: s.Port,
sshp: s.SSHPort,
topo: c.ClusterSpecification,
InstanceSpec: s,
name: c.Name(),
host: s.Host,
listenAddress: s.ListenAddress,
port: s.Port,
sshp: s.SSHPort,
topo: c.ClusterSpecification,

usedPorts: []int{
s.Port,
Expand Down Expand Up @@ -497,6 +509,7 @@ func (i *TiKVInstance) InitConfig(e executor.TiOpsExecutor, clusterName, cluster
spec := i.InstanceSpec.(TiKVSpec)
cfg := scripts.NewTiKVScript(
i.GetHost(),
i.GetListenAddress(),
paths.Deploy,
paths.Data[0],
paths.Log,
Expand Down Expand Up @@ -572,12 +585,13 @@ func (c *PDComponent) Instances() []Instance {
ins = append(ins, &PDInstance{
Name: s.Name,
instance: instance{
InstanceSpec: s,
name: c.Name(),
host: s.Host,
port: s.ClientPort,
sshp: s.SSHPort,
topo: c.ClusterSpecification,
InstanceSpec: s,
name: c.Name(),
host: s.Host,
listenAddress: s.ListenAddress,
port: s.ClientPort,
sshp: s.SSHPort,
topo: c.ClusterSpecification,

usedPorts: []int{
s.ClientPort,
Expand Down
9 changes: 6 additions & 3 deletions pkg/cluster/meta/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func AllComponentNames() (roles []string) {
// TiDBSpec represents the TiDB topology specification in topology.yaml
type TiDBSpec struct {
Host string `yaml:"host"`
ListenAddress string `yaml:"listen_address"`
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
SSHPort int `yaml:"ssh_port,omitempty"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"4000"`
Expand Down Expand Up @@ -185,6 +186,7 @@ func (s TiDBSpec) IsImported() bool {
// TiKVSpec represents the TiKV topology specification in topology.yaml
type TiKVSpec struct {
Host string `yaml:"host"`
ListenAddress string `yaml:"listen_address"`
SSHPort int `yaml:"ssh_port,omitempty"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"20160"`
Expand Down Expand Up @@ -263,9 +265,10 @@ func (s TiKVSpec) IsImported() bool {

// PDSpec represents the PD topology specification in topology.yaml
type PDSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
Imported bool `yaml:"imported,omitempty"`
Host string `yaml:"host"`
ListenAddress string `yaml:"listen_address"`
SSHPort int `yaml:"ssh_port,omitempty"`
Imported bool `yaml:"imported,omitempty"`
// Use Name to get the name with a default value if it's empty.
Name string `yaml:"name"`
ClientPort int `yaml:"client_port" default:"2379"`
Expand Down
28 changes: 15 additions & 13 deletions pkg/cluster/template/scripts/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ import (

// TiDBScript represent the data to generate TiDB config
type TiDBScript struct {
IP string
Port int
StatusPort int
DeployDir string
LogDir string
NumaNode string
Endpoints []*PDScript
IP string
ListenAddress string
Port int
StatusPort int
DeployDir string
LogDir string
NumaNode string
Endpoints []*PDScript
}

// NewTiDBScript returns a TiDBScript with given arguments
func NewTiDBScript(ip, deployDir, logDir string) *TiDBScript {
func NewTiDBScript(ip, listenAddress, deployDir, logDir string) *TiDBScript {
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
return &TiDBScript{
IP: ip,
Port: 4000,
StatusPort: 10080,
DeployDir: deployDir,
LogDir: logDir,
IP: ip,
ListenAddress: listenAddress,
Port: 4000,
StatusPort: 10080,
DeployDir: deployDir,
LogDir: logDir,
}
}

Expand Down
32 changes: 17 additions & 15 deletions pkg/cluster/template/scripts/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,27 @@ import (

// TiKVScript represent the data to generate TiKV config
type TiKVScript struct {
IP string
Port int
StatusPort int
DeployDir string
DataDir string
LogDir string
NumaNode string
Endpoints []*PDScript
IP string
ListenAddress string
Port int
StatusPort int
DeployDir string
DataDir string
LogDir string
NumaNode string
Endpoints []*PDScript
}

// NewTiKVScript returns a TiKVScript with given arguments
func NewTiKVScript(ip, deployDir, dataDir, logDir string) *TiKVScript {
func NewTiKVScript(ip, listenAddress, deployDir, dataDir, logDir string) *TiKVScript {
return &TiKVScript{
IP: ip,
Port: 20160,
StatusPort: 20180,
DeployDir: deployDir,
DataDir: dataDir,
LogDir: logDir,
IP: ip,
ListenAddress: listenAddress,
Port: 20160,
StatusPort: 20180,
DeployDir: deployDir,
DataDir: dataDir,
LogDir: logDir,
}
}

Expand Down
1 change: 1 addition & 0 deletions templates/scripts/run_tidb.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exec env GODEBUG=madvdontneed=1 bin/tidb-server \
{{- end}}
-P {{.Port}} \
--status="{{.StatusPort}}" \
--host="{{.ListenAddress}}" \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add --status-host="{{.ListenAddress}}" , too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--advertise-address="{{.IP}}" \
--store="tikv" \
--config="conf/tidb.toml" \
Expand Down
2 changes: 1 addition & 1 deletion templates/scripts/run_tikv.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/tikv-server
{{- else}}
exec bin/tikv-server \
{{- end}}
--addr "0.0.0.0:{{.Port}}" \
--addr "{{.ListenAddress}}:{{.Port}}" \
--advertise-addr "{{.IP}}:{{.Port}}" \
--status-addr "{{.IP}}:{{.StatusPort}}" \
--pd "{{template "PDList" .Endpoints}}" \
Expand Down