mongodb單節(jié)點副本集添加仲裁

服務(wù)器信息

ip 系統(tǒng) 配置 服務(wù) 目錄
172.24.32.201 centos7.7 2c4g mongo-primary /var/lib/mongo (the data directory) /var/log/mongodb (the log directory)
172.24.32.201 centos7.7 2c4g mongo-secondary /var/lib/mongo27018 (the data directory) /var/log/mongodb27018 (the log directory)
172.24.32.201 centos7.7 2c4g mongo-abiter /var/lib/mongo27019 (the data directory) /var/log/mongodb27019 (the log directory)

創(chuàng)建新的mongo實例巷送,27019,具體文檔參考mongo單點升級成單節(jié)點副本
這里直接貼出指令:

mkdir -p /var/log/mongodb27019/
mkdir -p /var/lib/mongo27019
chown mongod:mongod /var/log/mongodb27019/ &&chmod 0755 /var/log/mongodb27019/
chown mongod:mongod /var/lib/mongo27019/ &&chmod 0755 /var/lib/mongo27019/

-------------------------------------------------------------------------
cat >>/etc/mongod27019.conf<<EOF
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb27019/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/mongo27019
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb27019/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27019
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.
setParameter:
    enableLocalhostAuthBypass: true


#security:

#operationProfiling:

#replication:
replication:
   replSetName: lugotestrepl

#sharding:

## Enterprise-Only Options
security:
    keyFile: /etc/mongokey/mongodb-keyfile
    clusterAuthMode: keyFile

sharding:
  clusterRole: shardsvr

EOF

-----------------------------------------------------------------------------
cat >>/usr/lib/systemd/system/mongod27019.service<<EOF
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod27019.conf"
ExecStart=/usr/bin/mongod $OPTIONS 
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb27019
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb27019
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb27019
PermissionsStartOnly=true
PIDFile=/var/run/mongodb27019/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

EOF

啟動并且開機自啟動

systemctl daemon-reload
systemctl start mongod27019
systemctl enable mongod27019

添加仲裁

進入mongo27017(primary節(jié)點)

添加仲裁

rs.addArb('172.24.32.201:27019')

結(jié)果如下:

lugotestrepl:PRIMARY> db.auth('admin','test123')
1
lugotestrepl:PRIMARY> rs.addArb('172.24.32.201:27019')
{ "ok" : 1 }

查看副本集拓撲結(jié)構(gòu)

rs.status()
lugotestrepl:PRIMARY> rs.status()
{
    "set" : "lugotestrepl",
    "date" : ISODate("2020-05-14T08:10:49.745Z"),
    "myState" : 1,
    "term" : NumberLong(2),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "172.24.32.201:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 3989,
            "optime" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-14T08:10:43Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589439871, 1),
            "electionDate" : ISODate("2020-05-14T07:04:31Z"),
            "configVersion" : 3,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "172.24.32.201:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 3978,
            "optime" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-14T08:10:43Z"),
            "optimeDurableDate" : ISODate("2020-05-14T08:10:43Z"),
            "lastHeartbeat" : ISODate("2020-05-14T08:10:49.635Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-14T08:10:49.672Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "172.24.32.201:27017",
            "syncSourceHost" : "172.24.32.201:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 3
        },
        {
            "_id" : 2,
            "name" : "172.24.32.201:27019",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",
            "uptime" : 78,
            "lastHeartbeat" : ISODate("2020-05-14T08:10:49.635Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-14T08:10:46.739Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "configVersion" : 3
        }
    ],
    "ok" : 1
}

驗證數(shù)據(jù)可用性夫凸,插入一條數(shù)據(jù)坠韩,并且查看所有數(shù)據(jù)

lugotestrepl:PRIMARY> use lugotest;
switched to db lugotest
lugotestrepl:PRIMARY> db.auth('lugo','test123')
1
lugotestrepl:PRIMARY> show collections;
movie
lugotestrepl:PRIMARY> db.movie.insert({"moviename":"殺死比爾","points":"9.0"});

查看

lugotestrepl:PRIMARY> db.movie.find().pretty()
{
    "_id" : ObjectId("5ebbbca5692adbface98b2af"),
    "moviename" : "大偵探福爾摩斯",
    "points" : "9.5"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b0"),
    "moviename" : "掠奪",
    "points" : "9.2"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b1"),
    "moviename" : "搖滾黑幫",
    "points" : "9.9"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b2"),
    "moviename" : "兩桿大煙槍",
    "points" : "9.1"
}
{
    "_id" : ObjectId("5ebcff34df72ed1bb0505234"),
    "moviename" : "殺死比爾",
    "points" : "9.0"
}

去secondary節(jié)點查看數(shù)據(jù)

lugotestrepl:SECONDARY> rs.slaveOk();
lugotestrepl:SECONDARY> db.auth('lugo','test123')
1
lugotestrepl:SECONDARY> db.movie.find().pretty()
{
    "_id" : ObjectId("5ebbbca5692adbface98b2af"),
    "moviename" : "大偵探福爾摩斯",
    "points" : "9.5"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b0"),
    "moviename" : "掠奪",
    "points" : "9.2"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b1"),
    "moviename" : "搖滾黑幫",
    "points" : "9.9"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b2"),
    "moviename" : "兩桿大煙槍",
    "points" : "9.1"
}
{
    "_id" : ObjectId("5ebcff34df72ed1bb0505234"),
    "moviename" : "殺死比爾",
    "points" : "9.0"
}

數(shù)據(jù)一致

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末塑娇,一起剝皮案震驚了整個濱河市十偶,隨后出現(xiàn)的幾起案子学歧,更是在濱河造成了極大的恐慌勾效,老刑警劉巖饭入,帶你破解...
    沈念sama閱讀 206,602評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嵌器,死亡現(xiàn)場離奇詭異,居然都是意外死亡谐丢,警方通過查閱死者的電腦和手機爽航,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評論 2 382
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人岳掐,你說我怎么就攤上這事凭疮。” “怎么了串述?”我有些...
    開封第一講書人閱讀 152,878評論 0 344
  • 文/不壞的土叔 我叫張陵执解,是天一觀的道長。 經(jīng)常有香客問我纲酗,道長衰腌,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,306評論 1 279
  • 正文 為了忘掉前任觅赊,我火速辦了婚禮右蕊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘吮螺。我一直安慰自己饶囚,他們只是感情好,可當我...
    茶點故事閱讀 64,330評論 5 373
  • 文/花漫 我一把揭開白布鸠补。 她就那樣靜靜地躺著萝风,像睡著了一般。 火紅的嫁衣襯著肌膚如雪紫岩。 梳的紋絲不亂的頭發(fā)上规惰,一...
    開封第一講書人閱讀 49,071評論 1 285
  • 那天,我揣著相機與錄音泉蝌,去河邊找鬼歇万。 笑死,一個胖子當著我的面吹牛勋陪,可吹牛的內(nèi)容都是我干的贪磺。 我是一名探鬼主播,決...
    沈念sama閱讀 38,382評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼粥鞋,長吁一口氣:“原來是場噩夢啊……” “哼缘挽!你這毒婦竟也來了瞄崇?” 一聲冷哼從身側(cè)響起呻粹,我...
    開封第一講書人閱讀 37,006評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎苏研,沒想到半個月后等浊,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,512評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡摹蘑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,965評論 2 325
  • 正文 我和宋清朗相戀三年筹燕,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,094評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡撒踪,死狀恐怖过咬,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情制妄,我是刑警寧澤掸绞,帶...
    沈念sama閱讀 33,732評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站耕捞,受9級特大地震影響衔掸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜俺抽,卻給世界環(huán)境...
    茶點故事閱讀 39,283評論 3 307
  • 文/蒙蒙 一敞映、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧磷斧,春花似錦振愿、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,286評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至孩哑,卻和暖如春栓霜,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背横蜒。 一陣腳步聲響...
    開封第一講書人閱讀 31,512評論 1 262
  • 我被黑心中介騙來泰國打工胳蛮, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人丛晌。 一個月前我還...
    沈念sama閱讀 45,536評論 2 354
  • 正文 我出身青樓仅炊,卻偏偏與公主長得像,于是被迫代替她去往敵國和親澎蛛。 傳聞我的和親對象是個殘疾皇子抚垄,可洞房花燭夜當晚...
    茶點故事閱讀 42,828評論 2 345

推薦閱讀更多精彩內(nèi)容