• day30 第一阶段大考讲解


    目 录

    系统初始化需求

    关闭selinux

    关闭防火墙服务

    关闭交换分区

    时间同步定时任务需求

    配置yum源

    安装常用软件

    配置hosts解析

    服务部署题目

    将主机名修改为linux7

    配置nginx官方源

    指定yum源安装软件

    启动nginx服务并设置开机自启动

    精简配置文件

    启动nginx服务并设置开机自启动

    查找nginx进程是否存在

    访问并测试nginx是否可以访问

    创建普通用户www

    修改nginx配置文件里的运行用户

    重启nginx服务

    检查运行用户是否为www

    添加第二块磁盘并挂载到/code目录

    写入测试文件到/code目录

    编写自定义配置文件

    重新加载nginx配置文件

    测试访问

    定时备份

    日志切割

    第1章 系统初始化需求

    1.1 *关闭selinux*

    已知selinux配置文件为/etc/selinux/config

    需要将配置文件里的SELINUX=enforcing修改为SELINUX=disabled

    请写出临时关闭和永久关闭的命令

    Sed -i ‘s#SELINUX=enforcing #SELINUX=disabled#g’/etc/selinux/config

    setenforce 0

    Getenforce

    1.2 *关闭防火墙服务*

    已知需要关闭的服务名称为firewalld和NetworkManager

    请写出关闭服务和禁止开机自启动的命令

    Systemctl stop firewalld

    Systemctl stop NetworkManager

    Systemctl disable firewalld

    Systemctl disable NetworkManager

    1.3 *关闭交换分区*

    请写出临时关闭和永久关闭swap分区的步骤

    Swapoff -a

    sed -i '/dev/mapper/centos-swap swap/d' /etc/fstab

    1.4 *时间同步定时任务需求*

    已知时间服务器地址为time1.aliyun.com

    现在需要每隔5分钟同步一下系统时间,并且将输出定向到空

    请写配置步骤

    1.5 *配置**yum**源*

    配置系统的yum源为阿里源:

    https://mirrors.aliyun.com/repo/Centos-7.repo

    http://mirrors.aliyun.com/repo/epel-7.repo

    Curl -o /etc/yum.repos.d/Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo

    Curl -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

    需求:

    1.删除其他的源

    2.配置阿里云的base和epel源

    3.使用三剑客删除阿里源文件里的包含aliyuncs的行

    1.rpm -rf /etc/yum.repos.d/*

    2.yum makecache fast

    3.sed -i '/aliyuns/d' /etc/yum.repos.d/Centos-7.repo

    4.sed -i '/aliyuns/d' /etc/yum.repos.d/epel-7.repo

    1.6 *安装常用软件*

    安装以下的软件:

    Yum install tree vim wget bash-completion bash-completion-extras lrzsz net-tools iotop iftop htop unzip ntpdate -y

    1.7 *配置**hosts**解析*

    将以下内容写入/etc/hosts文件

    Cat >> /etc/hosts <<EOF

    10.0.0.5 172.16.1.5 lb-5

    10.0.0.6 172.16.1.6 lb-6

    10.0.0.7 172.16.1.7 web-7

    10.0.0.8 172.16.1.8 web-8

    10.0.0.9 172.16.1.9 web-9

    10.0.0.31 172.16.1.31 nfs-31

    10.0.0.41 172.16.1.41 backup-41

    10.0.0.51 172.16.1.51 db-51

    10.0.0.61 172.16.1.61 m-61

    EOF

    第2章 *服务部署题目*

    2.1 *修改主机名*

    将主机名修改为linux7

    hostname linux7

    echo CentOS7-100 >/etc/hostname

    2.2 *修改IP地址*

    修改IP地址为10.0.0.200

    find / -name '*eth0'

    Cat /etc/sysconfig/network-scripts/ifcfg-eth0

    sed -i 's#IPADDR=10.0.0.100#IPADDR=10.0.0.200#g' /etc/sysconfig/network-scripts/ifcfg-eth0

    2.3 *配置nginx官方源*

    自己去官网找:

    http://nginx.org/en/download.html

    你的步骤:

    [root@CentOS7-100 yum.repos.d]# cat >/etc/yum.repos.d/nginx.repo<< 'EOF'

    > [nginx-stable]

    > name=nginx stable repo

    > baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

    > gpgcheck=1

    > enabled=1

    > gpgkey=https://nginx.org/keys/nginx_signing.key

    > module_hotfixes=true

    >

    > [nginx-mainline]

    > name=nginx mainline repo

    > baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/

    > gpgcheck=1

    > enabled=0

    > gpgkey=https://nginx.org/keys/nginx_signing.key

    > module_hotfixes=true

    > EOF

    2.4 *指定**yum**源安装软件*

    因为epel源和nginx官方源有冲突,需要从nginx官方源安装指定的nginx,请问如何解决?

    查看nginx源

    yum list nginx

    yum install nginx --enablerepo=[nginx.repo] -y

    2.5 *启动nginx服务并设置开机自启动*

    systemctl enable nginx

    2.6 *精简配置文件*

    已知nginx的配置文件为 /etc/nginx/nginx.conf

    请使用三剑客命令将这个配置文件里的注释和空行过滤掉并保存

    先过滤cat /etc/nginx/nginx.conf |egrep -v '#|^$'

    Mkdir /backup

    cat /etc/nginx/nginx.conf |egrep -v '#|^$' > /backup/nginx.conf

    cp -a nginx.conf /etc/nginx/

    2.7 *启动**nginx**服务并设置开机自启动*

    systemctl enable nginx

    systemctl start nginx

    2.8 *查找**nginx**进程是否存在*

    ps -ef |grep [n]ginx

    2.9 *访问并测试nginx是否可以访问*

    测试命令如下:

    curl -I 127.0.0.1

    返回结果:

    200

    2.10 *创建普通用户www*

    创建普通用户名为www

    uid和gid均为2000,不创建家目录,不允许登陆

    请写出创建用户的命令和查看用户的命令

    groupadd -g 2000 www

    useradd -u 2000 -g 2000 -s /sbin/nologin -M www

    2.11 *修改**nginx**配置文件里的运行用户*

    请使用三剑客命令将nginx.conf配置文件里的user nginx; 修改为user www;

    sed -i 's#user nginx;#user www;#g' /etc/nginx/nginx.conf

    2.12 *重启**nginx**服务*

    systemctl restart nginx

    2.13 *检查运行用户是否为**www*

    请写出检查nginx进程是否为www用户运行的命令

    [root@CentOS7-100 backup]# ps -ef |grep [n]ginx

    root 1422 1 0 20:23 ? 00:00:00 nginx: master process /usr/sbin/nginx

    www 1424 1422 0 20:23 ? 00:00:00 nginx: worker process

    2.14 *添加第二块磁盘并挂载到/**code**目录*

    需求:

    1.添加1块10G大小的磁盘并格式化xfs文件系统

    Lsblk 查看挂载块设备

    Mkfs.xfs /dev/sdb

    2.将磁盘挂载到/code目录

    mount /dev/sdb /code

    3.检查是否挂载成功

    df -h

    4.将挂载信息写入到开机自启动

    Vim /etc/fstable

    /dev/sdb /code xfs defaults 0 0

    2.15 *写入测试文件到**/code**目录*

    需求:

    1.使用三剑客命令提取本机的IP地址并写入到/code/index.html文件中

    cat /etc/sysconfig/network-scripts/ifcfg-eth0 |grep 'IPADDR='|awk -F '=' '{print$2}' >/code/index.html

    2.将/code目录以及目录里所有的文件修改为www用户

    chown -R www: /code

    ll /code

    2.16 *编写自定义配置文件*

    需求:

    1.删除/etc/nginx/conf.d/目录下所有的文件

    Rm -rf /etc/nginx/conf.d/*

    2.将以下文本写入到/etc/nginx/conf.d/code.conf文件里

    注意:不能使用vi或vim

    server {

    listen 80;

    server_name localhost;

    location / {

    ​ root /code;

    ​ index index.html;

    }

    }

    操作步骤:

    [root@CentOS7-100 conf.d]# cat >/etc/nginx/conf.d/code.conf<< EOF

    > server {

    > listen 80;

    > server_name localhost;

    > location / {

    > root /code;

    > index index.html;

    > }

    > }

    > EOF

    [root@CentOS7-100 conf.d]# ls

    code.conf

    2.17 *重新加载n**ginx**配置文件*

    注意是重新加载,不是重启

    操作步骤:

    [root@CentOS7-100 conf.d]# systemctl reload nginx

    2.18 *测试访问*

    测试命令:

    curl 127.0.0.1

    返回结果:

    [root@CentOS7-100 conf.d]# curl 127.0.0.1

    10.0.0.100

    2.19 *定时备份*

    需求:

    1.将/code目录每天凌晨1点打包压缩一份备份到/backup目录下

    2.要求备份名称包含当前日期,举例:code_2021-11-03.tar.gz

    提示:

    显示当前日期的命令为date +%F

    你的步骤:

    1. tar -zcvf /backup/code_$(date +%F).tar.gz /code

    2. [root@CentOS7-100 backup]# crontab -e

    3. crontab: installing new crontab

    4. [root@CentOS7-100 backup]# crontab -l

    5. 00 01 * * * tar -zcvf /backup/code_$(date +%F).tar.gz /code

    2.20 *日志切割*

    需求:

    1.将/var/log/nginx/access.log移动到/backup/access_log_2021-11-03.log,注意时间是当天的日期。

    [root@CentOS7-100 nginx]# mv /var/log/nginx/access.log /backup/access_log_$(date +%F).log

    2.移动成功后重新加载nginx

    [root@CentOS7-100 nginx]# systemctl reload nginx

    3.将上面的操作编写成定时任务每天1点30分执行

    [root@CentOS7-100 nginx]# crontab -l

    00 01 * * * tar -zcvf /backup/code_$(date +%F).tar.gz /code

    30 01 * * * mv /var/log/nginx/access.log /backup/access_log_$(date +%F).log && systemctl reload nginx

    4.编写定时任务,对/backup/目录下的文件每周日清理一次,只保留7天以内的日志

    30 01 * * 0 find /backup/ -type f -mtime +7 |xargs rm -rf

  • 相关阅读:
    C#生成满足特定要求的密码
    抽象方法(abstract method) 和 虚方法 (virtual method), 重载(overload) 和 重写(override)的区别于联系
    面试问题 ---C#中的委托
    面试问题
    如何用DOS命令,获取一个目录下的文件数目
    vim怎么把一个写的代码文件另存到任意文件夹里?
    WIN7 不用格式化磁盘怎么把FAT32系统改成NTFS系统
    rhel6 中安装使用finger命令
    Redhat enterpise6 安装unix2dos/dos2unix
    阐述Linux操作系统之rpm五种基本操作
  • 原文地址:https://www.cnblogs.com/zhaocheng690/p/15510555.html
Copyright © 2020-2023  润新知