บทความนี้เรามาดูวิธีการทำ Multi Master-PKI Failover กันซึ่งจะไม่เหมือนการทำ Redundant Multi Master ในบทความที่แล้ว ตรงที่เครื่อง Salt Minion จะ connection ไปที่เครื่อง Salt Master หลักเครื่องเดียว ซึ่งถ้า Salt Master หลักไม่สามารถ connection ได้ Salt Minion ถึงจะย้ายไป conection กับ Salt Master อื่นที่อยู่ตาม list ใน config ของ Salt-Minion โดยมีขั้นตอนดังนี้
เครื่องที่ต้องใช้จะมี
- Salt Master 2 เครื่องชื่อ saltmaster1 และ saltmaster2
- Salt Minion 1 เครื่องชื่อ saltminion
ที่เครื่อง saltmaster1 และ saltmaster2 ตั้งค่า Salt Master ให้สร้าง file sign public key เพื่อใช้ Authen Reply
vi /etc/salt/master
เพิ่ม config นี้ไว้บรรทัดสุดท้าย
master_sign_pubkey: True
ทำการ restart Salt Master
service salt-master restart
Salt Master จะทำการ generate key-pair ขึ้นมาใน /etc/salt/pki/master/
master_sign.pem master_sign.pub
ทำการ copy master_sign.pem และ master_sign.pub ใน /etc/salt/pki/master/ จาก saltmaster1 ไปที่ saltmaster2
ที่เครื่อง saltminion ทำการ copy file master_sign.pub จากเครื่อง saltmaster1 มาไว้ที่ /etc/salt/pki/minion/ และเพิ่ม config ที่ /etc/salt/minion
vim /etc/salt/minion
เพิ่ม config นี้ไว้บรรทัดสุดท้าย
verify_master_pubkey_sign: True
แล้ว restart Salt Minion
service salt-minion restart
แล้วทำการ run manual debug mode เพื่อดูว่า Salt Minion ทำงานปกติไหม
salt-minion -l debug
ผลลัพธ์
[DEBUG ] Attempting to authenticate with the Salt Master at 192.168.56.109 [DEBUG ] Loaded minion key: /etc/salt/pki/minion/minion.pem [DEBUG ] salt.crypt.verify_signature: Loading public key [DEBUG ] salt.crypt.verify_signature: Verifying signature [DEBUG ] Successfully verified signature of master public key with verification public key master_sign.pub [INFO ] Received signed and verified master pubkey from master 192.168.56.109 [DEBUG ] Decrypting the current master AES key [DEBUG ] Attempting to authenticate with the Salt Master at 192.168.56.110 [DEBUG ] Loaded minion key: /etc/salt/pki/minion/minion.pem [DEBUG ] salt.crypt.verify_signature: Loading public key [DEBUG ] salt.crypt.verify_signature: Verifying signature [DEBUG ] Successfully verified signature of master public key with verification public key master_sign.pub [INFO ] Received signed and verified master pubkey from master 192.168.56.110 [DEBUG ] Decrypting the current master AES key
จะเห็นว่าสามารถ Authentication 192.168.56.109 และ 192.168.56.110 ได้
ตั้งค่า Fail-Over ใน saltminion
vi /etc/salt/minion
เพิ่ม config นี้ไว้บรรทัดสุดท้าย เพื่อตั้งให้เป็น mode Fail-Over
master_type: failover
ทำการทดสอบ Fail-Over โดยให้เปิด debug ที่เครื่อง saltminion ก่อน
salt-minion -l debug
ปิด service satl-master ที่เครื่อง saltmaster1
service salt-master stop
แล้วกลับมาดูผลลัพธ์ที่เครื่อง saltminion ที่ได้เปิด debug ทิ้งไว้
[DEBUG ] Attempting to authenticate with the Salt Master at 192.168.56.110 [DEBUG ] Loaded minion key: /etc/salt/pki/minion/minion.pem [DEBUG ] salt.crypt.verify_signature: Loading public key [DEBUG ] salt.crypt.verify_signature: Verifying signature [DEBUG ] Successfully verified signature of master public key with verification public key master_sign.pub [INFO ] Received signed and verified master pubkey from master 192.168.56.110 [DEBUG ] Decrypting the current master AES key
จะเห็นว่า Salt Minion จะสลับไป connect กับ saltmaster2 ก็เป็นอันจบครับสำหรับบทความนี้
ที่มา – http://docs.saltstack.com/en/latest/topics/tutorials/multimaster_pki.html