由于个人开发需求,一些软件需要安装本地的方便使用,但是这些软件如果全安装在主力机笔记本上,会严重拖慢笔记本的速度。 思前想后还是在阿里云上买一台云服务器比较合适。
怎么买的,直接上阿里云官网看看,选好配置,直接付款就行了。
1. ECS 概览页面
买到的机器这里可以显示出来:
选中实例之后,需要修改密码,初始化时账号名称是root:
使用Workbench登陆:
登陆之后页面如下,查看版本号:
只要知道IP和账号密码,用什么软件登录都是一样的,个人比较喜欢使用 IDEA 登陆,和开发工具结合在一起(默认端口是22):
2. 安装 Docker
登陆成功后,开始安装docker,由于这里是新的Linux系统,之前没有 Docker我文件,直接安装即可。
依次执行以下命令:
// 安装 yum-utils软件包
yum install -y yum-utils
// 设置 Docker 阿里云仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
// 更新yum软件包索引
yum makecache fast
下面安装 Docker:
yum install docker-ce docker-ce-cli containerd.io
中间需要确认,输入y,完成之后,会显示以下信息:
Installed:
containerd.io.x86_64 0:1.4.4-3.1.el7 docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-cli.x86_64 1:20.10.5-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8
docker-ce-rootless-extras.x86_64 0:20.10.5-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7
libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
Dependency Updated:
audit.x86_64 0:2.8.5-4.el7 audit-libs.x86_64 0:2.8.5-4.el7 libselinux.x86_64 0:2.5-15.el7
libselinux-python.x86_64 0:2.5-15.el7 libselinux-utils.x86_64 0:2.5-15.el7 libsemanage.x86_64 0:2.5-14.el7
libsepol.x86_64 0:2.5-10.el7 policycoreutils.x86_64 0:2.5-34.el7 selinux-policy.noarch 0:3.13.1-268.el7_9.2
selinux-policy-targeted.noarch 0:3.13.1-268.el7_9.2
Complete!
启动 Docker
systemctl start docker
查看 Docker 版本
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# docker -v
Docker version 20.10.5, build 55c4c88
执行 hello world
老规矩:
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# systemctl start docker
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
... 省略
安装 Docker Compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
3. 运行 Redis
查询 Redis image
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 9302 [OK]
bitnami/redis Bitnami Redis Docker Image 177 [OK]
sameersbn/redis 82 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2 77
rediscommander/redis-commander Alpine image for redis-commander - Redis man… 56 [OK]
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 33
redislabs/redis Clustered in-memory database engine compatib… 29
... 省略
这里直接pull 第一个:docker pull redis
可以看到已经 pull 到本地了:
[root@iZ2ze7eop7f43wmsiq5q9rZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest de974760ddb2 10 hours ago 105MB
hello-world latest d1165f221234 5 weeks ago 13.3kB
启动 Redis
// xxx 是你自定义的路径
docker run -p 6379:6379 -v /xxx:/data -d redis:latest redis-server --appendonly yes
这里将 6379 映射出去,如果这时候直接从外网去连接的话,你会发现连接不上的。用 ping 命令和 telnet 命令查看一下就会发现,端口没有从 ECS 暴露到外网。
ECS 安全组规则配置
找到 网络与安全 - 安全组 菜单,选中 配置规则 :
复制一条访问规则之后,修改端口:
将常用的端口开发出去,如Redis、MySQL等等:
外网访问 Redis
上面配置完成了之后,这时使用软件在本地连接 ECS 中的 Redis 服务器,可以发现正常连接:
:)