马哥N49第十周作业

1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建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实现自动登录系统。

  • 编写自动登录脚本
[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 [email protected]
[email protected]'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操作系统启动流程

  • centos6的启动流程
  1. BIOS加电自检,检查各个硬件是否符合操作系统启动条件
  2. bootloader引导加载grub程序,通过grub内置的文件系统驱动识别挂载boot分区
  3. 加载内核到内存,内核通过initramfs识别根分区,加载存放在根分区的文件系统驱动,从而挂载根分区,然后启动/etc/sysinit
  • centos7、8的启动流程
  1. BIOS加电自检,检查各个硬件是否符合操作系统启动条件
  2. bootloader引导加载grub2程序,通过grub2内置的文件系统驱动识别挂载boot分区
  3. 加载内核到内存,内核通过initramfs识别根分区,加载存放在根分区的文件系统驱动,从而挂载根分区,然后启动各个systemd的服务
    4、破解centos7 密码。
    1.方法1
  • 重启服务器,在选择内核界面,按e键修改启动项,找到linux开始的行,添加rd.break参数,并按Ctrl+x启动


    马哥N49第十周作业_第1张图片
    image.png
  • 切根,改密码


    马哥N49第十周作业_第2张图片
    image.png

    2.方法2

  • 重启服务器,在选择内核界面,按e键修改启动项,找到linux开始的行,修改ro 为rw /sysroot/bin/sh,并按Ctrl+x启动


    马哥N49第十周作业_第3张图片
    image.png
  • 切根,改密码


    马哥N49第十周作业_第4张图片
    image.png

架构作业
1、使用dockerfile制作nginx+php-fpm镜像,实现lnmp。
2、使用dockerfile制作tomcat镜像,并实现对jsp测试页访问
3、安装配置harbor服务,并将打包好的镜像提交到harbor仓库"

你可能感兴趣的:(马哥N49第十周作业)