---
# System prepended metadata

title: 1/20

---

# 1/20

- 系統更新及安裝管理套件

- 虛擬機器設定勾選選項1和3
CPU有虛擬技術
IO速度變快

- (研)更改登入訊息 
    - /etc/motd
    - 寫上產品名稱: Cloud Native Trainer

- keyboard layout
    - `us`

- 如打 us 會有地區上的差異性
    - 出現 variants: `us`

- (研)以上 TW 跟 US 的差別

- localhost 主機名
    - `cnt`

- 選網卡 eth0
    - `enter`

- Ip address dhcp
    - `enter`

```
lease time 1800 
#IP只能有效30分鐘(駐用時間)  
```

- 要不要手動網路設定 [n]
    - `enter`

- 改 root 密碼
    - root

- 時區
    - `Asia`
    - `Tapei`
```
Starting busybox acpid...
Starting busybox crond...
```

- (研)
>> acpid

- (研)
>> crond

- (研)自己建 proxy server:亨
- HTTP/FTP proxy URL? [none]
    - 透過 proxy 上網
    - `enter`


- (研)自己建 time server:亨
- ntp 時間伺服器 [chrony]
    - Hadoop datanode namenode 若時間差15分鐘，系統就壞掉
    - 去用 proxy 上網，問chrony client 時間
    - 公司一定要有 time server(在公司裝過是核心工程師)


- `6`

- ssh server [openssh]
    - (研究功能性)
    - dropbear 嵌入式系統: 物聯網都用這套
    - `enter`

- disk(s) 用哪顆硬碟
    - `sda`

- How would you like to use it? ('sys', 'data', 'lvm' or ? for help) 
    - (研)lvm: 很快地把硬碟空間加大
    - `sys`

- 是否要把硬碟空間清掉，用這個硬碟
    - `y`

- browser 搜尋
    - alpine custom install

- How to make a custom ISO image(研): captain

>> 自己做 iso 檔

> reboot

- bigred 可以用 sudo 免密碼

- 有 prefly 的功能
    - 建管理者帳號
    - 可利用sshpass，就不會問你密碼


> busybox httpd -p 8888 -h ~/www




> cat www/set/prefly.sh
```bash=
#!/bin/bash
apk update &>/dev/null
apk upgrade &>/dev/null

which nano &>/dev/null
if [ "$?" != "0" ];then
  apk add nano bash curl tree sudo grep procps &>/dev/null
  echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
  echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config
else
  echo 'system ready'
fi

if [ ! -d  /home/bigred ];then
  adduser -s /bin/bash -h /home/bigred -D bigred
  addgroup bigred wheel
  echo -e "bigred\nbigred\n" | passwd bigred &>/dev/null
  echo 'bigred ok'
fi

#for i in $(seq 1 2)
#do
#  if [ ! -d  /home/student${i} ];then
#  adduser -s /bin/bash -h /home/student${i} -D student${i}
#  echo -e "student${i}\nstudent${i}\n" | passwd student${i}
#fi
#done
```

- 設定使用憑證登入
    - known_hosts 如果複製到別台機器
        - 此台連過以前的機器，握有"其他台"公鑰，則無法進去"其他台"

> cat sysprep.sh
```bash=
#!/bin/bash

[ `hostname` != "gw01" ] && echo "wrong hostname" && exit 1
[ `whoami` != "bigred" ] && echo "wrong user" && exit 1

echo '' | ssh-keygen -t rsa -P '' &>/dev/null
cp .ssh/id_rsa.pub .ssh/authorized_keys

for n in mas01 wka01 wka02 wka03 mas02 mas03
do
  nc -w 1 -z $n 22 &>/dev/null
  if [ "$?" == "0" ];then
    sshpass -p 'bigred' ssh $n 'rm -r ~/.ssh/ &>/dev/null'
    sshpass -p 'bigred' ssh $n 'mkdir -p ~/.ssh'
    sshpass -p 'bigred' scp -r .ssh/ $n:~
    sshpass -p 'bigred' ssh $n 'chmod -R 700 .ssh/'
    sshpass -p 'bigred' ssh $n 'rm ~/.ssh/known_hosts'
    echo "$n ssh key ok"
  fi
done
```

> cat sysinfo.sh
```bash=
gw=$(route -n | grep -e "^0.0.0.0 ")
GWIF=${gw##* }
ips=$(ifconfig $GWIF | grep 'inet ')
IP=$(echo $ips | cut -d' ' -f2)
NETID=${IP%.*}
GW=$(route -n | grep -e '^0.0.0.0' | tr -s \ - | cut -d ' ' -f2)

echo "[`hostname`]"
echo "--------------------------------------------------------"
cn=$(cat /proc/cpuinfo | grep 'model name' | head -n 1 | cut -d ':' -f2 | tr -s ' ')
echo -n "CPU : $cn (core: "
cn=$(cat /proc/cpuinfo | grep 'model name' | wc -l)
echo "$cn)"

m=$(free -mh | grep Mem:)
echo -n "Memory : "
echo $m | cut -d' ' -f2 | sed 's/.$//'


echo "IP Address : $IP"
echo "Default Gateway : $GW"
echo ""

java -version &> /tmp/java
[ "$?" != "0" ] && echo 'JAVA NOT FOUND' || cat /tmp/java
echo ""
```

> cp sysinfo.sh www/set/

> ssh wka01 'curl -s http://192.168.10.254:8888/set/sysinfo.sh | bash'

- 查看作業系統
> cat /etc/os-release | head -n 1 | cut -d'=' -f2