# 181. 商品详情页动态渲染系统:在 CentOS 6 安装和部署 Docker
TIP
注意,docker 需要在 centOS 7 中安装,这里安装 CentOS-7-x86_64-Minimal-1708.iso , 然后在上面安装 docker
部分配置可以参考:之前的 centos 安装
# centOS 7 安装
- 使用版本:CentOS-7-x86_64-Minimal-1708.iso,
- 账户/密码 root/hadoop123
# 配置网络
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 # 先让它动态分配一个ip地址 ONBOOT=yes # 重启服务 service network restart # 查看分配的地址 ip addr # 再设置静态 ip 地址 BOOTPROTO=static IPADDR=192.168.99.20 NETMASK=255.255.255.0 GATEWAY=192.168.99.1 # 重启网络服务 service network restart # 查看是否设置成功 ip addr
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
执行以下命令报错,是缺少了 dns 配置
[root@localhost ~]# ping www.baidu.com ping: www.baidu.com: Name or service not known
Copied!
1
2
2
配置 dns
# 检查 NetManager 的状态: systemctl status NetworkManager.service # 检查 NetManager 管理的网络接口: nmcli dev status # 检查 NetManager 管理的网络连接: nmcli connection show # 设置 dns: nmcli con mod enp0s3 ipv4.dns "114.114.114.114 8.8.8.8" # 让 dns 配置生效: nmcli con up enp0s3
Copied!
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 关闭防火墙
systemctl stop firewalld.service systemctl disable firewalld.service
Copied!
1
2
2
# 安装 java 8
cd /usr/local # 安装上传下载工具 yum install lrzsz rz 选择 jdk-8u202-linux-i586.rpm rpm -ivh jdk-8u202-linux-i586.rpm # 卸载可以使用 rpm -e jdk1.8-2000:1.8.0_202-fcs.i586 # 安装过程中就出现了以下类似的错误 # 运行 java -version 出现以下错误 -bash: /usr/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 解决方案如下: # 安装 glibc.i686 yum install glibc.i686 # 卸载安装不完整的 java rpm -e jdk1.8-2000:1.8.0_202-fcs.i586 # 重新安装 rpm -ivh jdk-8u202-linux-i586.rpm 通过此方式安装之后,不需要配置环境变量
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 初步安装和启动 docker
如果这里的安装步骤让你感到不解,那么可以参考此教程 (opens new window) ,里面参考了官网的安装教程
yum update -y yum install -y yum-utils # 添加 docker-ce 仓库地址 # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum -y install docker-ce systemctl start docker
Copied!
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 设置镜像
vi /etc/docker/daemon.json # 设置成 阿里云的 { "registry-mirrors": ["https://aj2rgad5.mirror.aliyuncs.com"] }
Copied!
1
2
3
4
5
6
7
2
3
4
5
6
7
# 开放管理端口映射
vi /lib/systemd/system/docker.service # 将第 11 行的 ExecStart=/usr/bin/dockerd,替换为: # 2375 是管理端口,7654 是备用端口 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:7654 # 在 ~/.bashrc 中写入 docker 管理端口 vi ~/.bashrc export DOCKER_HOST=tcp://0.0.0.0:2375 source ~/.bashrc
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 测试 docker 是否正常安装和运行
# 记得先停止 docker 再运行,因为之前配置了端口什么的 systemctl stop docker systemctl start docker # 运行 docker 的一个 hello-world 镜像 docker run hello-world ... # 如果现实有以下文字就说明可以了 Hello from Docker! This message shows that your installation appears to be working correctly.
Copied!
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 错误解决
# yum-config-manager --add-repo 异常
执行命令后出现以下异常,原因是国内无法访问外国的 docker 镜像,这里需要使用阿里云的来安装
[root@eshop-detail01 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 416 Requested Range Not Satisfiable" Trying other mirror. Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 416 Requested Range Not Satisfiable"
Copied!
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
解决方案:yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum -y install docker-ce 异常
报错的地址文件的确 404 了,这个就是在 centos 6 下安装 docker-ce 的缘故,使用 centos 7 安装就行了
[root@eshop-detail01 ~]# yum install -y docker Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: ap.stykers.moe https://download.docker.com/linux/centos/7/i386/stable/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found" Trying other mirror. To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errors If above article doesn't help to resolve this issue please use https://bugs.centos.org/. Error: Cannot retrieve repository metadata (repomd.xml) for repository: docker-ce-stable. Please verify its path and try again
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16