shell script for hw2 of Network Adminstration in NCKU.
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:
- Press
Add
underHardware
- New a Hard Disk
- Select the type of the new hard disk. (SCSI recommended by VMware though)
- Select
Create a new virtual disk
if you haven't new a disk yet- Set the size of the disk to 1 GB
為了知道新增的硬碟叫什麼名字,先ls /dev
然後把印出來的內容截圖起來。接著用shutdown
把VM關機以後再用VMware shutdown機器。
打開VM設定,新增三顆大小為1GB的虛擬硬碟。
VMware的步驟如下 :
- 在Hardware底下按Add按鈕
- 新增一個硬碟
- 選擇硬碟的種類 (VMWare預設建議用SCSI)
- 選擇
Create a new virtual disk
,如果是已經新增好了也可以選擇Using an existing disk
- 將大小設定為1GB
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
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.
commands :
chown
(8) -- change user ownerchgrp
(1) -- change group owner-R
: recursively change (for directory)
github of logrotate
: https://github.com/logrotate/logrotate/tree/master
先下載logrotate
這個套件。
sudo pkg install logrotate
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
reference : logrotate/logrotate#89, https://gist.github.com/alexjj/4de71ddfae05e974c829
- Create
/sa_data/log
directory - python scripting :D
- Well Done!
zfs snapshot <pool>/<dataset>@<identifier>
zfs destroy <pool>/<dataset>@<identifier>
zfs destroy <pool>/<dataset>@%
zfs list -r -t snapshot -o name /<mountpoint> | sed -e '1d
zfs rollback -r <pool>/<dataset>@<identifier>
希望不會被當 :D