Skip to content

Latest commit

 

History

History
75 lines (67 loc) · 3.6 KB

File metadata and controls

75 lines (67 loc) · 3.6 KB

111-2Course-System-Adminstration

Homework 2 - Bash Shell Script

hw2.sh

shell script for hw2 of Network Adminstration in NCKU.

Homework 3 - Log & File Maintenance

Add three 1GB disks 新增三個1GB的硬碟

To get the name of the hard disk we added, let's first take a screenshot after giving command ls /dev. After that, shut down your VM with shutdown, and turn the VM down by VMware.

VMware Steps below:

  1. Press Add under Hardware
  2. New a Hard Disk
  3. Select the type of the new hard disk. (SCSI recommended by VMware though)
  4. Select Create a new virtual disk if you haven't new a disk yet
  5. Set the size of the disk to 1 GB

為了知道新增的硬碟叫什麼名字,先ls /dev然後把印出來的內容截圖起來。接著用shutdown把VM關機以後再用VMware shutdown機器。
打開VM設定,新增三顆大小為1GB的虛擬硬碟。

VMware的步驟如下 :

  1. 在Hardware底下按Add按鈕
  2. 新增一個硬碟
  3. 選擇硬碟的種類 (VMWare預設建議用SCSI)
  4. 選擇 Create a new virtual disk,如果是已經新增好了也可以選擇Using an existing disk
  5. 將大小設定為1GB

Create Pool

Create a ZFS RAID-Z pool named sa_pool and three 1G disks as devices.
sudo zpool create sa_pool raidz /dev/da1 /dev/da2 /dev/da3

Create Dataset

Make a new file system called data in pool sa_pool, set the following properties compression=lz4, copies=2, atime=off and mount it at /sa_data.
sudo zfs create -o compression=lz4 atime=off copies=2 mountpoint=/sa_data sa_pool/data

Also, we can change the properties after create the dataset by using zfs set.
sudo zfs create sa_pool/data
sudo zfs set compression=lz4 atime=off copies=2 mountpoint=/sa_data sa_pool/data

We can use sudo zfs get all sa_pool/data | less to check the properties.

Change directory owner and group

commands :

  • chown(8) -- change user owner
  • chgrp(1) -- change group owner
  • -R : recursively change (for directory)

Download logrotate

github of logrotate : https://github.com/logrotate/logrotate/tree/master
先下載logrotate這個套件。
sudo pkg install logrotate

Log Rotate Configutation file

reference : https://superuser.com/questions/1403121/systemd-logrotate-to-specific-folder , https://adamtheautomator.com/logrotate-linux/
example for config file : https://superuser.com/questions/1403121/systemd-logrotate-to-specific-folder , https://github.com/logrotate/logrotate/blob/master/examples/logrotate.conf

題敘 :

  • Add a logrotate configuration file in /etc/logrotate.d/fakelog
  • The program will generate a log file in /var/log/fakelog.log, copy the log files to the /var/log/fakelog/.
  • Set the number of log files to rotate to 10. : rotate <count>
  • Set the maximum size of each log file to 1k. : maxsize <size> (1k)
  • Move the log files to the /var/log/fakelog/ directory. : olddir <dir>

產生fakelog :
sudo ./fakeloggen.py 55 --logrotate

ZFS Managing tools

reference : logrotate/logrotate#89, https://gist.github.com/alexjj/4de71ddfae05e974c829

  1. Create /sa_data/log directory
  2. python scripting :D
  3. Well Done!

create snapshot

zfs snapshot <pool>/<dataset>@<identifier>

remove snapshot

zfs destroy <pool>/<dataset>@<identifier>

remove all snapshot

zfs destroy <pool>/<dataset>@%

list snapshot

zfs list -r -t snapshot -o name /<mountpoint> | sed -e '1d

rollback snapshot

zfs rollback -r <pool>/<dataset>@<identifier>

希望不會被當 :D