马哥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 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操作系统启动流程

  • 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启动


    image.png
  • 切根,改密码


    image.png

    2.方法2

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


    image.png
  • 切根,改密码


    image.png

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、编写脚本,接收二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu...
    L星Y阅读 155评论 0 0
  • 一、选择题:(20 分,每题2 分) 1、下列哪个不属于内核的功能? ( A ) A 用户管理B 内存管理C 进程...
    xinxin2019阅读 808评论 0 0
  • 1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu...
    82bb6438ec05阅读 221评论 0 0
  • 1、描述Linux发行版的系统目录名称命名规则以及用途。linux各发行版都遵循LSB(Linux Standar...
    letsgoheat_c1dc阅读 476评论 2 0
  • 1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu...
    阿浩浩浩阅读 296评论 0 0