1+X 初级实验

1+X 初级实验

Acha
2021-07-04 / 0 评论 / 148 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年07月04日,已超过1025天没有更新,若内容或图片失效,请留言反馈。

私有云实训

一、本地 YUM 源管理

使用 VMWare 软件启动提供的 xserver1 虚拟机(配置虚拟机 xserver1 的 IP 为 `192.168.100.11`,主机名为 xserver1)
在虚拟机的/root 目录下,存在一个`CentOS-7-x86_64-DVD-1511.iso` 的镜像文件,使用这个镜像文件配置本地 yum 源,
要求将这个镜像文件挂载在`/opt/centos` 目录,请问如何配置自己的 local.repo 文件,使得可以使用该镜像中的软件包,安装软件。
请将 local.repo 文件的内容和执行 yum repolist 的返回结果(简要)写到下方。
echo "TYPE=Ethernet
BOOTPROTO=static
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.100.11
GATEWAY=192.168.100.1
PREFIX=24" > /etc/sysconfig/network-scripts/ifcfg-eno16777736

[root@xserver1 ~]# hostnamectl set-hostname xserver1
[root@xserver1 ~]# bash

[root@xserver1 ~]#cd
[root@xserver1 ~]# mkdir /opt/centos
[root@xserver1 ~]# mount -o loop CentOS-7-x86_64-DVD-1511.iso /opt/centos/

[root@xserver1 ~]# mkdir /etc/yum.repos.d/bak
[root@xserver1 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/


echo "[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1" > /etc/yum.repos.d/local.repo 

[root@xserver1 ~]# yum clean all
[root@xserver1 ~]# yum repolist
Loaded plugins: fastestmirror
centos                                                                 | 3.6 kB  00:00:00     
(1/2): centos/group_gz                                                 | 155 kB  00:00:00     
(2/2): centos/primary_db                                               | 2.8 MB  00:00:00     
Determining fastest mirrors
repo id                                     repo name                                   status
centos                                      centos                                      3,723
repolist: 3,723


二、FTP 安装使用

使用 xserver1 虚拟机,安装 `ftp 服务`,并配置 ftp 的共享目录为/opt。
使用VMWare 软件继续启动提供的 xserver2 虚拟机(配置虚拟机 xserver2 的 IP 为`192.168.100.12`,主机名为xserver2),
并创建该虚拟机的 yum 源文件 `ftp.repo` 使用xserver1 的ftp 源(配置文件中的FTP 地址使用主机名)。
配置完成后,将xserver1节点执行 netstat -ntpl 命令(netstat 命令若不能用,则自行安装 net-tools 工具)的返回结果(简要)和将 xserver2 节点的 ftp.repo 文件内容写到下方。
[root@xserver1 ~]# yum instal vsftpd -y
[root@xserver1 ~]# echo anon_root=/opt/ >> /etc/vsftpd/vsftpd.conf 
[root@xserver1 ~]# systemctl start vsftpd && systemctl enable vsftpd

echo "TYPE=Ethernet
BOOTPROTO=static
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.100.12
GATEWAY=192.168.100.1
PREFIX=24" > /etc/sysconfig/network-scripts/ifcfg-eno16777736

[root@localhost ~]# hostnamectl set-hostname xserver2
[root@localhost ~]# bash


echo "[centos]
name=centos
baseurl=ftp://192.168.100.11/centos
gpgcheck=0
enabled=1" > /etc/yum.repos.d/ftp.repo

[root@xserver2 ~]# setenforce 0
[root@xserver2 ~]# systemctl stop firewalld && systemctl disable firewalld

[root@xserver1 ~]# setenforce 0
[root@xserver1 ~]# systemctl stop firewalld && systemctl disable firewalld

[root@xserver2 ~]# yum clean all
[root@xserver2 ~]# yum repolist
Loaded plugins: fastestmirror
centos                                                                 | 3.6 kB  00:00:00     
(1/2): centos/group_gz                                                 | 155 kB  00:00:00     
(2/2): centos/primary_db                                               | 2.8 MB  00:00:00     
Determining fastest mirrors
repo id                                     repo name                                   status
centos                                      centos                                      3,723
repolist: 3,723

[root@xserver1 ~]# yum install -y net-tools
[root@xserver1 ~]# netstat -ntpl
tcp6       0      0 :::21                   :::*                    LISTEN      3280/vsftpd 


三、NFS 服务管理

使用 xserver1、xserver2 虚拟机,安装 NFS 服务所需要的软件包,将 xserver1 节点中的/mnt/share 目录使用 NFS 服务共享出来(目录不存在请自行创建,要求可访问共享目录的网段为 192.168.100.0/24),
接着在 xserver2 节点上,将 xserver1中共享的文件挂载到/mnt 目录下。
操作完毕后,依次将 xserver1 节点上执行showmount -e ip 命令和 xserver2 节点上执行 df -h 命令的返回结果(简要)写到下方
[root@xserver1 ~]# yum -y install nfs-utils rpcbind
[root@xserver2 ~]# yum -y install nfs-utils rpcbind

echo "/mnt/share 192.168.100.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)" > /etc/exports

[root@xserver1 ~]# exportfs -r

[root@xserver1 ~]# systemctl start rpcbind && systemctl enable rpcbind
[root@xserver1 ~]# systemctl start nfs-server && systemctl enable nfs-server

[root@xserver1 ~]# showmount -e 192.168.100.11
Export list for 192.168.100.11:
/mnt/share 192.168.100.0/24

[root@xserver2 ~]# setenforce 0
[root@xserver2 ~]# systemctl stop firewalld && systemctl disable firewalld

[root@xserver1 ~]# setenforce 0
[root@xserver1 ~]# systemctl stop firewalld && systemctl disable firewalld

[root@xserver2 ~]# mount -t nfs 192.168.100.11:/mnt/share /mnt
[root@xserver2 ~]# df -h
192.168.100.11:/mnt/share   36G  7.6G   29G  22% /mnt


四、主从数据库管理

在 xserver1、xserver2 上安装 mariadb 数据库,
并配置为主从数据库(xserver1 为主节点、xserver2 为从节点),实现两个数据库的主从同步。
配置完毕后,请在 xserver2 上的数据库中执行“show slave status \G”命令查询从节点复制状态,将查询到的结果(简要)写到下方。
# xserver1 & xserver2 都执行
echo "192.168.100.11 mysql1
192.168.100.12 mysql2" >> /etc/hosts

[root@xserver1 ~]# yum install -y mariadb mariadb-server
[root@xserver1 ~]# systemctl start mariadb && systemctl enable mariadb

[root@xserver2 ~]# yum install -y mariadb mariadb-server
[root@xserver2 ~]# systemctl start mariadb && systemctl enable mariadb

# xserver1 & xserver2 都执行
[root@xserver1 ~]# mysql_secure_installation 
Disallow root login remotely? [Y/n] n
其他为 yes ;密码设置为 000000

# 为 xserver1/etc/my.cnf 中的[mysqld]增添如下内容
log_bin=mysql-bin
binlog_ignore_db=mysql
server_id=11

# xserver1
MariaDB [(none)]> grant all privileges  on *.* to root@'%' identified by "000000";
MariaDB [(none)]>  grant replication slave on *.* to 'user'@'mysql2' identified by '000000';

# 为 xserver2 /etc/my.cnf 中的[mysqld]增添如下内容
log_bin=mysql-bin
binlog_ignore_db=mysql
server_id=12

# xserver2
MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
    `Slave_IO_Running: Yes`
    `Slave_SQL_Running: Yes`

## 验证数据同步
# xserver1
MariaDB [(none)]> create database test;
MariaDB [(none)]> use test;
MariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255));
MariaDB [test]> insert into company values(1,"alibaba","china");
MariaDB [test]>  select * from company;

# xserver2
MariaDB [(none)]> show databases;
MariaDB [(none)]> use test;
MariaDB [test]> show tables;
MariaDB [test]> select * from company;
+----+---------+-------+
| id | name    | addr  |
+----+---------+-------+
|  1 | alibaba | china |
+----+---------+-------+
1 row in set (0.01 sec)


五、LNMP 环境部署

使用 xserver1 节点,安装单节点 lnmp 环境。
安装 lnmp 环境需要用到的 YUM 源为 CentOS-7-x86_64-DVD-1511.iso 和 lnmp 目录(均在/root 目录下)。
安装并配置完 lnmp 环境后。依次查询数据库、nginx、php 服务的状态,并使用 netstat -ntpl 命令查看端口开放情况。
最后依次将查询服务状态的返回结果(简要),和查看端口开放情况的返回结果(简要)写到下方。
echo "[lnmp]
name=centos
baseurl=file:///root/lnmp
gpgcheck=0
enabled=1" >> /etc/yum.repos.d/local.repo 
[root@xserver1 ~]# yum clean all
[root@xserver1 ~]# yum repolist

[root@xserver1 ~]# yum install -y nginx
echo "server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}" > /etc/nginx/conf.d/default.conf 

[root@xserver1 ~]# mysql -uroot -p000000
MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '000000' with grant option;
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '000000' with grant option;
MariaDB [(none)]> create database wordpress;

[root@xserver1 ~]# yum install -y php-fpm php-mysql  
[root@xserver1 ~]# vi /etc/php-fpm.d/www.conf #修改下两行
user = nginx
group = nginx

[root@xserver1 ~]# systemctl restart nginx php-fpm

[root@xserver1 ~]# yum install net-tools
[root@xserver1 ~]# netstat -ntpl


六、部署 WordPress 应用

使用 xserver1 节点,基于 lnmp 环境,部署 WordPress 应用(WordPress 源码包在/root 目录下)。
应用部署完毕后,设置 WordPress 的站点标题为自己的姓名( 例: 名字叫张三, 则设置站点标题为张三的 BLOG),
设置完毕后登录WordPresss 首页。最后将命令 curl ip(ip 为 wordpress 的首页 ip)的返回结果(简要)写到下方。
[root@xserver1 ~]# yum install -y unzip
[root@xserver1 ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@xserver1 ~]# cp -rfv wordpress/* /usr/share/nginx/html/

echo "<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '000000');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
define('AUTH_KEY',         '<*sWiXc.1x HhNW`r>o?o7b,l`PoiY`_Ji/YD>o4Cc}460|Bew2-Ba)X/LZmsbvS');
define('SECURE_AUTH_KEY',  '`v$-3/Gk`/&yRoSBoVrc+%*=WGmQc;R0!KxY}HM61V9Pcyz&= Xw986qi4/,W*4j');
define('LOGGED_IN_KEY',    '/%Iuho!m&L#d1J=S:*6C~4>7@72$ZcGJcE=bW)jM0wl^|ZO2YIX5OllUMG*Wr1?W');
define('NONCE_KEY',        'K!KOU7%&2K=x^o7p7VG>/ast51N>ry_Rcl^)c}WOong&~cuh>p 8twe{B]Z[7Q)]');
define('AUTH_SALT',        '#ho(+-ICZ>@fy>^;U],e!9Y<sbGV$|LLo)F[Lkveh]~s|Q9KQ)g#cCrgw2fGviP,');
define('SECURE_AUTH_SALT', 'l~@~( d2k-Gh?VczpK(_4}8#;BEX0RFncorH#qf1{r<-1$DpM#@bcBKjv)R4Q}_9');
define('LOGGED_IN_SALT',   '1q.8W-yy)tNt^$+pSScX>o*UDX!T?>I%{_RP~<*heM|A6j[6OfL4]w 2:SI)cuud');
define('NONCE_SALT',       '6kt&5<?n%]:z4[%i6,jL-l@i#!$v8x-[JXERj+*dja{]))<e`aE!qwzy>?kw$IKI');
$table_prefix  = 'wp_';
define('WP_DEBUG', false);
define('WP_ZH_CN_ICP_NUM', true);
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
" > /usr/share/nginx/html/wp-config.php

[root@xserver1 ~]# systemctl restart mariadb nginx php-fpm

[root@xserver1 ~]# netstat -lntp
[root@xserver1 ~]# curl 192.168.100.11


七、Linux 存储 LVM 管理

使用 xserver1 虚拟机,使用 VMWare 软件自行添加一块大小为 20G 的硬盘, 使用 fdisk 命令对该硬盘进形分区,
要求分出两个大小为 5G 的分区。使用两个分区,创建名 xcloudvg 的卷组,
然后再创建一个 5G 的分区,将 xcloudvg 扩容至 15G,最后执行 vgdisplay 命令查看卷组信息。
将上述所有操作命令和返回结果(简要)写到下方。
[root@controller ~]# lsblk
[root@controller ~]# fdisk /dev/sdb
# 创建分区 3个分区
[root@controller ~]# lsblk
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2
[root@localhost ~]# vgcreate xcloudvg /dev/sdb[1-2]
[root@localhost ~]# vgextend xcloudvg /dev/sdb3


八、OpenStack Keystone 管理

使用 VMWare 软件启动提供的 opensatckallinone 镜像,自行检查 openstack 中各服务的状态,若有问题自行排查。
在 keystone 中创建用户 testuser,密码为123456,创建好之后,查看 testuser 的详细信息。
将上述所有操作命令及返回结果(简要)写到下方。
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# openstack user create --password 123456 --domain xiandian usertest
[root@controller ~]# openstack user show usertest
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | 9321f21a94ef4f85993e92a228892418 |
| enabled   | True                             |
| id        | b9b24fd835344500837cb2cbfb79d90d |
| name      | usertest                         |
+-----------+----------------------------------+


九、OpenStack Glance 管理

使用 VMWare 软件启动提供的 opensatckallinone 镜像,自行检查 openstack 中各服务的状态,若有问题自行排查。
在 xserver1 节点的/root 目录下存在一个cirros-0.3.4-x86_64-disk.img 镜像; 
使用 glance 命令将镜像上传, 并命名为mycirros,
最后将glance image-show id 命令的返回结果(简要)写到下方。
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# glance image-create --name "mycirros" --disk-format qcow2 --container-format bare --progress < cirros-0.3.2-x86_64-disk.img 
[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | 64d7c1cd2b6f60c92c14662941cb7913     |
| container_format | bare                                 |
| created_at       | 2021-06-30T19:45:27Z                 |
| disk_format      | qcow2                                |
| id               | ae634816-62f7-4bcb-8b89-04166478d834 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | mycirros                             |
| owner            | f9ff39ba9daa4e5a8fee1fc50e2d2b34     |
| protected        | False                                |
| size             | 13167616                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2021-06-30T19:45:27Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+
[root@controller ~]# glance image-show mycirros
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | 64d7c1cd2b6f60c92c14662941cb7913     |
| container_format | bare                                 |
| created_at       | 2021-06-30T19:45:27Z                 |
| disk_format      | qcow2                                |
| id               | ae634816-62f7-4bcb-8b89-04166478d834 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | mycirros                             |
| owner            | f9ff39ba9daa4e5a8fee1fc50e2d2b34     |
| protected        | False                                |
| size             | 13167616                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2021-06-30T19:45:27Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+


十、Docker 安装

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

echo "[kubernetes]
name=kubernetes
baseurl=file:///opt/docker/Docker
gpgcheck=0
enabled=1
" >> /etc/yum.repos.d/local.repo 

[root@xserver1 ~]# yum clean all
[root@xserver1 ~]# yum repolist
[root@xserver1 ~]# yum upgrade -y
[root@xserver1 ~]# uname -r
[root@xserver1 ~]# iptables -t filter -F
[root@xserver1 ~]# iptables -t filter -X
[root@xserver1 ~]# iptables -t filter -Z
[root@xserver1 ~]# /usr/sbin/iptables-save
[root@xserver1 ~]# reboot

[root@xserver1 ~]# rm -rf /etc/yum.repos.d/C*
[root@xserver1 ~]# yum clean all
[root@xserver1 ~]# yum repolist

cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

[root@xserver1 ~]# sysctl -p
[root@xserver1 ~]# modprobe br_netfilter
[root@xserver1 ~]# yum install -y yum-utils device-mapper-persistent-data
[root@xserver1 ~]# yum install docker-ce -y
[root@xserver1 ~]# systemctl daemon-reload
[root@xserver1 ~]# systemctl restart docker
[root@xserver1 ~]# systemctl enable docker
[root@xserver1 ~]# docker info

[root@xserver1 ~]# docker load -i /opt/docker/images/registry_latest.tar 
[root@xserver1 opt]# docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry f32a97de94e1


十一、Dockerfile 编写

使用 xserver1 节点,新建目录 centos-jdk,将提供的 jdk-8u141-linux-x64.tar.gz
复制新建的目录,然后编辑 Dockerfile 文件,文件要求如下:
    1.使用 centos:latest 基础镜像;
    2.指定作为为 xiandian;
    3.新建文件夹/usr/local/java 用于存放 jdk 文件;
    4.将 JDK 文件复制到镜像内创建的目录并自动解压;
    5.创建软连接:ln -s /usr/local/java/jdk1.8.0_141 /usr/local/java/jdk; 
    6.设置环境变量如下
        ENV JAVA_HOME /usr/local/java/jdk ENV JRE_HOME ${JAVA_HOME}/jre
        ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH ${JAVA_HOME}/bin:$PATH
编写完毕后,构建名为 centos-jdk 的镜像,构建成功后,查看镜像列表。
最后将 Dockerfile 的内容、构建镜像的操作命令、查看镜像列表的命令和返回的(简要)写到下方。
[root@xserver1 ~]# mkdir /home/centos-jdk
[root@xserver1 ~]# cp /opt/docker/jdk/jdk-8u141-linux-x64.tar.gz /home/centos-jdk
[root@xserver1 centos-jdk]# cat /home/centos-jdk/dockerfile 
FROM centos:latest
MAINTAINER xiandian
WORKDIR /usr/local/java
ADD jdk-8u141-linux-x64.tar.gz /usr/local/java
RUN ln -s /usr/local/java/jdk1.8.0_141 /usr/local/java/jdk
ENV JAVA_HOME /usr/local/java/jdk 
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib 
ENV PATH ${JAVA_HOME}/bin:$PATH

[root@xserver1 ~]# docker build -t centos-jdk /home/centos-jdk
[root@xserver1 ~]# docker run -d -it --rm centos-jdk


十二、swarm集群部署

写出部署swarm集群的主要步骤
1. 主机映射
2. 时间同步
3. 配置Docker API
4. 初始化集群
5. Node节点加入集群
0

评论

博主关闭了当前页面的评论