MENU

溶けかけてるうさぎ HP GALLERY BLOG TOP RECENT ARTICLES POPULAR ARTICLES ABOUT THIS BLOG

CATEGORY

大学 (140) 仕事 (17) 航空宇宙 (104) 写真 (77) 旅行 (32) 飯・酒 (17) コンピュータ (118) その他 (44)

TAG

ARCHIVE

RECENT

【カメラ】X100 シリーズが好きすぎる(主にリーフシャッタ) 【カメラ】X100V から X100VI に買い替えました 【自宅サーバー】Google Domains から Cloudflare にドメインを移管 【カメラ】FUJIFILM XF レンズのサイズ比較ができるようにしてみた 【写真】自作写真閲覧ページにてフィルムシミュレーションで写真をフィルタできるようにした

【自宅サーバー】新サーバーの構築(ソフトウェア編)

事象発生日:2020-04-11

記事公開日:2020-04-12

アクセス数:4142

新しい自宅サーバーに,OSやソフトウェアをインストールしていく.

もうちょっと待てばUbuntu Server 20.04 LTSがでるのがもどかしいが,リリース直後は互換性云々があるので,まあ18.04 LTSでいいか.

1.Ubuntu Server 18.04.4 LTS のインストール

」で組んだ自作サーバーにOSをインストールしていく.

基本的には「」から続く一連の過去ログと同様である.

 

Ubuntu Server 18.04.4 LTSのイメージファイルをダウンロード
Rufusを使って,インストールメディアを作成
Ubuntu Serverのインストール(OpenSSHも同時にインストール)
DHCP設定とIPの固定
SSHの設定(「」)
Ubuntu諸々初期設定(「」)
システムアップデート

2.いくつかのサービスなどの設定

chrony

時刻設定.ついでにタイムゾーンも変更した.

$ sudo apt install chrony

$ sudo nano /etc/chrony/chrony.conf
# プロバイダがBIGLOBEなので,NTPサーバーを以下のように設定
#  変更前) 17行目, Ubuntu 18.04
#   pool ntp.ubuntu.com        iburst maxsources 4
#   pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#   pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#   pool 2.ubuntu.pool.ntp.org iburst maxsources 2
#
#  変更例) ※ BIGLOBE以外のプロバイダ契約の人はコピペしないように!!
#   server ntp01.tk.mesh.ad.jp iburst minpoll 10 maxpoll 12
#   server ntp02.tk.mesh.ad.jp iburst minpoll 10 maxpoll 12
#   server ntp03.tk.mesh.ad.jp iburst minpoll 10 maxpoll 12

$ sudo service chrony restart

$ sudo timedatectl set-timezone Asia/Tokyo

$ sudo timedatectl status

$ date

追加のHDDのマウント

システムドライブとして2TBのHDDがあり,その他に6TBのHDDを2台マウントさせる.

過去記事「」とほぼ同じ手順でOK.

 

最初は2TBのHDDのみ認識されている.

$ sudo fdisk -l
Disk /dev/loop0: 89.1 MiB, 93417472 bytes, 182456 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 /dev/loop1: 93.8 MiB, 98336768 bytes, 192064 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 /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 333AC4AF-FDFA-4D9E-9EE5-F5157BDDD5E5

Device       Start        End    Sectors  Size Type
/dev/sda1     2048    1050623    1048576  512M EFI System
/dev/sda2  1050624 3907026943 3905976320  1.8T Linux filesystem

$ sudo parted -l
Model: ATA WDC WD20EZRZ-00Z (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  538MB   537MB   fat32              boot, esp
 2      538MB   2000GB  2000GB  ext4

2台目を追加.

sdbとして認識されている.

$ sudo fdisk -l
Disk /dev/loop0: 89.1 MiB, 93417472 bytes, 182456 sectors
# -- 中略 --

Disk /dev/sdb: 5.5 TiB, 6001175126016 bytes, 11721045168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
[ryo@ubuntu18 ~ Sun Apr 12 13:57:11]

Model: ATA WDC WD20EZRZ-00Z (scsi)
# -- 中略 --

Error: /dev/sdb: unrecognised disk label
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: unknown
Disk Flags:

partedで初期化とパーティションを作成する.

$ sudo parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/sdb: unrecognised disk label
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) p
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary
File system type?  [ext2]? ext4
Start? 0%
End? 100%
(parted) q
Information: You may need to update /etc/fstab.

# システム予約領域を1%としてフォーマット
$ sudo mkfs.ext4 -m 1 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 1465130240 4k blocks and 183144448 inodes
Filesystem UUID: b0db47b4-e263-4471-9253-b26ee0b1b353
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

$ sudo fdisk -l
# -- 中略 --
Disk /dev/sdb: 5.5 TiB, 6001175126016 bytes, 11721045168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: BF6B2DD3-32DB-471D-8426-CB6798B4C611

Device     Start         End     Sectors  Size Type
/dev/sdb1   2048 11721043967 11721041920  5.5T Linux filesystem

$ sudo parted -l
# -- 中略 --
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  6001GB  6001GB  ext4         primary

$ sudo tune2fs -l /dev/sdb1
tune2fs 1.44.1 (24-Mar-2018)
Filesystem volume name:   
Last mounted on:          
Filesystem UUID:          b0db47b4-e263-4471-9253-b26ee0b1b353
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              183144448
Block count:              1465130240
Reserved block count:     14651302
Free blocks:              1453294207
Free inodes:              183144437
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         4096
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Sun Apr 12 14:19:38 2020
Last mount time:          n/a
Last write time:          Sun Apr 12 14:19:44 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Sun Apr 12 14:19:38 2020
Check interval:           0 ()
Lifetime writes:          1039 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      e3503014-63d7-47cd-b7a8-97aed911c6d3
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x46aa359d

最後にマウントポイントを作成し,fstabに登録し,マウントを恒久化.

$ cd /mnt/

$ sudo mkdir disk1

$ sudo mount -t ext4 /dev/sdb1 /mnt/disk1

$ sudo blkid /dev/sdb1
/dev/sdb1: UUID="b0db47b4-e263-4471-9253-b26ee0b1b353" TYPE="ext4" PARTLABEL="primary" PARTUUID="b2574de8-f9e7-47d2-a44a-9177eb1c8a6b"

$ sudo nano /etc/fstab
# 以下2行を追記
# 2nd disk for samba
UUID=b0db47b4-e263-4471-9253-b26ee0b1b353 /mnt/disk1/     ext4 defaults,nofail 0 0

再起動して,マウントが維持されていればOK.

 

もう1台も同様に設定する.

設定後.

$ sudo fdisk -l
# -- 中略 --
Disk /dev/sdc: 5.5 TiB, 6001175126016 bytes, 11721045168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 5ECBFC65-1E09-4679-9192-18EA47027942

Device     Start         End     Sectors  Size Type
/dev/sdc1   2048 11721043967 11721041920  5.5T Linux filesystem

$ sudo parted -l
# -- 中略 --
Model: ATA ST6000DM003-2CY1 (scsi)
Disk /dev/sdc: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  6001GB  6001GB  ext4         primary

$ sudo tune2fs -l /dev/sdc1
tune2fs 1.44.1 (24-Mar-2018)
Filesystem volume name:   
Last mounted on:          
Filesystem UUID:          bdc23deb-108e-4641-9262-6ef1efb21453
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              183144448
Block count:              1465130240
Reserved block count:     14651302
Free blocks:              1453294207
Free inodes:              183144437
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         4096
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Sun Apr 12 14:46:22 2020
Last mount time:          n/a
Last write time:          Sun Apr 12 14:46:25 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Sun Apr 12 14:46:22 2020
Check interval:           0 ()
Lifetime writes:          1039 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      978f96b4-3361-40d8-8369-7c09ee296cb6
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x9e4e78fd

samba

NASにするので必要.

$ sudo apt install samba

# システムディスクのうちネットワークからアクセスできるフォルダを作成
$ sudo mkdir /home/share
$ sudo chmod 777 /home/share
$ sudo chown nobody:nogroup /home/share

# 設定
$ cd /etc/samba/
$ sudo cp smb.conf smb.conf_orig
$ sudo nano smb.conf

# [global] に以下を追加
  unix charset = UTF-8
  dos charset = CP932
  load printers = no
  disable spoolss = yes
  hosts allow = 127. 192.168.

# [homes] に以下を追加
   comment = Home Directories
   browseable = no
   writable = yes

# [printers], [print$] の項目は全てコメントアウト

# 末尾に追加
[share]
  comment = Shared folder
  path = /home/share
  guest ok = no
  guest only = no
  writable = yes
  create mode = 0777
  directory mode = 0777

[share2]
  comment = Shared folder
  path = /mnt/disk1/share2
  guest ok = no
  guest only = no
  writable = yes
  create mode = 0777
  directory mode = 0777

[share3]
  comment = Shared folder
  path = /mnt/disk2/share3
  guest ok = no
  guest only = no
  writable = yes
  create mode = 0777
  directory mode = 0777

# 設定確認
$ sudo testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[share]"
Processing section "[share2]"
Processing section "[share3]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        disable spoolss = Yes
        dns proxy = No
        dos charset = CP932
        load printers = No
        log file = /var/log/samba/log.%m
        map to guest = Bad User
        max log size = 1000
        obey pam restrictions = Yes
        pam password change = Yes
        panic action = /usr/share/samba/panic-action %d
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        passwd program = /usr/bin/passwd %u
        server role = standalone server
        server string = %h server (Samba, Ubuntu)
        syslog = 0
        unix password sync = Yes
        usershare allow guests = Yes
        idmap config * : backend = tdb
        browseable = No
        comment = Home Directories
        hosts allow = 127. 192.168.


[share]
        comment = Shared folder
        create mask = 0777
        directory mask = 0777
        path = /home/share


[share2]
        comment = Shared folder
        create mask = 0777
        directory mask = 0777
        path = /mnt/disk1/share2


[share3]
        comment = Shared folder
        create mask = 0777
        directory mask = 0777
        path = /mnt/disk2/share3

# 再起動
$ sudo service smbd restart
$ sudo service nmbd restart

共有フォルダにアクセスできるユーザー,グループを作っていく.

${user1}が全フォルダ,${user2}が[share3]のみにアクセスできるようにしておく.

# ユーザー作成
$ sudo adduser ${user1}
$ sudo adduser ${user2}

# グループ作成
$ sudo groupadd samba_full
$ sudo groupadd samba_limited

# グループ追加
$ sudo gpasswd -a ${user1} samba_full
$ sudo gpasswd -a ${user1} samba_limited
$ sudo gpasswd -a ${user2} samba_limited

# 確認
$ sudo cat /etc/group

$ sudo nano smb.conf
# 各セクション([share]など)にアクセス可能なグループを以下のように追加
valid users = @samba_full

# sambaにユーザー登録
$ sudo pdbedit -a ${user1}
$ sudo pdbedit -a ${user2}

# 再起動
$ sudo service smbd restart
$ sudo service nmbd restart

なお,デフォルトではWindowsからファイルを書き込む場合,ファイルのオーナーが書き込んだユーザー/グループになってしまう.

すると,samba_limitedの他のユーザーが編集できなくなってしまったので,

  force group = samba_limited

を追加した.

 

なお,create modecreate directoryも,これは上限を決めているだけなので,特定の値に強制したい場合はforceをつければいいらしい.

3.おわりに

これで,最低限の設定が終わり,NASとしてファイル共有も可能になった.

今後,アプリケーションサーバーとして,適当に使っていく.

4.出典・参考

@IT. 【 parted 】コマンド――GPT対応のパーティションを作成、削除する. Retrieved April 11, 2020, from https://www.atmarkit.co.jp/ait/articles/1803/08/news017.html
K-Lab. Ubuntu 14.04 に parted を利用して 8TBのHDDを増設したときのメモ. Retrieved April 11, 2020, from http://www.nemotos.net/?p=1394
virtualiment. sambaサーバによるファイル共有環境の構築手順メモ. Retrieved April 11, 2020, from https://www.virment.com/config-sambaserver/

関連記事

コメントを投稿

名前

Email (※公開されることはありません)

コメント