0

ubuntu – nas

 2 years ago
source link: https://xmetal.cc/?p=2103
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
  • 1 Hardware requirements
  • 2 Software requirements
  • 3 Set up static IP and networking
  • 4 Set up RAID
  • 5 Mount the hard drive (optional)
  • 6 Set up NFS Server and NFS Share
  • 7 Set up Samba Shares
  • 8 Assign a nice URL to NAS IP

1 . 至少1核2g 8g 硬盘

2. 按照 ubuntu server

软件选择  SSH Server (to enable SSH access) and Samba (to enable file access).

3. 设置网络

配置静态IP, 新版ubuntu 默认 netplan接管网络

4. RAID (Redundant Array of Independent Disks) 

a storage virtualization technology that combines multiple physical disk drive components into logical units.

分为 硬件raid / 软件raid 软件raid 很鸡肋

In case you decide to use RAID, install mdadm by running the following command:

sudo apt-get --no-install-recommends install mdadm

我们使用–no-install-recommends 来避免安装mail-transport-agent 和default-mta,它们会设置我们并不真正需要的新邮件代理

 If you want a step-by-step guide, check out How To Create RAID Arrays with mdadm.

5. Mount the hard drive (optional)

如果只有一块硬盘, 组不了raid 我们就挂载它吧

1sudo mkdir /mnt/hdd1
2sudo chown -hR $(whoami):$(whoami) /mnt/hdd1

接下来我们要做的是编辑 /etc/fstab 文件并包含新路径,以便下次重新启动时可以识别我们的磁盘驱动器。

运行以下命令并记下要自动挂载的磁盘驱动器的 ID 号

*新磁盘可能需要格式化才能查看到Id,不错ubuntu 20 可以不用知道id 直接绑定

1#查看磁盘id
2sudo blkid 
3#编辑
4sudo nano /etc/fstab
5 
6# fstab 文件添加一下内容
7UUID="ID From blkid" /mnt/hdd1    ext4 rw,user,auto 0    0

6. Set up NFS Server and NFS Share

1sudo apt install nfs-kernel-server

我们现在将创建 NFS 共享的根目录,这也称为导出文件夹。为此,需要编辑 /etc/exports

1sudo vim /etc/exports

我们将在 /mnt/hdd1 共享整个挂载的磁盘,因此我们必须将以下行添加到 /etc/exports 的末尾

1/mnt/hdd1   192.168.1.0/255.255.255.0(rw,sync,root_squash,subtree_check)

您现在可以使用 exportfs 命令使共享目录对客户端可用。之后重新启动 NFS 服务以使更改生效。

1sudo exportfs
2sudo service nfs-kernel-server restart

7. Set up Samba Shares

Samba 允许您通过 SMB 网络协议共享文件。基本上,这意味着各种 Microsoft Windows 客户端的文件和打印服务以及与 Microsoft Windows Server 域的集成

1 安装 samba

sudo apt-get install samba smbfs

2 安装完成后,编辑 /etc/samba/smb.conf 以包含共享文件夹的设置。在示例中,我们共享 /mnt/hdd1 具有读和写权限

1# NAS share directory
2[NASShare]
3comment = anything_will_do
4path = /mnt/hdd1
5read only = no
6guest ok = yes

更多配制参阅 Samba Docs

3 Finally, restart Samba services for the changes to take effect.

1sudo service smbd restart
2 
3# 防火墙设置
4 
5sudo ufw allow samba
6 
7# 添加 smb 用户
8# 注意:此处使用的用户名应该是您的 server上的真实用户。每次更改用户/密码或“smb.conf”时重新加载 Samba
9sudo smbpasswd -a username

Assign a nice URL to NAS IP

您可以通过在 /etc/hosts 文件中添加一行来为您的 NAS IP 地址分配一个不错的本地可访问域

1echo -e "192.168.1.100\t nas.box" | sudo tee -a /etc/hosts

\t 代表制表符

tee -a 将上面的行附加到文件中

您可以通过指定其 IP 地址或 nas.box 来访问 NAS 盒。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK