【Ansible】アクセス制限用のモジュールを作成する【シェルスクリプト】

Ansible の 標準モジュールに良さげなモジュールがなかったんで、んじゃいっそ作ってみようかと。

ディレクトリ構造

├── README.md
├── ansible.cfg
├── block.yml
├── group_vars
│   └── main.yml
├── hosts
├── library
│   └── block_ip.sh
└── roles
    └── block_ip
        ├── README.md
        ├── tasks
        │   └── main.yml
        └── vars
            └── main.yml

モジュール

root@DESKTOP-MOGIJIA:/opt/playbook/ip_block# cat library/block_ip.sh
#!/bin/sh
source `dirname $0`/args

if [ $state == "absent" ] ; then
        route del -host $target reject
        if [ $? -eq 0 ] ; then
                echo '{ "rc": 0, "changed": true }'
        else
                echo '{ "rc": 0 }'
        fi
elif [ $state == "present" ] ; then
        route add -host $target reject
        if [ $? -eq 0 ] ; then
                echo '{ "rc": 0, "changed": true }'
        else
                echo '{ "rc": 0 }'
        fi
else
        echo '{ "failed": true, "rc": 0 }'
fi

library ディレクトリ以下にモジュールを作成します。
それと、playbook の中で target (対象IPアドレス)、 state (状態)を定義できるようにしておきます。

Role

root@DESKTOP-MOGIJIA:/opt/playbook/ip_block# cat roles/block_ip/tasks/main.yml
---
# tasks file for block_ip
- name: block_ip
  block_ip:
    target: "{{ item }}"
    state: absent
  with_items:
    - "{{ block_target }}"

- name: accept_ip
  block_ip:
    target: "{{ item }}"
    state: absent
  with_items:
    - "{{ accept_target }}"

「state」が「present」⇒アクセスを制限
「state」が「absent」⇒アクセス制限を解除
としておきます。
root@DESKTOP-MOGIJIA:/opt/playbook/ip_block# cat group_vars/main.yml
---
   block_target:
     - 192.168.99.99
     - 192.168.99.98
     - 192.168.99.97
     - 192.168.99.96
     - 192.168.99.95
     - 192.168.99.94
     - 192.168.99.93
     - 192.168.99.00

   accept_target:
     - 127.0.0.1

playbook

root@DESKTOP-MOGIJIA:/opt/playbook/ip_block# cat block.yml
---
# Main Playbook
- name: apply master configuration to master nodes
  hosts: all
  vars_files:
   - ./group_vars/main.yml
  remote_user: vagrant
#  remote_user: centos
  become: yes
  roles:
    - block_ip

実行

root@DESKTOP-MOGIJIA:/opt/playbook/ip_block# ansible-playbook block.yml --ask-pass
SSH password:

PLAY [apply master configuration to master nodes] **********************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.33.10]

TASK [block_ip : block_ip] *********************************************************************************************
changed: [192.168.33.10] => (item=192.168.99.99)
changed: [192.168.33.10] => (item=192.168.99.98)
changed: [192.168.33.10] => (item=192.168.99.97)
changed: [192.168.33.10] => (item=192.168.99.96)
changed: [192.168.33.10] => (item=192.168.99.95)
changed: [192.168.33.10] => (item=192.168.99.94)
changed: [192.168.33.10] => (item=192.168.99.93)
changed: [192.168.33.10] => (item=192.168.99.00)

TASK [block_ip : accept_ip] ********************************************************************************************
ok: [192.168.33.10] => (item=127.0.0.1)

PLAY RECAP *************************************************************************************************************
192.168.33.10              : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

結果

[root@ansible-dev ~]# ip route show
default via 10.0.2.2 dev eth0 proto dhcp metric 100
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100
192.168.33.0/24 dev eth1 proto kernel scope link src 192.168.33.10 metric 101
unreachable 192.168.99.0 scope host
unreachable 192.168.99.93 scope host
unreachable 192.168.99.94 scope host
unreachable 192.168.99.95 scope host
unreachable 192.168.99.96 scope host
unreachable 192.168.99.97 scope host
unreachable 192.168.99.98 scope host
unreachable 192.168.99.99 scope host
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1

うん、大丈夫ですね。

【Ansible】AnsibleでAWSのネットワークを構築する【IaC】

Terraform に埋もれがちですが Ansible でも AWS のリソース構築が出来るんですよね。

作るもの

・VPC
・public subnet x 2
・private subnet x 2
・internet gateway
・route table

ディレクトリ構造

├── README.md
├── ansible.cfg
├── hosts
├── roles
│   └── aws_vpc
│       ├── tasks
│       │   └── main.yml
│       └── vars
│           └── main.yml
└── vpc_create.yml

インベントリファイル

root@DESKTOP-MOGIJIA:/opt/playbook/aws-vpc-2layer# cat hosts
[localhost]
127.0.0.1

サーバをプロビジョニングする訳ではないので、ローカルホストを指定

Role

root@DESKTOP-MOGIJIA:/opt/playbook/aws-vpc-2layer# cat roles/aws_vpc/tasks/main.yml
---
# tasks file for aws_vpc
- name: create_vpc
  ec2_vpc_net:
    name: "{{ vpc_name }}"
    cidr_block: "{{ vpc_cidr }}"
    region: "{{ region }}"
    dns_hostnames: yes
    dns_support: yes
  register: vpc_info

# PUBLIC_SUBNETの作成
- name: create_public_subnet
  ec2_vpc_subnet:
    vpc_id: "{{ vpc_info.vpc.id }}"
    cidr: "{{ item.pub_subnet_cidr }}"
    az: "{{ item.subnet_az }}"
    region: "{{ region }}"
    resource_tags: { "Name":"{{ item.pub_subnet_name }}" }
  register: pubsub_info
  with_items:
    - "{{ pub_subnet }}"

# PRIVATE_SUBNETの作成
- name: create_private_subnet
  ec2_vpc_subnet:
    vpc_id: "{{ vpc_info.vpc.id }}"
    cidr: "{{ item.pri_subnet_cidr }}"
    az: "{{ item.subnet_az }}"
    region: "{{ region }}"
    resource_tags: { "Name":"{{ item.pri_subnet_name }}" }
  register: prisub_info
  with_items:
    - "{{ pri_subnet }}"

# IGWの作成
- name: create_igw
  ec2_vpc_igw:
    vpc_id: "{{ vpc_info.vpc.id }}"
    region: "{{ region }}"
    tags: { "Name":"{{ igw_name }}" }
  register: igw_info

# ROUTETABLEの作成(IGW)
- name: create_route_table
  ec2_vpc_route_table:
    vpc_id: "{{ vpc_info.vpc.id }}"
    subnets: "{{ atache_igw_subnet }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ igw_info.gateway_id }}"
    region: "{{ region }}"
    resource_tags: { "Name":"{{ rttable_pub_name }}" }

root@DESKTOP-MOGIJIA:/opt/playbook/aws-vpc-2layer# cat roles/aws_vpc/vars/main.yml
---
# vars file for aws_vpc

# REGION
  region: "ap-northeast-1"

# VPC
  vpc_name: "sanuki-wd-vpc"
  vpc_cidr: "10.0.0.0/16"

# IGW
  igw_name: "sanuki-igw"

# ROUTETABLE(PUBLIC)
  rttable_pub_name: "sanuki-pub-rt"

# PUBLIC_SUBNET
  pub_subnet:
    - { pub_subnet_cidr: "10.0.10.0/24" ,subnet_az: "ap-northeast-1a" ,pub_subnet_name: "sanuki-wd-public-subnet-a" }
    - { pub_subnet_cidr: "10.0.20.0/24" ,subnet_az: "ap-northeast-1c" ,pub_subnet_name: "sanuki-wd-public-subnet-c" }

# PRIVATE_SUBNET
  pri_subnet:
    - { pri_subnet_cidr: "10.0.50.0/24" ,subnet_az: "ap-northeast-1a" ,pri_subnet_name: "sanuki-wd-private-subnet-a" }
    - { pri_subnet_cidr: "10.0.60.0/24" ,subnet_az: "ap-northeast-1c" ,pri_subnet_name: "sanuki-wd-private-subnet-c" }

# IGWに紐付けるサブネット
  atache_igw_subnet:
    - "10.0.10.0/24"
    - "10.0.20.0/24"

playbook

root@DESKTOP-MOGIJIA:/opt/playbook/aws-vpc-2layer# cat vpc_create.yml
---
# VPC CREATE Playbook
- name: create vpc subnet igw routetable
  hosts: localhost
  connection: local
  gather_facts: False
  become: False
  roles:
    - aws_vpc

実行

root@DESKTOP-MOGIJIA:/opt/playbook/aws-vpc-2layer# ansible-playbook -i hosts vpc_create.yml

PLAY [create vpc subnet igw routetable] ********************************************************************************

TASK [aws_vpc : create_vpc] ********************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 127.0.0.1 should use /usr/bin/python3, but is using
/usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using
the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature
 will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
changed: [127.0.0.1]

TASK [aws_vpc : create_public_subnet] **********************************************************************************
changed: [127.0.0.1] => (item={u'pub_subnet_name': u'sanuki-wd-public-subnet-a', u'subnet_az': u'ap-northeast-1a', u'pub_subnet_cidr': u'10.0.10.0/24'})
changed: [127.0.0.1] => (item={u'pub_subnet_name': u'sanuki-wd-public-subnet-c', u'subnet_az': u'ap-northeast-1c', u'pub_subnet_cidr': u'10.0.20.0/24'})

TASK [aws_vpc : create_private_subnet] *********************************************************************************
changed: [127.0.0.1] => (item={u'pri_subnet_cidr': u'10.0.50.0/24', u'pri_subnet_name': u'sanuki-wd-private-subnet-a', u'subnet_az': u'ap-northeast-1a'})
changed: [127.0.0.1] => (item={u'pri_subnet_cidr': u'10.0.60.0/24', u'pri_subnet_name': u'sanuki-wd-private-subnet-c', u'subnet_az': u'ap-northeast-1c'})

TASK [aws_vpc : create_igw] ********************************************************************************************
changed: [127.0.0.1]

TASK [aws_vpc : create_route_table] ************************************************************************************
changed: [127.0.0.1]

PLAY RECAP *************************************************************************************************************
127.0.0.1                  : ok=5    changed=5    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

補足

boto3 が必要になります。
pip でインストールしておいて下さい。

pip install boto boto3

稼働中の MySQLサーバ から slaveサーバ を構築する備忘録

こんにちは。
MySQLサーバ の slaveサーバを構築する機会があったので備忘録を残しておきます。

確認事項

バイナリログが出力されていて、尚且つ server-id が設定されている必要があります。

vi /etc/my.cnf
=======================================
server-id=1001
log-bin = /var/lib/mysql/mysql-bin
=======================================

systemctl restart mysqld

レプリケーション用ユーザの作成

レプリケーション用のユーザを事前に作成しておきます。

create user 'repl'@'%' identified by 'xxxxxxxxxx';
grant replication slave on *.* to 'repl'@'%';

dumpファイルの取得

mysqldump で dumpデータを取得します。
ストレージエンジンが innodb であれば、–single-transaction オプションで DBをロックせずに取得が可能です。
また、–master-data=2 オプションでバイナリログの読み出し開始位置を出力しておきます。

mysqldump -u root -p --skip-lock-tables --quote-names --single-transaction --master-data=2 -A > /var/tmp/mysqldump.sql

dumpファイルのインポート

slaveサーバ に dumpファイルを転送して流し込みます。
単純に mysql コマンドとリダイレクトを組み合わせるだけで大丈夫です。

scp user@xxx.xxx.xxx.xxx:/var/tmp/mysqldump.sql /var/tmp/.
mysql -u root -p < /var/tmp/mysqldump.sql

テーブルチェック

mysql_upgrade コマンドを使ってテーブルのチェックを行います。

mysql_upgrade -u root -p
systemctl restart mysqld

バイナリログの開始位置を確認

–master-data=2 オプションでバイナリログの読み出し開始位置が出力されているので確認します。

grep "CHANGE MASTER" /var/tmp/mysqldump.sql

レプリケーション設定

mysql> change master to
    -> master_host='xxx.xxx.xxx.xxx',
    -> master_user='repl',
    -> master_password='xxxxxxxxxx',
    -> master_log_file='[バイナリログ]',
    -> master_log_pos=[ポジション];

mysql> start slave;
mysql> show slave status\G

【データ移行】/var を別の追加ディスクに移行【Tips】

こんにちは。
/var のディレクトリを別の追加ディスクに移行する手順を残しておきます。

[root@test-server /]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   30G  0 disk
mqvda1 253:1    0 29.3G  0 part /
vdb    253:16   0  100G  0 disk

/dev/vdb の領域に /var を移行してみます。

手順

・ファイルシステムの作成
/dev/vdb にパーティションを切ってからファイルシステムを作成します。

[root@test-server /]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf4f00fe7.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209584127, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209584127, default 209584127): +100G
Value out of range.
Last sector, +sectors or +size{K,M,G} (2048-209584127, default 209584127): ^[[A^[[D^[[B^[[B^C
[root@sr-stg-ftp01 /]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x71de9846.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209584127, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209584127, default 209584127):
Using default value 209584127
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): p

Disk /dev/vdb: 107.3 GB, 107307073536 bytes, 209584128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x71de9846

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209584127   104791040   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

mkfs -t xfs /dev/vdb1

・シングルユーザモードへ
init 1

・追加ディスクをアタッチして/var を同期する
cd /
mkdir /new_var
mount -t xfs /dev/vdb1 /new_var
rsync -avzr /var/ /new_var/

・元の /var を別名保存し、/var へ vdb をマウント
umount /new_var
mv var var_old
mkdir var
mount -t xfs /dev/vdb1 /var

・fstab に追記
vi /etc/fstab
=================================
/dev/vdb1 /var xfs defaults 0 2

・マルチユーザモードへ
init 3

【Ansible】いい感じにデータを変数にいれる【シェルスクリプト】

スペース区切りだったり、カンマ区切りのデータをいい感じに Ansible の変数に入れたいことってありますよね。
そんな時によく使うスクリプトです。

シェルスクリプト

vi var_create.sh
===============================================
#!/bin/bash

while IFS=' ' read key val
do
  echo "     - { domain: '$val' ,owner: '$key' }"
done < $1

vi data.txt
============================
user1 aaa
user2 bbb
user3 ccc

実行

[root@keisuke-main tmp]# ./var_create.sh data.txt
     - { domain: 'aaa' ,owner: 'user1' }
     - { domain: 'bbb' ,owner: 'user2' }
     - { domain: 'ccc' ,owner: 'user3' }

【ruby】rails環境構築【rbenv】

サーバにrailsを導入する必要があったのです。
ただそれだけ。

パッケージのインストール

cd /usr/local
yum install -y git gcc gcc-c++ openssl-devel readline-devel
git clone git://github.com/sstephenson/rbenv.git rbenv
git clone git://github.com/sstephenson/ruby-build.git rbenv/plugins/ruby-build

環境変数の設定

vi /etc/profile.d/rbenv.sh
========================================
export RBENV_ROOT="/usr/local/rbenv"
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init --no-rehash -)"
========================================
source /etc/profile.d/rbenv.sh

rubyの導入

rbenv install --list

⇒必要なバージョンを確認
rbenv install 2.6.3
rbenv global 2.6.3
rbenv rehash

*取り敢えずruby 2.6.3を導入

railsとpassengerのインストール

gem update --system
gem install rails -v 6.0.0.rc2
gem install passenger
rbenv rehash

必要パッケージのインストール

yum install httpd libcurl-devel httpd-devel apr-devel apr-util-devel 
passenger-install-apache2-module

設定ファイル作成

vi /etc/httpd/conf.d/passenger.conf
=========================================================================================================================================
   LoadModule passenger_module /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2
     PassengerDefaultRuby /usr/local/rbenv/versions/2.6.3/bin/ruby
   </IfModule>
=========================================================================================================================================

【Ansible】Ansible と expect で MySQL 導入を自動化する【IaC】

こんにちは。
MySQL の導入が面倒だったので Ansible と expect で自動化にチャレンジします。

mysql_secure_installation の自動化

expect と awk でシェルスクリプトを作成します。

#!/bin/bash


# 初期パスワードを取得
IntPasswd=$(grep "A temporary password is generated for root@localhost:" /var/log/mysqld.log | awk '{ print $13}')

# パスワード指定
MysqlRootPasswd="{{ db_passwd }}"

expect -c '
    set timeout 10;
    spawn mysql_secure_installation;
    expect "Enter password for user root:";
    send -- "'"${IntPasswd}"'\n";
    expect "New password:";
    send -- "'"${MysqlRootPasswd}"'\n";
    expect "Re-enter new password:";
    send -- "'"${MysqlRootPasswd}"'\n";
    expect "Change the password for root ?";
    send "n\n";
    expect "Remove anonymous users?";
    send "y\n";
    expect "Disallow root login remotely?";
    send "y\n";
    expect "Remove test database and access to it?";
    send "y\n";
    expect "Reload privilege tables now?";
    send "y\n";
    interact;'

awk で初期パスワードを取得し、対話処理は expect で処理します。

Playbook

Ansible の playbook で処理します。

---
# tasks file for mysql-server80
- name: install mysql80 repository
  yum:
    name: https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    state: present

- name: install mysql
  yum:
    name:
      - mysql-server
      - expect
    state: present

- name: put my.cnf
  template:
    src: ../templates/my.cnf.j2
    dest: /etc/my.cnf
    owner: root
    group: root
    mode: 0644
    backup: yes

- name: mkdir /var/log/mysql/
  file:
    path: /var/log/mysql
    state: directory
    owner: mysql
    group: mysql
    mode: 0755

- name: start mysql
  systemd:
    name: mysqld
    state: started
    enabled: yes

- name: confirm check_file
  stat: path=/usr/local/etc/mysql_stat.txt
  register: result_mysql_exit

- name: put mysql_secure_installation_script
  template:
    src: ../templates/mysql_secure_installation_script
    dest: /tmp/mysql_secure_installation_script
    owner: root
    group: root
    mode: 0755

- name: exec mysql_secure_installation_script
  shell: "/tmp/mysql_secure_installation_script"
  when: not result_mysql_exit.stat.exists

- name: create check_file
  file:
    path: /usr/local/etc/mysql_stat.txt
    state: touch
    mode: "u=rw,g=r,o=r"

- name: change error-log location
  lineinfile:
    dest: /etc/my.cnf
    state: present
    backrefs: yes
    regexp: '^log-error = /var/log/mysqld.log'
    line: 'log-error = /var/log/mysql/mysqld.log'
  notify: mysqld_restart

おまけ

こちらに CentOS7用の playbook を纏めていますので宜しければ。
https://github.com/keisukesanuki/default-CentOS7

【監視設定】Zabbix Proxy の設定【踏み台経由】

設定ですごく嵌ったんですね。
踏み台サーバ経由で監視設定をいれる方法です。

zabbix-proxy 導入

各種パッケージのインストール

※ CentOS6

rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.rpm

yum install zabbix-proxy zabbix-proxy-sqlite3 zabbix-agent

※ CentOS7
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

yum install zabbix-proxy zabbix-proxy-sqlite3 zabbix-agent

sqlite 設定

mkdir /var/lib/sqlite3
chown -R zabbix:zabbix /var/lib/sqlite3
cd /var/lib/sqlite3
zcat /usr/share/doc/zabbix-proxy-sqlite3-3.4.15/schema.sql.gz | sqlite3 zabbix.db
chown zabbix:zabbix zabbix.db

zabbix-proxy 設定

sed -i -e "s/^Server=.*\$/Server=xxx.xxx.xxx.xxx/g" /etc/zabbix/zabbix_proxy.conf
sed -i -e "s/^Hostname=.*\$/Hostname=${HOSTNAME}/g" /etc/zabbix/zabbix_proxy.conf
sed -i -e "s/^DBName=.*\$/DBName=\/var\/lib\/sqlite3\/zabbix.db/g" /etc/zabbix/zabbix_proxy.conf

※ xxx.xxx.xxx.xxx は Zabbix サーバの IP

zabbix-agent 設定

sed -i -e "s/^Hostname=.*\$/Hostname=${HOSTNAME}/g" /etc/zabbix/zabbix_agentd.conf

zabbix-proxy 起動

/etc/init.d/zabbix-proxy start
chkconfig zabbix-proxy on
/etc/init.d/zabbix-agent start
chkconfig zabbix-agent on

zabbix-agent 導入

各種パッケージのインストール

※ CentOS6

rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.rpm

yum install zabbix-agent

※ CentOS7
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

yum install zabbix-agent

zabbix-agent 設定

sed -i -e "s/^ServerActive/ServerActive=xxx.xxx.xxx.xxx/g" /etc/zabbix/zabbix_agentd.conf
sed -i -e "s/^Hostname=.*\$/Hostname=${HOSTNAME}/g" /etc/zabbix/zabbix_agentd.conf
sed -i -e "s/^Server=.*\$/Server=xxx.xxx.xxx.xxx/g" /etc/zabbix/zabbix_agentd.conf

※ xxx.xxx.xxx.xxx は踏み台( proxy )サーバの IP

zabbix-agent 起動

/etc/init.d/zabbix-agent start
chkconfig zabbix-agent on

【サーバ移設】踏み台サーバを経由してrsyncする方法【rsync】

こんにちは。
先日にサーバ移設案件に携わる機会があって、踏み台サーバを経由して、目的のサーバにデータを同期する必要がありました。
その際に先輩に教えてもらった方法をメモレベルで残しておこうと思います。

rsync 用ユーザ作成

useradd rsync
su rsync
cd ~
mkdir .ssh
chmod 700 .ssh

SSH 設定

vi /home/rsync/.ssh/config
===============================================
Host step-new
    HostName      111.111.111.111
    User          step-new-user
    IdentityFile  ~/.ssh/id_rsa_step-new.pem
Host step-old
    ProxyCommand  ssh -W %h:%p step-new
    HostName      222.222.222.222
    User          step-old-user
    IdentityFile  ~/.ssh/id_rsa_step-old.pem
Host target-server
    ProxyCommand  ssh -W %h:%p step-old
    HostName      333.333.333.333
    User          target-server-user
    IdentityFile  ~/.ssh/id_rsa_target.pem
===============================================

vi ~/.ssh/id_rsa_step-new.pem
vi ~/.ssh/id_rsa_step-old.pem
vi ~/.ssh/id_rsa_target.pem

chmod 600 ~/.ssh/id_rsa_step-new.pem
chmod 600 ~/.ssh/id_rsa_step-old.pem
chmod 600 ~/.ssh/id_rsa_target.pem

データ同期

mkdir -p /var/tmp/rsync_results/test1
nohup time rsync -avzrn --rsync-path="sudo rsync" target-server:/home/target-server-user/ /home/purpose/ 1>/var/tmp/rsync_results/test1/result_$(date +"%Y%m%d").log 2>/var/tmp/rsync_results/test1/error_$(date +"%Y%m%d").log &
nohup time rsync -avzr --rsync-path="sudo rsync" target-server:/home/target-server-user/ /home/purpose/ 1>/var/tmp/rsync_results/test1/result_$(date +"%Y%m%d").log 2>/var/tmp/rsync_results/test1/error_$(date +"%Y%m%d").log &

補足

・.ssh/ 以下に config ファイルを作成することで、踏み台サーバを経由して接続が出来る。
・秘密鍵は事前に配置しておく必要がある。

【ファイル共有】nfsサーバの構築手順【構築手順】

こんにちは。
移設案件でnfsサーバを構築したので、
備忘録として手順を残しておきます。

サーバ

nfs用のディレクトリの準備

mkfs -t xfs /dev/xvdf
mkdir /mnt/nfsserv/
chmod 777 /mnt/nfsserv/
mount -t xfs -o nouuid /dev/xvdf /mnt/nfsserv/

fstabの編集

vi /etc/fstab
===================================================================
/dev/xvdf /mnt/nfsserv             xfs     defaults        0 0
===================================================================

nfsパッケージの導入

yum install nfs-utils
systemctl start rpcbind
systemctl start nfs-server
systemctl enable rpcbind
systemctl enable nfs-server

nfs設定ファイルの編集

vi /etc/exports
=================================================================
/mnt/nfsserv/   10.204.68.0/255.255.255.0(rw,sync,no_root_squash)
=================================================================

systemctl restart rpcbind
systemctl restart nfs-server

クライアント

nfsパッケージの導入

yum install nfs-utils
systemctl start rpcbind
systemctl enable rpcbind

マウント

mkdir /data
mount -t nfs 10.204.68.32:/mnt/nfsserv /data

fstabの編集

vi /etc/fstab
======================================================================
10.204.68.32:/mnt/nfsserv /data    nfs     defaults,_netdev        0 0
======================================================================