mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(master,meta,data): add switch to control whether use target ip when start service
Closes #1826 Signed-off-by: Victor1319 <834863182@qq.com>
This commit is contained in:
parent
6175df4eb5
commit
e1ac90fba8
@ -112,6 +112,7 @@ type DataNode struct {
|
||||
zoneName string
|
||||
clusterID string
|
||||
localIP string
|
||||
bindIp bool
|
||||
localServerAddr string
|
||||
nodeID uint64
|
||||
raftDir string
|
||||
@ -255,6 +256,7 @@ func (s *DataNode) parseConfig(cfg *config.Config) (err error) {
|
||||
)
|
||||
LocalIP = cfg.GetString(ConfigKeyLocalIP)
|
||||
port = cfg.GetString(proto.ListenPort)
|
||||
s.bindIp = cfg.GetBool(proto.BindIpKey)
|
||||
serverPort = port
|
||||
if regexpPort, err = regexp.Compile("^(\\d)+$"); err != nil {
|
||||
return fmt.Errorf("Err:no port")
|
||||
@ -537,7 +539,10 @@ func (s *DataNode) registerHandler() {
|
||||
|
||||
func (s *DataNode) startTCPService() (err error) {
|
||||
log.LogInfo("Start: startTCPService")
|
||||
addr := fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
addr := fmt.Sprintf(":%v", s.port)
|
||||
if s.bindIp {
|
||||
addr = fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
}
|
||||
l, err := net.Listen(NetworkProtocol, addr)
|
||||
log.LogDebugf("action[startTCPService] listen %v address(%v).", NetworkProtocol, addr)
|
||||
if err != nil {
|
||||
@ -581,7 +586,10 @@ func (s *DataNode) serveConn(conn net.Conn) {
|
||||
|
||||
func (s *DataNode) startSmuxService(cfg *config.Config) (err error) {
|
||||
log.LogInfo("Start: startSmuxService")
|
||||
addr := fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
addr := fmt.Sprintf(":%v", s.port)
|
||||
if s.bindIp {
|
||||
addr = fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
}
|
||||
addr = util.ShiftAddrPort(addr, s.smuxPortShift)
|
||||
log.LogInfof("SmuxListenAddr: (%v)", addr)
|
||||
|
||||
|
||||
@ -37,10 +37,16 @@ func (m *Server) startHTTPService(modulename string, cfg *config.Config) {
|
||||
m.registerAPIRoutes(router)
|
||||
m.registerAPIMiddleware(router)
|
||||
exporter.InitWithRouter(modulename, cfg, router, m.port)
|
||||
addr := fmt.Sprintf(":%s", m.port)
|
||||
if m.bindIp {
|
||||
addr = fmt.Sprintf("%s:%s", m.ip, m.port)
|
||||
}
|
||||
|
||||
var server = &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%s", m.ip, m.port),
|
||||
Addr: addr,
|
||||
Handler: router,
|
||||
}
|
||||
|
||||
var serveAPI = func() {
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
log.LogErrorf("serveAPI: serve http server failed: err(%v)", err)
|
||||
|
||||
@ -17,7 +17,6 @@ package master
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cubefs/cubefs/util/stat"
|
||||
syslog "log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@ -25,6 +24,8 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/cubefs/cubefs/util/stat"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/raftstore"
|
||||
"github.com/cubefs/cubefs/util/config"
|
||||
@ -111,6 +112,7 @@ type Server struct {
|
||||
id uint64
|
||||
clusterName string
|
||||
ip string
|
||||
bindIp bool
|
||||
port string
|
||||
logDir string
|
||||
walDir string
|
||||
@ -202,6 +204,7 @@ func (m *Server) checkConfig(cfg *config.Config) (err error) {
|
||||
|
||||
m.clusterName = cfg.GetString(ClusterName)
|
||||
m.ip = cfg.GetString(IP)
|
||||
m.bindIp = cfg.GetBool(proto.BindIpKey)
|
||||
m.port = cfg.GetString(proto.ListenPort)
|
||||
m.logDir = cfg.GetString(LogDir)
|
||||
m.walDir = cfg.GetString(WalDir)
|
||||
|
||||
@ -53,6 +53,7 @@ var (
|
||||
type MetaNode struct {
|
||||
nodeId uint64
|
||||
listen string
|
||||
bindIp bool
|
||||
metadataDir string // root dir of the metaNode
|
||||
raftDir string // root dir of the raftStore log
|
||||
metadataManager MetadataManager
|
||||
@ -186,6 +187,7 @@ func (m *MetaNode) parseConfig(cfg *config.Config) (err error) {
|
||||
}
|
||||
m.localAddr = cfg.GetString(cfgLocalIP)
|
||||
m.listen = cfg.GetString(proto.ListenPort)
|
||||
m.bindIp = cfg.GetBool(proto.BindIpKey)
|
||||
serverPort = m.listen
|
||||
m.metadataDir = cfg.GetString(cfgMetadataDir)
|
||||
m.raftDir = cfg.GetString(cfgRaftDir)
|
||||
|
||||
@ -37,7 +37,6 @@ func NewInodeResponse() *InodeResponse {
|
||||
// Create and inode and attach it to the inode tree.
|
||||
func (mp *metaPartition) fsmCreateInode(ino *Inode) (status uint8) {
|
||||
status = proto.OpOk
|
||||
log.LogDebugf("execute fsmCreateInode to create ino, %v", ino.Inode)
|
||||
if _, ok := mp.inodeTree.ReplaceOrInsert(ino, false); !ok {
|
||||
status = proto.OpExistErr
|
||||
}
|
||||
|
||||
@ -30,7 +30,12 @@ import (
|
||||
func (m *MetaNode) startServer() (err error) {
|
||||
// initialize and start the server.
|
||||
m.httpStopC = make(chan uint8)
|
||||
addr := fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
|
||||
addr := fmt.Sprintf(":%s", m.listen)
|
||||
if m.bindIp {
|
||||
addr = fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
@ -105,7 +110,11 @@ func (m *MetaNode) handlePacket(conn net.Conn, p *Packet,
|
||||
func (m *MetaNode) startSmuxServer() (err error) {
|
||||
// initialize and start the server.
|
||||
m.smuxStopC = make(chan uint8)
|
||||
ipPort := fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
|
||||
ipPort := fmt.Sprintf(":%s", m.listen)
|
||||
if m.bindIp {
|
||||
ipPort = fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
}
|
||||
addr := util.ShiftAddrPort(ipPort, smuxPortShift)
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
|
||||
@ -76,6 +76,7 @@ const (
|
||||
MasterAddr = "masterAddr"
|
||||
ListenPort = "listen"
|
||||
ObjectNodeDomain = "objectNodeDomain"
|
||||
BindIpKey = "bindIp"
|
||||
)
|
||||
|
||||
type MountOption struct {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
"role": "datanode",
|
||||
"listen": "17310",
|
||||
"localIP": "_ip_",
|
||||
"bindIp": "true",
|
||||
"raftHeartbeat": "17330",
|
||||
"raftReplica": "17340",
|
||||
"raftDir": "_dir_/raftlog/datanode",
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
"id": "_id_",
|
||||
"role": "master",
|
||||
"ip": "_ip_",
|
||||
"bindIp": "true",
|
||||
"listen": "17010",
|
||||
"peers": "_peers_",
|
||||
"retainLogs": "2000",
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
"role": "metanode",
|
||||
"listen": "17210",
|
||||
"localIP": "_ip_",
|
||||
"bindIp": "true",
|
||||
"raftHeartbeatPort": "17230",
|
||||
"raftReplicaPort": "17240",
|
||||
"logLevel": "debug",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user