2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rocky Linux上で Webサーバ とDBサーバを個別にたててそれぞれプライベートIPで相互に通信できるように構築する

Posted at

RockyLinuxでサーバ構築

パッケージのアップデート

dnf update

epel-releaseのインストール

dnf install epel-release

WebサーバのプライベートIPを設定する

nmcli connection

上記コマンドで現在の論理ネットーワーク設定を確認する

NAME                UUID                                  TYPE      DEVICE
System eth0         5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
Wired connection 1  a2a5252c-0bde-36be-8473-a3bea87f9b6f  ethernet  --

上記のような状態が表示される
次に,物理ネットワーク設定を確認する

nmcli device

上記コマンドを打つと

DEVICE  TYPE      STATE         CONNECTION
eth0    ethernet  connected     System eth0
eth1    ethernet  disconnected  --
lo      loopback  unmanaged     --

上記のような設定が表示される.

優先ネットワークのコネクション名をわかりやすいものに変更する

# 'Wired connection 1' => ethernet1 とする

nmcli connection modify 'Wired connection 1' connection.id ethernet1

上記コマンドを実行すると
論理ネットワーク[Wired connection 1]という論理ネットワークの名前[connection.id]が
[ethernet1]という名前に変更される

次のコマンドで変更を確認する

nmcli connection

とコマンドを実行すると

[root@vXXX-XXX-XXX-XXX ~]# nmcli connection
NAME         UUID                                  TYPE      DEVICE
ethernet1    a2a5252c-0bde-36be-8473-a3bea87f9b6f  ethernet  eth1
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0

上記のように当初 Wired connection 1となってた箇所が 変更後の ethernet1 となっている
どうやら自動的に論理ネットワーク設定[ethernet1] と物理ネットワーク設定[eth1]が紐付けられている

connectionとdeviceが自動でひもづけられない場合は以下のコマンドで直接命令する

nmcli connection modify eth1 connection.interface-name eth1

実際にeth1の論理ネットワークにプライベートIPを設定する

# 任意のIPアドレスにはかならずサイダー表記でサブネットを指定する
nmcli connection modify eth1  \
ipv4.method manual \
ipv4.address "192.168.1.1/24" \
connection.autoconnect "yes" \
ipv6.method ignore

では,実際にeth1という論理ネットワークが IP 192.168.1.1に正しく設定されているかどうかを
確認する

nmcli connection show eth1

# 以下を確認する

ipv4.method:                            manual
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.1.1/24
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --

上記をみると正しく設定されていそう

設定したeth1の192.168.1.1 にpingをとばす

ping -c 10 192.168.1.1

# とすると

64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.064 ms
64 bytes from 192.168.1.1: icmp_seq=7 ttl=64 time=0.070 ms
64 bytes from 192.168.1.1: icmp_seq=8 ttl=64 time=0.062 ms
64 bytes from 192.168.1.1: icmp_seq=9 ttl=64 time=0.067 ms
64 bytes from 192.168.1.1: icmp_seq=10 ttl=64 time=0.080 ms

--- 192.168.1.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9219ms
rtt min/avg/max/mdev = 0.061/0.071/0.094/0.013 ms

上記をみると問題なさそう
次に,eth1の論理ネットワークを停止してただしくpingが通らなくなることを確認する

nmcli connection down eth1

# 論理ネットワーク eth1が停止したメッセージを確認

Connection 'eth1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/24)


# 再度 pingを実行

ping -c 10 192.168.1.1

# 多分こうなる...
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

--- 192.168.1.1 ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9245ms

以上で,webサーバー側に追加されている物理ネットワークインターフェースに 192.168.1.1
というプライベートIPが設定された.

# eth1を停止させたままなのでもう一度起動させておく

nmcli connection up eth1

# 以下メッセージを確認して起動成功

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/25)

次にWebサーバからアクセスするDBサーバーのプライベートIPを設定する

nmcliコマンドで優先ネットワークが認識されていることを確認

nmcli connection

NAME                UUID                                  TYPE      DEVICE
System eth0         5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
Wired connection 1  844ebe49-adec-3080-863e-a3d1db223a74  ethernet  --

Wired connection 1 という優先接続を確認
'Wired connection 1' という論理ネットワーク名を 'eth1'という名前に変更する

nmcli connection modify 'Wired connection 1' connection.id 'eth1'

# 設定後変更を確認
nmcli connection

NAME         UUID                                  TYPE      DEVICE
eth1         844ebe49-adec-3080-863e-a3d1db223a74  ethernet  eth1
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0

connectionとdeviceが自動でひもづけられない場合は以下のコマンドで直接命令する

nmcli connection modify eth1 connection.interface-name eth1

では実際に,DBサーバーを担う側の端末にもプライベートIPを割り振る

# 先程のWEBサーバー側では 192.168.1.1 としたのでDB側は以下のようにする
# 任意のIPアドレスにはかならずサイダー表記でサブネットを指定する
nmcli connection modify eth1  \
ipv4.method manual \
ipv4.address "192.168.1.2/24" \
connection.autoconnect "yes" \
ipv6.method ignore

# 以下確認用コマンドを叩く
nmcli connection show eth1

# 以下のように IPが指定した通り設定されたことを確認する

ipv4.method:                            manual
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.1.2/24
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --

DBサーバから自ホストへpingを飛ばす

ping -c 10 192.168.1.2


# 以下のように自ホストにpingが飛べばOK
64 bytes from 192.168.1.2: icmp_seq=6 ttl=64 time=0.054 ms
64 bytes from 192.168.1.2: icmp_seq=7 ttl=64 time=0.091 ms
64 bytes from 192.168.1.2: icmp_seq=8 ttl=64 time=0.059 ms
64 bytes from 192.168.1.2: icmp_seq=9 ttl=64 time=0.059 ms
64 bytes from 192.168.1.2: icmp_seq=10 ttl=64 time=0.094 ms

--- 192.168.1.2 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9232ms
rtt min/avg/max/mdev = 0.054/0.069/0.094/0.016 ms

WEBサーバ <=> DBサーバ間でpingが応答するように設定する

まず対象のクラウドサービス上で
上記2端末間のIP192.168.1.1./24とか任意のIP間の通信ができるよう
セキリティグループを設定する

その後,各サーバー上で相手のサーバーにpingをとばす

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?