Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (s *Client) AddMembers(members []Member) error
- func (s *Client) ChangeUserPassword(name, pw string) error
- func (s *Client) CheckMemberStatus() (error, []string, []string)
- func (s *Client) CheckReplSetInit() error
- func (s *Client) CreateUserBySecret(usersSecret *corev1.Secret) error
- func (s *Client) CreateUserBySpec(user, pw string, roles primitive.A) error
- func (s *Client) GetMgoNodeInfo() (*ServerStatusRepl, error)
- func (s *Client) ReadConfig() (*RSConfig, error)
- func (s *Client) RemoveMembers(members []Member) error
- func (s *Client) ReplMemberStatus() ([]MemberStatus, error)
- func (s *Client) RunCommand(cmd bson.D, pResult interface{}) error
- func (s *Client) StepDown() error
- func (s *Client) WriteConfig(cfg *RSConfig) error
- func (s *Client) WriteConfigWithForce(cfg *RSConfig) error
- type DBServerStatusReplResponse
- type Member
- type MemberStatus
- type OKResponse
- type RSConfig
- type RSConfigWrap
- type RSStatusResponse
- type ReplsetTags
- type ServerStatusRepl
- type Settings
- type WriteConcern
Constants ¶
View Source
const ( DbAdmin = "admin" DbLocal = "local" MaxMembers = 50 CmdOk = 1 MongoRoot = "root" // 最高权限,暴露给dba MongoClusterAdmin = "clusterAdmin" // operator内部使用,只有管理权限没有读写权限 MongoClusterMonitor = "clusterMonitor" // 监控使用 MongoReadWrite = "readWrite" // 数据库读写权限 MongoUser = "MONGO_USER" MongoPassword = "MONGO_PASSWORD" MongoRole = "MONGO_ROLE" MongoDB = "MONGO_DB" )
View Source
const ( Primary = "PRIMARY" Secondary = "SECONDARY" Arbiter = "ARBITER" )
View Source
const ( // %s里不能使用单引号(') MongoShellEvalWithAuth = `mongo -u root -p '%s' --eval '%s'` MongoShellEvalNoAuth = `mongo --eval '%s'` // success: // "ok" : 1 // fail: // {"info":"try querying local.system.replset to see current configuration","ok":0,"errmsg":"already initialized","code":23,"codeName":"AlreadyInitialized"} // errmsg\" : \"Our config version of 1 is no larger than the version on 10.29.5.107:30247, which is 1\",\ RSIntitate = `rs.initiate({_id: "%s", members: %s});` // 当多个节点共同初始化时,会生成不一样的replicaSetId RSReconfig = `rs.reconfig({_id: "%s", members: %s, force: true });` DBServerStatusReplMe = `db.serverStatus().repl.me;` // success: // "ok" : 1 // fail: // "ok" : 0 RSStatus = `rs.status();` RSAlreadyInitialized = `AlreadyInitialized` RSConfigIncompatible = `NewReplicaSetConfigurationIncompatible` OK = `"ok" : 1` // success: // Successfully added user // fail: // Error: couldn't add user: there are no users authenticated CreateUser = ` db.getSiblingDB("admin").createUser({ user: "%s", pwd: "%s", roles: [{role: "root", db: "admin"}] }); ` CreateUserSuccess = `Successfully added user` CreateUserUnauthorized = `no users authenticated` // 在非master节点上执行了创建root用户 CreateUserNotMaster = `not master` )
mongo script
Variables ¶
View Source
var ( ErrCmdNotOk = errors2.New("command exec not ok") ErrAlreadyExists = errors2.New("already exists") )
View Source
var StaticMemberUtil = new(memberUtil)
Functions ¶
This section is empty.
Types ¶
type Client ¶
func (*Client) AddMembers ¶
func (*Client) ChangeUserPassword ¶
func (*Client) CheckMemberStatus ¶
判断所有member status是否正常
func (*Client) CreateUserBySecret ¶
func (*Client) CreateUserBySpec ¶
func (*Client) GetMgoNodeInfo ¶
func (s *Client) GetMgoNodeInfo() (*ServerStatusRepl, error)
获取当前mongo的副本集信息
func (*Client) ReadConfig ¶
func (*Client) RemoveMembers ¶
func (*Client) ReplMemberStatus ¶
func (s *Client) ReplMemberStatus() ([]MemberStatus, error)
获取集群Member状态, 在status中显示
func (*Client) RunCommand ¶
command syntax ref: https://docs.mongodb.com/manual/reference/command/
func (*Client) WriteConfig ¶
func (*Client) WriteConfigWithForce ¶
type DBServerStatusReplResponse ¶
type DBServerStatusReplResponse struct { ServerStatusRepl ServerStatusRepl `bson:"repl" json:"repl"` OK int `bson:"ok" json:"ok"` }
type Member ¶
type Member struct { Tags ReplsetTags `bson:"tags,omitempty" json:"tags,omitempty"` Host string `bson:"host" json:"host"` ID int `bson:"_id" json:"_id"` Priority int `bson:"priority" json:"priority"` SlaveDelay int64 `bson:"slaveDelay" json:"slaveDelay"` Votes int `bson:"votes" json:"votes"` ArbiterOnly bool `bson:"arbiterOnly" json:"arbiterOnly"` BuildIndexes bool `bson:"buildIndexes" json:"buildIndexes"` Hidden bool `bson:"hidden" json:"hidden"` }
type MemberStatus ¶
type MemberStatus struct { Host string `bson:"name" json:"name"` StateStr string `bson:"stateStr" json:"stateStr"` SyncingTo string `bson:"syncingTo" json:"syncingTo"` SyncSourceHost string `bson:"syncSourceHost" json:"syncSourceHost"` ID int `bson:"_id" json:"_id"` Health int `bson:"health" json:"health"` State int `bson:"state" json:"state"` }
type OKResponse ¶
type OKResponse struct { Errmsg string `bson:"errmsg,omitempty" json:"errmsg,omitempty"` OK int `bson:"ok" json:"ok"` }
OKResponse is a standard MongoDB response
type RSConfig ¶
type RSConfig struct { ID string `bson:"_id" json:"_id"` Members []Member `bson:"members" json:"members"` Settings Settings `bson:"settings,omitempty" json:"settings,omitempty"` Version int `bson:"version" json:"version"` ProtocolVersion int `bson:"protocolVersion,omitempty" json:"protocolVersion,omitempty"` Configsvr bool `bson:"configsvr,omitempty" json:"configsvr,omitempty"` WriteConcernMajorityJournalDefault bool `bson:"writeConcernMajorityJournalDefault,omitempty" json:"writeConcernMajorityJournalDefault,omitempty"` }
Member document from 'replSetGetConfig' ref: https://docs.mongodb.com/manual/reference/command/replSetGetConfig/#dbcmd.replSetGetConfig
type RSConfigWrap ¶
type RSConfigWrap struct { Config *RSConfig `bson:"config" json:"config"` Errmsg string `bson:"errmsg,omitempty" json:"errmsg,omitempty"` OK int `bson:"ok" json:"ok"` }
runCommand resp外层有ok等状态码
type RSStatusResponse ¶
type RSStatusResponse struct { Members []MemberStatus `bson:"members" json:"members"` OK int `bson:"ok" json:"ok"` }
type ReplsetTags ¶
type ServerStatusRepl ¶
type Settings ¶
type Settings struct { GetLastErrorModes map[string]ReplsetTags `bson:"getLastErrorModes,omitempty" json:"getLastErrorModes,omitempty"` GetLastErrorDefaults WriteConcern `bson:"getLastErrorDefaults,omitempty" json:"getLastErrorDefaults,omitempty"` HeartbeatIntervalMillis int64 `bson:"heartbeatIntervalMillis,omitempty" json:"heartbeatIntervalMillis,omitempty"` HeartbeatTimeoutSecs int `bson:"heartbeatTimeoutSecs,omitempty" json:"heartbeatTimeoutSecs,omitempty"` ElectionTimeoutMillis int64 `bson:"electionTimeoutMillis,omitempty" json:"electionTimeoutMillis,omitempty"` CatchUpTimeoutMillis int64 `bson:"catchUpTimeoutMillis,omitempty" json:"catchUpTimeoutMillis,omitempty"` ReplicaSetID primitive.ObjectID `bson:"replicaSetId,omitempty" json:"replicaSetId,omitempty"` ChainingAllowed bool `bson:"chainingAllowed,omitempty" json:"chainingAllowed,omitempty"` }
type WriteConcern ¶
type WriteConcern struct { WriteConcern interface{} `bson:"w" json:"w"` WriteTimeout int `bson:"wtimeout" json:"wtimeout"` Journal bool `bson:"j,omitempty" json:"j,omitempty"` }
ref: https://docs.mongodb.com/manual/reference/write-concern/
Click to show internal directories.
Click to hide internal directories.