ericvlog / note

6 stars 1 forks source link

Complete guide the setup linux based system as nas #27

Open ericvlog opened 2 years ago

ericvlog commented 2 years ago

Step 1: Install the ‘sudo’ command

  1. Switch user to root su -
    apt get install sudo
  2. Added user to sudo groups, use id username to checks user groups.
usermod -aG sudo username
  1. Logout & login SSH

Install Docker & Portainer 2.0 on Debian Based Distros!

  1. Install and start docker by running the commands below.

sudo apt install docker.io sudo systemctl start docker

  1. Download and run Portainer 2.0 by running the commands below.

sudo docker pull portainer/portainer-ce sudo docker run --restart=always --name=portainer -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer-ce

  1. This will install Docker and it will be accessible by the workstation’s IP address and port 9000. When you get there, create a username and password.

http://[WORKSTATION_IP_ADDRESS]:9000

  1. Give user permission for docker.
    sudo groupadd docker
    sudo usermod -aG docker $USER

    logout & login ssh.

Install docker-compose

sudo apt install docker-compose

Install docker-compose v2

  1. X86 device
    mkdir -p /usr/local/lib/docker/cli-plugins
    curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
  2. Arm device
    mkdir -p /usr/local/lib/docker/cli-plugins
    curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-aarch64 -o /usr/local/lib/docker/cli-plugins/docker-compose
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version

Mount hardisk in armbian.

useful command

lsblk #check hardisk 'add -f' for checking file system of drive.
sudo blkid #check hardisk uuid.
mount /dev/fromlsblk /mountpoint #mount hardisk command.

Let's suppose we have a single disk drive and want it to be available at /mnt/wd, run the following commands

sudo mkdir /mnt/wd sudo chown -hR $(whoami):$(whoami) /mnt/wd

The next thing we have to do is edit /etc/fstab file and include the new path so that our disk drive will be recognized the next time we restart.

Run the following command and take a note of the ID number of the disk drive you want to automatically mount.

sudo blkid

Having the correct disk ID, we now edit /etc/fstab

sudo nano /etc/fstab

Then we add a new line to the end of /etc/fstab so that the system knows what to mount and where.

UUID="ID From blkid" /mnt/wd ext4 rw,user,auto 0 0

Reboot for it mount automatic.

Set up Samba Shares

Samba allows you to share files via the SMB network protocol. Basically this means file and print services for various Microsoft Windows clients and integration with a Microsoft Windows Server domain.

First you need to install samba and smbfs by running.

sudo apt-get install samba smbfs

After the installation is done, edit /etc/samba/smb.conf to include settings for the share folders. In the example, we're sharing /mnt/wd with both read and write permission.

NAS share directory

Install dependencies: sudo apt install samba samba-common-bin

Setup Network Shares Edit the Samba config:

sudo nano /etc/samba/smb.conf Add the following to the end of the smb.conf file:

[mynas]
    comment = Samba on My NAS
    path = /patch
    read only = no
    browsable = yes

This creates a share called “mynas” allowing access to all the drives mounted under the /mnt folder. Read-only is set to no, which permits modifying and writing data to the share. Browsable allows the share to be seen by a Linux file manager or Windows Explorer.

Add user account to access the Samba share Since Samba doesn’t use the system account password, we need to set up a Samba password for our user account: You can also specify a different username, although it must exist on the system.

sudo smbpasswd -a $(whoami) sudo smbpasswd -a anotheruser

Restart Samba sudo service smbd restart

Connect to the Share You can now connect to the share using \IP address of NAS from Windows Explorer.

If unable access from windows, try reboot windows and tested.

Or smb://IP address of NAS from a Linux file manager.

How To View Linux Machines from a Windows 10 Network

Installing WSD on Ubuntu wsdd is a service by christgau on GitHub, which implements a Web Service Discovery host daemon for Ubuntu. This enables Samba hosts to be found by Web Service Discovery Clients like Windows 10.

If you are experiencing any issues with this service, please let us know in the comments or submit an issue on GitHub.

Change to /tmp directory.

cd /tmp

Download and unzip the archive.

wget https://github.com/christgau/wsdd/archive/master.zip

unzip master.zip

Rename wsdd.py to wsdd.

sudo mv wsdd-master/src/wsdd.py wsdd-master/src/wsdd

Copy to /usr/bin.

sudo cp wsdd-master/src/wsdd /usr/bin

Copy wsdd to /etc/systemd/system.

sudo cp wsdd-master/etc/systemd/wsdd.service /etc/systemd/system

Open wsdd.service in nano and comment out User=nobody and Group=nobody with a ; semicolon.

sudo nano /etc/systemd/system/wsdd.service

If you found out below code different from yours just copy and paste it under [Service] to remove original code.

/etc/systemd/system/wsdd.service
[Unit]
Description=Web Services Dynamic Discovery host daemon
; Start after the network has been configured
After=network-online.target
Wants=network-online.target
; It makes sense to have Samba running when wsdd starts, but is not required
;Wants=smb.service

[Service]
Type=simple
ExecStart=/usr/bin/wsdd --shortlog
; Replace those with an unprivledged user/group that matches your environment,
; like nobody/nogroup or daemon:daemon or a dedicated user for wsdd
; User=nobody 
; Group=nobody
; The following lines can be used for a chroot execution of wsdd.
; Also append '--chroot /run/wsdd/chroot' to ExecStart to enable chrooting
;AmbientCapabilities=CAP_SYS_CHROOT
;ExecStartPre=/usr/bin/install -d -o nobody -g nobody -m 0700 /run/wsdd/chroot
;ExecStopPost=rmdir /run/wsdd/chroot

[Install]
WantedBy=multi-user.target

Save and exit (press CTRL + X, press Y and then press ENTER) Reload daemon.

sudo systemctl daemon-reload

Start and enable wsdd.

sudo systemctl start wsdd

sudo systemctl enable wsdd

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/wsdd.service → /etc/systemd/system/wsdd.service.

Now check that the service is running.

sudo service wsdd status

Output:

● wsdd.service - Web Services Dynamic Discovery host daemon Loaded: loaded (/etc/systemd/system/wsdd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-06-10 10:51:39 CEST; 8s ago Main PID: 40670 (python3) Tasks: 1 (limit: 6662) Memory: 10.8M CGroup: /system.slice/wsdd.service └─40670 python3 /usr/bin/wsdd --shortlog

jun 10 10:51:39 ubuntu systemd[1]: Started Web Services Dynamic Discovery host daemon. jun 10 10:51:40 ubuntu wsdd[40670]: WARNING: no interface given, using all interfaces

You should now be able to browse your Ubuntu machines and Samba shares in the Windows 10 file explorer. You may need to restart the Windows 10 machines to force discovery.

You may also want to reboot the Ubuntu server just to make sure the wsdd service starts up automatically without issue.

Disable zram Optional

sudo vim /etc/default/armbian-zram-config A few lines down the file, uncomment the line that says SWAP=false:

Zram swap enabled by default, unless set to disabled

SWAP=false Reboot, and the zram swap is gone.


Credits

https://devanswers.co/discover-ubuntu-machines-samba-shares-windows-10-network/

ericvlog commented 3 months ago

Installing SAMBA

The first step in setting up SAMBA is to install the necessary packages. This can be done using Debian's package management system. Open a terminal and run the following command:

sudo apt update
sudo apt install samba samba-common-bin

Once the installation process completes, the SAMBA service should start automatically. You can verify its status with:

sudo systemctl status smbd

Configuring SAMBA

With SAMBA installed, the next step is to configure it appropriately. The main configuration file for SAMBA is /etc/samba/smb.conf. Before making changes, it's good practice to back up the original configuration file:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup

Edit the configuration file using your preferred text editor, like nano:

sudo nano /etc/samba/smb.conf

In the smb.conf file, you can set up different shared directories, adjust security settings, and define user access permissions. Here's an example of how to define a new share:

\[SharedDocs\]
   path = /srv/samba/sharedocs
   writable = yes
   guest ok = no
   valid users = @sambashare

This configuration sets up a share named 'SharedDocs' pointing to /srv/samba/sharedocs, which is writable but not accessible by guests, and only accessible by users in the 'sambashare' group.

Creating a Shared Directory

Create the directory that you want to share and set its permissions accordingly:

sudo mkdir -p /srv/samba/sharedocs
sudo chown nobody:nogroup /srv/samba/sharedocs
sudo chmod 0775 /srv/samba/sharedocs

Managing User Access

To allow users to access the shared directory, you may need to add them to the sambashare group and create a Samba password:

sudo adduser your_username sambashare
sudo smbpasswd -a your_username

Replace your_username with the actual username of the person needing access.

Finalizing and Testing Configuration

After configuring SAMBA, restart the service for changes to take effect:

sudo systemctl restart smbd

To ensure that your shares are correctly configured, use the smbclient utility to list available shares:

smbclient -L localhost -U %

If everything is set up correctly, you should see your shared directories listed.

Troubleshooting Common Issues

If you encounter issues accessing your shares, check the following:

ericvlog commented 3 months ago

如何在 Debian 上挂载 RAID 0

根据你的 blkid 输出信息,/dev/sdb1, /dev/sdc1, 和 /dev/sdd1linux_raid_member 类型的分区,表明它们是 RAID 0 阵列的一部分。你可以使用 mdadm 工具来组装和挂载 RAID 0 阵列。

步骤 1:安装 mdadm

如果尚未安装 mdadm,你需要先安装它。

sudo apt-get update
sudo apt-get install mdadm

步骤 2:组装 RAID 阵列

使用 mdadm 来组装 RAID 阵列。你需要知道 RAID 阵列的设备名称(通常是 /dev/md0)。

sudo mdadm --assemble --scan

这将自动扫描并组装 RAID 阵列。

步骤 3:验证 RAID 阵列

你可以使用以下命令来验证 RAID 阵列是否已成功组装。

cat /proc/mdstat

输出应该显示类似以下内容:

Personalities : [raid0]
md0 : active raid0 sdd1[2] sdc1[1] sdb1[0]
      117187328 blocks super 1.2 512k chunks

步骤 4:挂载 RAID 阵列

找到 RAID 阵列的设备名称(假设是 /dev/md0),然后将其挂载到指定的挂载点。

sudo mkdir -p /mnt/raid0
sudo mount /dev/md0 /mnt/raid0

步骤 5:验证挂载

你可以使用 df -hlsblk 来验证 RAID 阵列是否已成功挂载。

df -h
lsblk

步骤 6:自动挂载(可选)

如果你希望在每次启动时自动挂载 RAID 阵列,你需要编辑 /etc/fstab 文件。首先,获取 RAID 阵列的 UUID:

sudo blkid /dev/md0

复制 UUID,然后编辑 /etc/fstab 文件并添加以下行:

UUID=your-raid-uuid /mnt/raid0 ext4 defaults 0 0

your-raid-uuid 替换为你从 blkid 命令中获取的 UUID。


完成以上步骤后,你的 RAID 0 阵列应该已经成功组装并挂载到 /mnt/raid0 目录。