LoginSignup
3
6

More than 5 years have passed since last update.

NFSサーバの構築(CentOS7)

Posted at

やりたい事

  • AWS環境でNFSサーバーを構築する
  • nfsv3に対応できる形にしておく
  • NFSに利用するPortを固定したい
    • nfsv4を利用する場合は考慮が不要な点(TCP:2049のみ利用)

構成

  • AWS環境を利用
  • AMI:ami-8e8847f1
  • OS:CentOS Linux release 7.5.1804 (Core)
  • NFSパッケージ:nfs-utils-1.3.0-0.54.el7.x86_64
  • 参考値
    • ServerIP:10.0.0.84
    • ClientIP:10.0.0.176

参考

構築(Server側)

  • 共有用のディレクトリを作成する
    • この際、必要に応じてパーミッションを変更する
mkdir -p /export/data
  • /etc/exportsの編集
vi /etc/exports
# 以下を追加
/export/data 10.0.0.176(rw,no_root_squash)
# clientIPに対しアクセス許可を付与、読み取り・書込みを許可、rootでアクセス
  • サービス周り
# 有効化
systemctl enable nfs-server
# systemctl enable rpcbind
# 起動
systemctl start nfs-server
# systemctl enable rpcbind
# 確認
systemctl status nfs-server rpcbind
  • rpcinfo
# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  44717  status
    100024    1   tcp  40203  status
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  42773  nlockmgr
    100021    3   udp  42773  nlockmgr
    100021    4   udp  42773  nlockmgr
    100021    1   tcp  40671  nlockmgr
    100021    3   tcp  40671  nlockmgr
    100021    4   tcp  40671  nlockmgr
#

一度クライアント側からの接続を試る

  • この際、NFS ServerのSGはTCP:2049のみ空けています
mount -t nfs 10.0.0.84:/export/data /mnt/nfs
  • 見えてます。
# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/xvda1              8.0G  885M  7.2G  11% /
devtmpfs                222M     0  222M   0% /dev
tmpfs                   244M     0  244M   0% /dev/shm
tmpfs                   244M  8.5M  235M   4% /run
tmpfs                   244M     0  244M   0% /sys/fs/cgroup
tmpfs                    49M     0   49M   0% /run/user/1000
10.0.0.84:/export/data  8.0G  885M  7.2G  11% /mnt/nfs

nfsv3向けにServer側のPortを固定する

  • nfsv3で解放すべきサービスは以下なのでmountdで利用するportを固定する
    • portmapper(TCP:111)
    • mountd(不定)
vi /etc/sysconfig/nfs
# 以下を設定
RPCMOUNTDOPTS="-p 892"
  • サービス再起動
systemctl restart nfs-server
  • rpcinfo
# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  44717  status
    100024    1   tcp  40203  status
    100005    1   udp    892  mountd
    100005    1   tcp    892  mountd
    100005    2   udp    892  mountd
    100005    2   tcp    892  mountd
    100005    3   udp    892  mountd
    100005    3   tcp    892  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  50887  nlockmgr
    100021    3   udp  50887  nlockmgr
    100021    4   udp  50887  nlockmgr
    100021    1   tcp  37257  nlockmgr
    100021    3   tcp  37257  nlockmgr
    100021    4   tcp  37257  nlockmgr

SGの整理

  • NFS Server側のSGを以下のように設定
  • inboud
    • TCP:111
    • TCP:892
    • TCP:2049
  • outbound
    • default(any all)
3
6
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
3
6