機能追加 #611

山本 義治約9年前に更新

h2. db3

h3. db_syncユーザー作成

[root@db3 admin]# /usr/sbin/adduser db_sync
[root@db3 admin]# passwd db_sync
<pre>
Changing password for user db_sync.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
</pre>
[root@db3 admin]# su - db_sync
[db_sync@db3 ~]$ ssh-keygen - t rsa
<pre>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/db_sync/.ssh/id_rsa):
Created directory '/home/db_sync/.ssh'.
Enter passphrase (empty for no passphrase): Enter
Enter same passphrase again: Enter
Your identification has been saved in /home/db_sync/.ssh/id_rsa.
Your public key has been saved in /home/db_sync/.ssh/id_rsa.pub.
The key fingerprint is:
</pre>
[db_sync@db3 ~]$ scp ~/.ssh/id_rsa.pub admin@192.168.2.104:/home/admin/
<pre>
The authenticity of host '192.168.2.104 (192.168.2.104)' can't be established.
RSA key fingerprint is a2:5e:f0:74:56:72:99:7e:8d:2b:1a:8b:eb:4a:5e:21.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.104' (RSA) to the list of known hosts.
admin@192.168.2.104's password:
id_rsa.pub

</pre>

h2. db2

h3. db_syncユーザー作成

[root@db2 admin]# /usr/sbin/adduser db_sync
[root@db2 admin]# passwd db_sync
<pre>
Changing password for user db_sync.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
</pre>
[root@db2 admin]# su - db_sync
[db_sync@db2 ~]$ mkdir .ssh
[db_sync@db2 ~]$ ll -la
total 28
drwx------ 3 db_sync db_sync 4096 Dec 16 07:17 .
drwxr-xr-x 4 root root 4096 Dec 16 07:15 ..
-rw-r--r-- 1 db_sync db_sync 33 Dec 16 07:15 .bash_logout
-rw-r--r-- 1 db_sync db_sync 176 Dec 16 07:15 .bash_profile
-rw-r--r-- 1 db_sync db_sync 124 Dec 16 07:15 .bashrc
rwxrwxr-x 2 db_sync db_sync 4096 Dec 16 07:17 .ssh
[db_sync@db2 ~]$ exit
logout

[root@db2 admin]# cat /home/admin/id_rsa.pub >> /home/db_sync/.ssh/authorized_keys
[root@db2 admin]# chmod 600 /home/db_sync/.ssh/authorized_keys
[root@db2 admin]# vi /etc/ssh/sshd_config
<pre>
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
</pre>
[root@db2 admin]# /etc/init.d/sshd restart
<pre>
sshd を停止中: [ OK ]
sshd を起動中: [ OK ]
</pre>
[root@db2 admin]# chown db_sync:db_sync /home/db_sync/.ssh/authorized_keys

h3. パス無しでログインできることを確認

[db_sync@db3 ~]$ ssh db_sync@192.168.2.104
<pre>
Last login: Wed Dec 16 07:21:00 2015 from 192.168.2.105
</pre>

h3. バックアップスクリプト設置

[root@db3 admin]# vi /home/db_sync/bkup.sh
<pre>
#!/bin/sh

rm -f /home/db_sync/bkup/aff.dump.`date --date '30 days ago' "+%Y%m%d"`.gz

eval `ssh-agent -s`
ssh-add /home/db_sync/.ssh/id_rsa
rsync -avz -e ssh db_sync@192.168.2.104:/usr/local/mysql/aff/bkup /home/db_sync/
eval `ssh-agent -s -k`
</pre>

[root@db3 admin]# chmod u+x /home/db_sync/bkup.sh
[root@db3 admin]# crontab -e
<pre>
#DB_BACKUP
30 6 * * * /home/db_sync/bkup.sh > /dev/null 2>&1
</pre>

戻る