0%

KVM环境下制作CentOS7 qcow2格式镜像

virt-install是一个命令行工具,它能够为KVM、Xen或其它支持libvirt API的hypervisor创建虚拟机并完成GuestOS安装;此外,它能够基于串行控制台、VNC或SDL支持文本或图形安装界面。安装过程可以使用本地的安装介质如CDROM,也可以通过网络方式如NFS、HTTP或FTP服务实现。对于通过网络安装的方式,virt-install可以自动加载必要的文件以启动安装过程而无须额外提供引导工具。当然,virt-install也支持PXE方式的安装过程,也能够直接使用现有的磁盘映像直接启动安装过程。

阅读全文 »

Linux–Centos7 升级内核为最新长期维护版 4.4

elrepo 官网

1
2
http://elrepo.org
https://elrepo.org/tiki/tiki-index.php

安装 ELRepo源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#  查看内核
[root@localhost ~]# uname -r

# 安装 Yum密钥
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

# 安装对应的Yum源
# To install ELRepo for CentOS8
yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

# To install ELRepo for CentOS7
yum -y install yum-plugin-fastestmirror yum-utils
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

# To install ELRepo for CentO6
yum -y install yum-plugin-fastestmirror yum-utils
yum install https://www.elrepo.org/elrepo-release-6.el6.elrepo.noarch.rpm

Centos7 安装内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# list available 查看kernel的版本
yum --disablerepo="*" --enablerepo="elrepo-kernel"

# 安装秘钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

# 安装最新长期维护版kernel
yum -y --enablerepo=elrepo-kernel install kernel-lt

# 设置为默认为最新版本kernel
grub2-set-default 0
reboot


# 重启之后即可选择对应的内核版本
uname -r

# 查看当前系统所有的内核版本选择
awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (3.10.0-1127.13.1.el7.x86_64) 7 (Core)
1 : CentOS Linux (4.4.228-2.el7.elrepo.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-fc3fb3f757784457a95f1652cd0c7f93) 7 (Core)

# 设置默认启动的内核版本
grub2-set-default "CentOS Linux (4.4.228-2.el7.elrepo.x86_64) 7 (Core)"
# 或者执行如下步骤,上面和这个步骤是同样的效果
grub2-set-default 1 (第二种方式,输入对应的内核编号)

# 确认是否执行成功
grub2-editenv list
saved_entry=CentOS Linux (4.4.228-2.el7.elrepo.x86_64) 7 (Core)

网络拓扑

k8s集群的pod网段为179.10.0.0/16,svc的网段为179.20.0.0/16
办公网为18.16.0.0/16
k8s nat节点ip为18.16.200.149/32 宿主机ip段为18.16.200.0/24

办公网于k8s内网互通

目前线下环境迁移到k8s集群,运行在k8s内的微服务应用注册到nacos,注册的为本地办公网ip+port,但开发在本地办公电脑上启动服务,注册到nacos,注册信息是办公网络的IP与端口,因为办公网络与k8s集群内部网络相对隔离,导致服务之间调用异常。

添加路由中转机

选定k8s内的一台node节点专门作为路由,配置低一点没有关系, 禁止调度就行, test-worker-4作为本次的NAT机器

1
2
3
4
5
6
7
8
9
[root@test-master-1 ~]# kubectl get nodes 
NAME STATUS ROLES AGE VERSION
test-master-1 Ready etcd,master,worker 108d v1.18.8
test-master-2 Ready etcd,master,worker 108d v1.18.8
test-master-3 Ready etcd,master,worker 108d v1.18.8
test-worker-1 Ready worker 73d v1.18.8
test-worker-2 Ready worker 73d v1.18.8
test-worker-3 Ready worker 73d v1.18.8
test-worker-4 Ready,SchedulingDisabled worker 11d v1.18.8

开启nat节点的路由转发功能

test-worker-4节点执行

1
2
echo "net.ipv4.ip_forward = 1"  >> /etc/sysctl.conf
sysctl -p

设置转发规则

test-worker-4节点执行

1
2
iptables -t nat -A POSTROUTING -s 18.16.0.0/16 -d 179.20.0.0/16 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 18.16.0.0/16 -d 179.10.0.0/16 -j MASQUERADE

本地网络添加静态路由

本地的网络尽量是私网ip,在出口的路由骑上添加静态路由, 是在不知道的话就问下网络的同事

1
2
ip route 179.20.0.0 255.255.0.0 18.16.200.149
ip route 179.10.0.0 255.255.0.0 18.16.200.149

html–语法结构

介绍

超文本标记语言(Hyper Text Markup Language),HTML 不是一种编程语言,而是一种 指超文本标签语言,是网页制作所必备的.

阅读全文 »

HTML–列表标签

无序列表标签(ul标签)

==无序列表是一个项目的列表,使用粗体圆点(典型的小黑圆圈)开头。==

阅读全文 »

HTML–常用标签

HTML元素(标签)分类

  • 块元素(行元素)
  • 内联元素(行内元素)

    HTML–块元素(行元素)

    特点: 单个块元素在浏览器中默认独占一行 块元素可以设置宽高等属性.

阅读全文 »

HTML–表单提交

==表单用于搜集不同类型的用户输入(用户输入的数据),然后可以把用户数据提交到web服务器==

表单的基本标签

  • <form> 标签 表示表单标签,定义整体的表单区域

    • action属性 设置表单数据提交地址
    • method属性 设置表单提交的方式,一般有“GET”方式和“POST”方式, 不区分大小写
阅读全文 »

HTML– 表单标签

==表单提交信息时候必须指定提交的参数名即设置标签中需要设置name属性==

  • <form>标签 表示表单标签,定义整体的表单区域
  • <label>标签 表示表单元素的文字标注标签,定义文字标注
  • <input>标签 表示表单元素的用户输入标签,定义不同类型的用户输入数据方式
  • type属性
    • type="text" 定义单行文本输入框
    • type="password" 定义密码输入框
    • type="radio" 定义单选框
    • type="checkbox" 定义复选框
    • type="file" 定义上传文件
    • type="submit" 定义提交按钮
    • type="reset" 定义重置按钮
    • type="button" 定义一个普通按钮
    • <textarea>标签 表示表单元素的多行文本输入框标签 定义多行文本输入框
  • <select>标签 表示表单元素的下拉列表标签 定义下拉列表
  • <option>标签 与<select>标签配合,定义下拉列表中的选项
阅读全文 »

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

列出本地镜像列表

REPOSITORY:表示镜像的仓库源
TAG:镜像的标签
IMAGE ID:镜像ID
CREATED:镜像创建时间
SIZE:镜像大小

1
2
3
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4bb46517cac3 2 weeks ago 133MB

同一仓库源可以有多个 TAG,代表这个仓库源的不同个版本,使用 REPOSITORY:TAG 来定义不同的镜像。

1
2
3
4
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 6f715d38cfe0 2 weeks ago 22.1MB
nginx latest 4bb46517cac3 2 weeks ago 133MB

获取新的镜像

当我们在本地主机上使用一个不存在的镜像时 Docker 就会自动下载这个镜像。如果我们想预先下载这个镜像,我们可以使用 docker pull 命令来下载它。

1
2
3
4
5
6
7
8
9
10
[root@centos7 ~]# docker pull nginx:alpine
alpine: Pulling from library/nginx
df20fa9351a1: Pull complete
3db268b1fe8f: Pull complete
f682f0660e7a: Pull complete
7eb0e8838bc0: Pull complete
e8bf1226cc17: Pull complete
Digest: sha256:a97eb9ecc708c8aa715ccfb5e9338f5456e4b65575daf304f108301f3b497314
Status: Downloaded newer image for nginx:alpine
docker.io/library/nginx:alpine

查找镜像

我们可以从 Docker Hub 网站来搜索镜像,Docker Hub 网址为: https://hub.docker.com/ 我们也可以使用 docker search 命令来搜索镜像。

NAME: 镜像仓库源的名称
DESCRIPTION: 镜像的描述
OFFICIAL: 是否 docker 官方发布
stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
AUTOMATED: 自动构建。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@centos7 ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13677 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1867 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 782 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 127
bitnami/nginx Bitnami nginx Docker Image 89 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 88 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 82
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 75 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 59 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 53 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 41
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 32 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]

删除镜像

镜像删除使用 docker rmi 命令

1
2
3
4
5
[root@centos7 ~]# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63

更新镜像

新镜像之前,我们需要使用镜像来创建一个容器。

1
2
3
4
5
6
7
[root@centos7 ~]# docker run -itd centos:centos7.8.2003 /bin/bash
4d95f2fd7cfb5ca53fd98eabfe4745815a9530ff7f593957d3b10b4b110318e3
[root@centos7 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d95f2fd7cfb centos:centos7.8.2003 "/bin/bash" 8 seconds ago Up 7 seconds angry_cori
[root@centos7 ~]# docker exec -it 4d95f2fd7cfb bash
[root@4d95f2fd7cfb /]# yum update -y

各个参数说明:
-m: 提交的描述信息
-a: 指定镜像作者
e218edb10161:容器 ID(docker ps获取)
runoob/ubuntu:v2: 指定要创建的目标镜像名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 通过命令docker commit 来提交容器副本 创建新的镜像
[root@centos7 ~]# docker commit -m="yum update" -a="user" 4d95f2fd7cfb user/centos:v2
sha256:8aee4e075a0d907c757bcc3946165447607bfe8d726888fad090fdc9ddda0718

# 查看是否生产新的镜像
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
user/centos v2 8aee4e075a0d 12 seconds ago 203MB

# 启动新的镜像容器
[root@centos7 ~]# docker run -itd user/centos:v2 /bin/bash
799efd51587574113896b3c3218b08664b864c155490ca2728e65452a9f44901

# 查看启动的容器
[root@centos7 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
799efd515875 user/centos:v2 "/bin/bash" 4 seconds ago Up 3 seconds elastic_euclid
4d95f2fd7cfb centos:centos7.8.2003 "/bin/bash" 5 minutes ago Up 5 minutes angry_cori

# 停止旧的容器
[root@centos7 ~]# docker stop 4d95f2fd7cfb
4d95f2fd7cfb
# 删除旧的容器
[root@centos7 ~]# docker rm 4d95f2fd7cfb
4d95f2fd7cfb
# 查看剩余容器状态
[root@centos7 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
799efd515875 user/centos:v2 "/bin/bash" 3 minutes ago Up 3 minutes elastic_euclid

设置镜像标签

使用 docker tag 命令,为镜像添加一个新的标签。

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看镜像
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 6f715d38cfe0 2 weeks ago 22.1MB

# 为镜像搭上tag号
[root@centos7 ~]# docker tag 6f715d38cfe0 nginx:new

# 确认最终状态,生成两个镜像,可以理解为复制镜像
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 6f715d38cfe0 2 weeks ago 22.1MB
nginx new 6f715d38cfe0 2 weeks ago 22.1MB