1、編寫腳本,接受二個位置參數(shù),magedu和/www,判斷系統(tǒng)是否有magedu,如果沒有則自動創(chuàng)建magedu用戶,并自動設置家目錄為/www
- 準備腳本
[root@localhost ~]# cat createuser.sh
#!/bin/bash
usage (){
echo "Receive user name and home directory to create user
eg: $0 admin /home/admin"
}
create_user (){
id $1 &> /dev/null
if [ $? -eq 0 ];then
echo "User $1 exsit!"
else
useradd -d $2 $1 &> /dev/null && echo "Create $1 and directory is $2" || echo "Args error, try again"
fi
}
if [ $# -eq 2 ];then
create_user $1 $2
else
usage
fi
[root@localhost ~]#
- 測試腳本
[root@localhost ~]# bash createuser.sh
Receive user name and home directory to create user
eg: createuser.sh admin /home/admin
[root@localhost ~]# bash createuser.sh xxx xxx
Args error, try again
[root@localhost ~]#
[root@localhost ~]# bash createuser.sh xxx /home/xxx
Create xxx and directory is /home/xxx
[root@localhost ~]# getent passwd xxx
xxx:x:1001:1001::/home/xxx:/bin/bash
[root@localhost ~]#
[root@localhost ~]# bash createuser.sh xxx /xxx
User xxx exsit!
[root@localhost ~]#
2、使用expect實現(xiàn)自動登錄系統(tǒng)。
- 編寫自動登錄腳本
[root@localhost ~]# cat expect_login.sh
#!/bin/bash
user="root"
ip="10.0.0.8"
pass="123456"
rpm -q expect &> /dev/null || yum -y install expect
expect << EOF
set timeout 20
spawn ssh ${user}@${ip}
expect {
"yes/no" {send "yes\n"; exp_continue }
"password" {send "${pass}\n" }
}
expect eof
EOF
[root@localhost ~]#
- 測試腳本
[root@localhost ~]# bash expect_login.sh
spawn ssh root@10.0.0.8
root@10.0.0.8's password:
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Mon Dec 14 19:22:09 2020 from 10.0.0.7
[root@localhost ~]#
3、簡述linux操作系統(tǒng)啟動流程
- centos6的啟動流程
- BIOS加電自檢,檢查各個硬件是否符合操作系統(tǒng)啟動條件
- bootloader引導加載grub程序,通過grub內置的文件系統(tǒng)驅動識別掛載boot分區(qū)
- 加載內核到內存,內核通過initramfs識別根分區(qū),加載存放在根分區(qū)的文件系統(tǒng)驅動,從而掛載根分區(qū),然后啟動/etc/sysinit
- centos7、8的啟動流程
- BIOS加電自檢,檢查各個硬件是否符合操作系統(tǒng)啟動條件
- bootloader引導加載grub2程序,通過grub2內置的文件系統(tǒng)驅動識別掛載boot分區(qū)
- 加載內核到內存,內核通過initramfs識別根分區(qū),加載存放在根分區(qū)的文件系統(tǒng)驅動,從而掛載根分區(qū),然后啟動各個systemd的服務
4、破解centos7 密碼。
1.方法1
-
重啟服務器,在選擇內核界面,按e鍵修改啟動項,找到linux開始的行,添加rd.break參數(shù),并按Ctrl+x啟動
image.png -
切根,改密碼
image.png
2.方法2
-
重啟服務器,在選擇內核界面,按e鍵修改啟動項,找到linux開始的行,修改ro 為rw /sysroot/bin/sh,并按Ctrl+x啟動
image.png -
切根,改密碼
image.png
架構作業(yè)
1、使用dockerfile制作nginx+php-fpm鏡像,實現(xiàn)lnmp。
2、使用dockerfile制作tomcat鏡像,并實現(xiàn)對jsp測試頁訪問
3、安裝配置harbor服務,并將打包好的鏡像提交到harbor倉庫"



