华为云之HECS云服务器配置docker环境

Posted 江湖有缘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了华为云之HECS云服务器配置docker环境相关的知识,希望对你有一定的参考价值。

华为云之HECS云服务器配置docker环境

一、华为HECS云服务器介绍

云耀云服务器(Hyper Elastic Cloud Server,HECS)是可以快速搭建简单应用的新一代云服务器,具备独立、完整的操作系统和网络功能。提供快速应用部署和简易的管理能力,适用于网站搭建、开发环境等低负载应用场景。具有高性价比、易开通、易搭建、易管理的特点。

二、SSH登录HECS云服务器

三、检查HESC环境

1.检查系统版本

[root@server-01 ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
aaa

2.检查VPC本地IP地址

[root@server-01 ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.150  netmask 255.255.255.0  broadcast 192.168.200.255
        inet6 fe80::f816:3eff:fe26:7b4  prefixlen 64  scopeid 0x20<link>
        ether fa:16:3e:26:07:b4  txqueuelen 1000  (Ethernet)
        RX packets 7806451  bytes 4883098416 (4.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10812338  bytes 5026213960 (4.6 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

四、配置yum仓库

1.备份yum仓库

[root@server-01 yum.repos.d]# pwd
/etc/yum.repos.d
[root@server-01 yum.repos.d]# cp -a ./*   /tmp/

2.配置阿里仓库源


[root@server-01 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  13708      0 --:--:-- --:--:-- --:--:-- 13708

3.配置epel源

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm   #安装 epel 配置包
[root@server-01 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*  # )将 repo 配置中的地址替换为阿里云镜像站地址
[root@server-01 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

4.配置docker源

①安装系统工具

yum install -y yum-utils device-mapper-persistent-data lvm2

②配置docker源

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo

5.生成缓存

[root@server-01 yum.repos.d]# yum makecache 
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                                    48 kB/s | 3.9 kB     00:00    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                                  19 kB/s | 1.5 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                               33 kB/s | 4.3 kB     00:00    
Docker CE Stable - x86_64                                                                                                      22 kB/s | 3.5 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                         25 kB/s | 3.0 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                 47 kB/s | 4.7 kB     00:00    
Metadata cache created.


6.列出yum源

[root@server-01 yum.repos.d]# yum repolist all
repo id                                              repo name                                                                                        status
AppStream                                            CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                 enabled
PowerTools                                           CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com                                                disabled
base                                                 CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                      enabled
centosplus                                           CentOS-8.5.2111 - Plus - mirrors.aliyun.com                                                      disabled
docker-ce-nightly                                    Docker CE Nightly - x86_64                                                                       disabled
docker-ce-nightly-debuginfo                          Docker CE Nightly - Debuginfo x86_64                                                             disabled
docker-ce-nightly-source                             Docker CE Nightly - Sources                                                                      disabled
docker-ce-stable                                     Docker CE Stable - x86_64                                                                        enabled
docker-ce-stable-debuginfo                           Docker CE Stable - Debuginfo x86_64                                                              disabled
docker-ce-stable-source                              Docker CE Stable - Sources                                                                       disabled
docker-ce-test                                       Docker CE Test - x86_64                                                                          disabled
docker-ce-test-debuginfo                             Docker CE Test - Debuginfo x86_64                                                                disabled
docker-ce-test-source                                Docker CE Test - Sources                                                                         disabled
epel                                                 Extra Packages for Enterprise Linux 8 - x86_64                                                   enabled
epel-debuginfo                                       Extra Packages for Enterprise Linux 8 - x86_64 - Debug                                           disabled
epel-modular                                         Extra Packages for Enterprise Linux Modular 8 - x86_64                                           enabled
epel-modular-debuginfo                               Extra Packages for Enterprise Linux Modular 8 - x86_64 - Debug                                   disabled
epel-modular-source                                  Extra Packages for Enterprise Linux Modular 8 - x86_64 - Source                                  disabled
epel-source                                          Extra Packages for Enterprise Linux 8 - x86_64 - Source                                          disabled
epel-testing                                         Extra Packages for Enterprise Linux 8 - Testing - x86_64                                         disabled
epel-testing-debuginfo                               Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Debug                                 disabled
epel-testing-modular                                 Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64                                 disabled
epel-testing-modular-debuginfo                       Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64 - Debug                         disabled
epel-testing-modular-source                          Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64 - Source                        disabled
epel-testing-source                                  Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Source                                disabled
extras                                               CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                    enabled

五、安装docker

1.安装docker

yum -y install docker-ce

2.启动docker服务

systemctl enable --now docker


3.配置镜像加速


echo ' "registry-mirrors": ["https://sp4mg57h.mirror.aliyuncs.com"] '   > /etc/docker/daemon.json 

4.重启服务

#systemctl daemon-reload 
#systemctl restart docker

5.查看docker状态

[root@server-01 yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-05-17 14:38:18 CST; 5 months 1 days ago
     Docs: https://docs.docker.com
 Main PID: 1176 (dockerd)
    Tasks: 123
   Memory: 155.4M
   CGroup: /system.slice/docker.service

六、docker相关配置

1.查看docker版本

[root@server-01 yum.repos.d]# docker version
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:36:58 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:35:20 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

2.配置路由转发

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

七、部署一个测试容器

1.创建nginx容器

[root@server-01 test]# docker run -d --name my_nginx -v $(pwd):/usr/share/nginx/html -p 8744:80 nginx:1.21
Unable to find image 'nginx:1.21' locally
1.21: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:1.21
69361239b7ad511da62bf1206c0089793bb2637a5b5f1a52d17dabba239faffc

2.查看docker容器状态

[root@server-01 test]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                  PORTS                                                                                                                                                                                                                   NAMES
69361239b7ad   nginx:1.21                           "/docker-entrypoint.…"   5 minutes ago   Up 5 minutes            0.0.0.0:8744->80/tcp, :::8744->80/tcp                                                                                                                                                                                   my_nginx

3.访问业务内容

[root@server-01 test]#echo hello > index.html
[root@server-01 test]# curl 192.168.200.150:8744
hello

以上是关于华为云之HECS云服务器配置docker环境的主要内容,如果未能解决你的问题,请参考以下文章

华为云ECS/HECS:中小企业上云第一步

华为云之EVS云硬盘的使用与快速入门

华为云之RDS云数据库的管理使用与快速入门

华为云之深入探究GaussDB如何助力企业公司打造金融核心数据

教你搭建一个Telegraf+Influxdb+Grafana 监控系统

教你搭建一个Telegraf+Influxdb+Grafana 监控系统