-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
set -eu # 未定義変数のチェック、コマンドエラー時は処理中断 | ||
|
||
: ${CLUSTER_HOSTS:=ke2dev-swarm1 ke2dev-swarm2 ke2dev-swarm3} | ||
: ${HOST_NAME:=$(hostname)} | ||
|
||
# | ||
# root ユーザに切り替える | ||
# | ||
if [[ ${USER} != "root" ]]; then | ||
echo "root ユーザではありません。sudo 権限で root ユーザに変更します" | ||
sudo -E su -m -c ${0} | ||
exit $? | ||
fi | ||
: ${LOGIN_USER:=${SUDO_USER}} | ||
|
||
SSH_KEYFILE_NAME=id_rsa_pgpool | ||
# | ||
# 自ホストの postgres ユーザーの SSH 公開鍵ファイルをクラスタの他のホストの authorized_keys に追加する | ||
# | ||
for host in ${CLUSTER_HOSTS}; do | ||
if [[ ${HOST_NAME} == ${host} ]]; then | ||
continue | ||
fi | ||
KEY_DATA=$(cat /var/lib/pgsql/.ssh/${SSH_KEYFILE_NAME}.pub) | ||
ssh -t ${LOGIN_USER}@${host} sudo -i -u postgres sh -c "'grep -qs ${HOST_NAME} ~/.ssh/authorized_keys || (mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo ${KEY_DATA} >> ~/.ssh/authorized_keys && restorecon -Rv ~/.ssh)'" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters