美文网首页
1+X云计算平台运维与开发认证

1+X云计算平台运维与开发认证

作者: 拾杉 | 来源:发表于2020-11-18 10:43 被阅读0次

    Docker安装题目:

    使用xserver1节点,自行配置YUM源,安装docker服务(需要用到的包为xserver1节点/root目录下的Docker.tar.gz)。安装完服务后,将registry_latest.tar上传到xserver1节点中并配置为私有仓库。要求启动registry容器时,将内部保存文件的目录映射到外部的/opt/registry目录,将内部的5000端口映射到外部5000端口。依次将启动registry容器的命令及返回结果、执行docker info命令的返回结果以文本形式提交到答题框。

    解压docker包
    tar -zxvf Docker.tar.gz

    image.png yu

    开启路由转发,在/etc/sysctl.conf配置文件中添加net.ipv4.ip_forward=1(0为禁用,1为开启)
    vi /etc/sysctl.conf
    net.ipv4.ip_forward=1
    net.bridge.bridge-nf-call-ip6tables=1
    net.bridge.bridge-nf-call-iptables=1

    image.png

    安装依赖包
    yum install -y yum-utils device-mapper-persistent-data

    image.png

    安装docker-ce
    yum install -y docker-ce* containerd.io

    image.png
    启动docker服务并配置docker开机自启
    systemctl start docker && systemctl enable docker
    image.png
    配置私有仓库
    (1)将registry_latest.tar上传到xserver1节点中并配置为私有仓库
    docker load -i images/registry_latest.tar image.png
    image.png
    (2)启动registry容器时,将内部保存文件的目录映射到外部的/opt/registry目录,将内部的5000端口映射到外部5000端口
    docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name=registry registry:latest
    -选项说明
    -d:后台运行
    -v:将主机的本地目录/opt/registry目录挂载到容器的/var/lib/registry目录
    -p:端口映射,将主机5000端口映射到容器的5000端口
    –restart:在容器退出时总是重启容器
    –name:设置容器名称
    image.png
    (3)docker info
    [root@xserver1 ~]# docker info
    Containers: 1
     Running: 1
     Paused: 0
     Stopped: 0
    Images: 1
    Server Version: 18.09.6
    Storage Driver: devicemapper
     Pool Name: docker-253:0-135151151-pool
     Pool Blocksize: 65.54kB
     Base Device Size: 10.74GB
     Backing Filesystem: xfs
     Udev Sync Supported: true
     Data file: /dev/loop1
     Metadata file: /dev/loop2
     Data loop file: /var/lib/docker/devicemapper/devicemapper/data
     Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
     Data Space Used: 59.11MB
     Data Space Total: 107.4GB
     Data Space Available: 27.36GB
     Metadata Space Used: 688.1kB
     Metadata Space Total: 2.147GB
     Metadata Space Available: 2.147GB
     Thin Pool Minimum Free Space: 10.74GB
     Deferred Removal Enabled: true
     Deferred Deletion Enabled: true
     Deferred Deleted Device Count: 0
     Library Version: 1.02.107-RHEL7 (2015-10-14)
    Logging Driver: json-file
    Cgroup Driver: cgroupfs
    Plugins:
     Volume: local
     Network: bridge host macvlan null overlay
     Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
    Swarm: inactive
    Runtimes: runc
    Default Runtime: runc
    Init Binary: docker-init
    containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
    runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
    init version: fec3683
    Security Options:
     seccomp
      Profile: default
    Kernel Version: 3.10.0-327.el7.x86_64
    Operating System: CentOS Linux 7 (Core)
    OSType: linux
    Architecture: x86_64
    CPUs: 2
    Total Memory: 3.688GiB
    Name: xserver1
    ID: SI25:I2VM:2TSU:HN3K:5US5:OQ6W:5JF4:7QT4:L3JZ:MGB4:7YR4:PZ7O
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    Debug Mode (server): false
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: false
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false
    Product License: Community Engine
    
    WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
    WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
             Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
    

    Docker运维题目:

    假设当前存在docker镜像mysql:latest,将该镜像上传至本地,然后将该镜像推送至本地仓库(假设仓库地址为192.168.100.100:5000),从私有仓库中拉取mariadb:v10.3.18镜像。运行mysql镜像,要求将内部3306端口映射到外部的13306端口,提供交互接口,后台运行,容器名为xmysql。最后将mysql镜像和创建的容器删除。依次提交操作命令。

    1、首先要确保docker环境存在
    image.png
    2、开始解题

    安装完docker环境后,本地镜像还是空的


    image.png

    所以要拉取mysql镜像

    docker pull mysql
    

    下载好后查看是否下载成功

    docker images
    
    image.png

    save指定镜像保存为tar归档文件
    -o 输出到的文件

    docker save -o mysql.tar mysql:latest
    

    导入镜像到本地

    docker load -i mysql.tar
    
    image.png

    docker默认镜像仓库是dockerhub,所以mysql:latest相当于docker.io/mysql:latest,因此,想要将镜像推送到私服仓库中,需要修改镜像标签。

    docker tag mysql:latest localhost:5000/mysql:latest
    
    docker push localhost:5000/mysql:latest
    
    image.png

    题目要求仓库地址为192.168.100.100:5000,所以需要修改ip地址为192.168.100.100,我暂时用localhost代替

    从私有仓库中拉取mariadb:v10.3.18镜像

    docker pull mariadb:10.3.18
    

    运行mysql镜像,要求将内部3306端口映射到外部的13306端口,提供交互接口,后台运行,容器名为xmysql

    docker run -itd --name xmysql mysql  -p 13306:3306 /bin/bash
    
    image.png

    最后将mysql镜像和创建的容器删除

    docker rmi mysql:latest
    docker rm -f xmysql
    
    image.png

    Dockerfile编写

    使用xserver1节点,新建httpd目录,然后编写Dockerfile文件,要求如下:1)使用centos:latest镜像作为基础镜像;2)作者为xiandian;3)Dockerfile要求删除镜像的yum源,使用当前系统的local.repo源文件;4)安装http服务;5)暴露80端口。编写完毕后,构建的镜像名字叫httpd:v1.0的镜像。完成后将Dockerfile文件和镜像列表信息以文本形式提交到答题框。

    新建目录
    mkdir httpd
    cd httpd
    编写文件
    vi Dockerfile
    FROM centos:latest
    MAINTAINER xiandian
    RUN rm -rf /etc/yum.repos.d/*
    ADD local.repo /etc/yum.repos.d/
    RUN yum clean all
    RUN /bin/sh -c yum -y install httpd
    EXPOSE 80
    修改DNS客户机配置文件
    vi /etc/resolv.conf
    添加nameserver 8.8.8.8
    cp /etc/yum.repos.d/local.repo /root/httpd/
    创建镜像
    docker build -t httpd:v1.0 .

    image.png
    docker images
    image.png

    Nova题目:

    使用VMWare软件启动提供的opensatckallinone镜像,自行检查openstack中各服务的状态,若有问题自行排查。使用nova相关命令,查询nova所有的监控列表,并查看ID为1的监控主机的详细信息,将操作命令和返回结果以文本形式提交到答题框。

    环境打开后,先启动openstack

    openstack-service restart
    source /etc/keystone/admin-openrc.sh
    
    image.png

    openstack执行发现nova list报错,说明是keystone没有启动
    启动后成功

    查询nova所有的监控列表
    nova hypervisor-list

    image.png

    查看ID为1监控主机的详细信息
    nova hypervisor-show controller

    image.png

    Cinder题目:

    使用VMWare软件启动提供的opensatckallinone镜像,自行检查openstack中各服务的状态,若有问题自行排查。使用Cinder服务,创建名为“ lvm”的卷类型,然后创建一块带“lvm” 标识的云硬盘,名称为 BlockVloume,大小为 2G,查询该云硬盘详细信息。完成后,将cinder show BlockVloume命令的返回结果以文本形式提交到答题框。

    创建名为“lvm”的卷类型
    cinder type-create lvm

    image.png

    创建一块带“lvm”标识的云硬盘,名称为BlockVloume,大小为 2G
    cinder create --name BlockVloume --volume-type lvm 2

    image.png

    使用cinder show BlockVloume查看创建的云硬盘的具体信息
    cinder show BlockVloume

    image.png

    Swift题目:

    使用VMWare软件启动提供的opensatckallinone镜像,自行检查openstack中各服务的状态,若有问题自行排查。使用swift相关命令,创建一个名叫examcontainer的容器,然后往这个容器中上传一个test.txt的文件(文件可以自行创建),上传完毕后,使用命令查看容器,将操作命令和返回结果以文本形式提交到答题框。

    创建一个名叫examcontainer的容器
    swift post examcontainer

    往这个容器中上传一个test.txt的文件(文件可以自行创建)
    swift upload examcontainer test.txt

    查看容器
    openstack container list
    openstack object list examcontainer
    查看容器下的文件

    image.png

    Lnmp 题目:

    使用xserver1节点,安装单节点lnmp环境。安装lnmp环境需要用到的YUM源为CentOS-7-x86_64-DVD-1511.iso和lnmp目录(均在/root目录下)。安装并配置完lnmp环境后。依次查询数据库、nginx、php服务的状态,并使用netstat -ntpl命令查看端口开放情况。最后依次将查询服务状态的返回结果,和查看端口开放情况的返回结果以文本形式提交到答题框。

    配置yum源
    vi /etc/yum.repos.d/lnmp.repo

    image.png image.png

    安装nginx和php
    yum install nginx -y
    yum -y install php* --disablerepo=centos --enablerepo=lnmp
    //指定安装lnmp库的php软件包,disablerepo选项的作用是不使用特定仓库,enablerepo选项的作用是使用特定仓库

    image.png

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

    image.png
    image.png

    yum install mariadb-server -y

    image.png

    netstat -ntpl

    image.png

    WordPress题目:

    使用xserver1节点,基于lnmp环境,部署WordPress应用(WordPress源码包在/root目录下)。应用部署完毕后,设置WordPress的站点标题为自己的姓名(例:名字叫张三,则设置站点标题为张三的BLOG),设置完毕后登录WordPresss首页。最后将命令curl ip(ip为wordpress的首页ip)的返回结果以文本形式提交到答题框。

    配置Wordpress数据库
    (1)登陆mariadb,创建wordpress数据库
    (2)赋予root用户本地和远程访问数据库的所有权限(with grant option:root用户可以将自己拥有的权限授权给别人)

     grant all privileges on *.* to root@localhost identified by '000000' with grant option;
     grant all privileges on *.* to root@'%' identified by '000000' with grant option;
    
    image.png

    解压当前目录下的wp包
    yum install unzip -y
    unzip wordpress-4.7.3-zh_CN.zip

    删除/usr/share/nginx/html目录下的所有文件和目录,并将wordpress目录下的所有文件和目录复制到/usr/share/nginx/html目录下

    rm -rf /usr/share/nginx/html/*
    cp -rf wordpress/* /usr/share/nginx/html/
     ls /usr/share/nginx/html/
    
    image.png
    赋予文件和目录权限
    chmod 777 /usr/share/nginx/html/*

    配置php连接数据库文件wp-config.php,复制模板文件wp-config-sample.php,将其改名wp-config.php,并编辑该文件
    cd /usr/share/nginx/html/
    cp wp-config-sample.php wp-config.php

    image.png image.png

    配置nginx支持php,修改nginx配置文件/etc/nginx/conf.d/default.conf
    vi /etc/nginx/conf.d/default.conf

    image.png
    添加以下内容,配置nginx支持php文件的解析 image.png
    重启nginx systemctl restart nginx
    在浏览器的地址栏输入http://192.168.100.11访问wordpress安装主页,输入相应信息进行安装
    image.png
    image.png

    Linux存储LVM管理题目:

    使用xserver1虚拟机,使用VMWare软件自行添加一块大小为20G的硬盘,使用fdisk命令对该硬盘进形分区,要求分出三个大小为5G的分区。使用这三个分区,创建名xcloudvg的卷组。然后创建名xcloudlv的逻辑卷,大小为12G,再创建完之后,使用命令将逻辑卷大小缩小2G,然后查看逻辑卷信息。将上述所有操作命令和返回结果以文本形式提交到答题框。

    添加一块硬盘

    image.png

    分出三个大小为5G的分区
    fdisk /dev/sdb

    image.png
    image.png
    创建物理卷
    pvcreate /dev/sdb[1-3]
    image.png

    使用刚才创建好的3个物理卷,创建名为 xcloudvg的卷组
    vgcreate xcloudvg /dev/sdb[1-3]

    image.png

    创建名xcloudlv的逻辑卷,大小为12G
    lvcreate -L +12G -n xcloudlv xcloudvg
    `

    image.png

    使用 ext4 文件系统格式化逻辑卷xcloudlv
    mkfs.ext4 /dev/mapper/xcloudvg-xcloudlv
    mount /dev/mapper/xcloudvg-xcloudlv /mnt
    把逻辑卷 xcloudlv挂载到/mnt 下并验证

    image.png
    image.png

    将逻辑卷大小缩小2G,然后查看逻辑卷信息
    lvreduce -L -2G /dev/mapper/xcloudvg-xcloudlv

    image.png
    [root@xserver1 ~]# lvs
      LV       VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root     centos   -wi-ao---- 35.59g                                                    
      swap     centos   -wi-ao----  3.88g                                                    
      xcloudlv xcloudvg -wi-ao---- 10.00g      
    
    image.png

    主从数据库管理题目:

    在xserver1、xserver2上安装mariadb数据库,并配置为主从数据库(xserver1为主节点、xserver2为从节点),实现两个数据库的主从同步。配置完毕后,请在xserver2上的数据库中执行“show slave status \G”命令查询从节点复制状态,将查询到的结果以文本形式提交到答题框。

    在xserver1、xserver2上安装mariadb数据库,并设置开机自启动
    yum install mariadb mariadb-server -y
    systemctl start mariadb && systemctl enable mariadb

    image.png
    image.png

    在xserver1上配置主数据库

    [root@xserver1 ~]# mysql_secure_installation
    /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    Set root password? [Y/n] y
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] 
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] n    //输入n,允许root账户远程登陆
     ... skipping.
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] 
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] 
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    

    修改数据库配置文件/etc/my.cnf

    vim /etc/my.cnf
    log_bin=mysql-bin //启动日志记录功能
    binlog_ignore_db=mysql   //不同步mysql系统数据库
    server_id=11  //数据库集群唯一ID,一般取服务器IP地址的最后一段
    
    image.png
    重启数据库服务,登陆数据库进行配置
    为在任意IP上登陆访问数据库的root用户授予所有权限
    创建一个用于连接从节点的用户user(该用户只能在从节点登陆访问主节点数据库),密码为000000,并授予其从节点数据库同步主节点数据库的权限
    image.png
    [root@xserver1 ~]# systemctl restart mariadb
    [root@xserver1 ~]# mysql -uroot -p000000
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB-log MariaDB Server
    
    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '000000';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> grant replication slave on *.* to 'user'@'xserver2' ident
    ified by '000000';
    Query OK, 0 rows affected (0.00 sec)
    

    同xserver1一样,配置从数据库xserver2
    mysql_secure_installation
    vi /etc/my.cnf
    log_bin=mysql-bin
    binlog_ignore_db=mysql
    server_id=12

    image.png

    systemctl restart mariadb

    配置从节点连接主节点的连接参数。 master_host 为主节点主机名xserver1,master_user为主节点数据库中创建的用户user,master_password为user的密码
    开启从节点服务
    验证主从数据库同步是否配置正确(Slave_IO_Running和Slave_SQL_Running都为Yes)

    [root@xserver2 ~]# mysql -uroot -p000000
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB-log MariaDB Server
    
    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> change master to master_host='xserver1',master_user='user',master_password='000000';
    Query OK, 0 rows affected (0.02 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: xserver1
                      Master_User: user
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000001
              Read_Master_Log_Pos: 531
                   Relay_Log_File: mariadb-relay-bin.000002
                    Relay_Log_Pos: 815
            Relay_Master_Log_File: mysql-bin.000001
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                  Replicate_Do_DB: 
              Replicate_Ignore_DB: 
               Replicate_Do_Table: 
           Replicate_Ignore_Table: 
          Replicate_Wild_Do_Table: 
      Replicate_Wild_Ignore_Table: 
                       Last_Errno: 0
                       Last_Error: 
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 531
                  Relay_Log_Space: 1111
                  Until_Condition: None
                   Until_Log_File: 
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File: 
               Master_SSL_CA_Path: 
                  Master_SSL_Cert: 
                Master_SSL_Cipher: 
                   Master_SSL_Key: 
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error: 
                   Last_SQL_Errno: 0
                   Last_SQL_Error: 
      Replicate_Ignore_Server_Ids: 
                 Master_Server_Id: 11
    1 row in set (0.00 sec)
    
    ERROR: No query specified
    

    相关文章

      网友评论

          本文标题:1+X云计算平台运维与开发认证

          本文链接:https://www.haomeiwen.com/subject/xjmqiktx.html