云容器平台实战

初始快照

准备工作

①部署 IP,能联通外网

②清除防火墙规则

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -X
[root@localhost ~]# iptables -Z
[root@localhost ~]# /usr/sbin/iptables-save

[root@localhost ~]# vim /etc/selinux/config
...
SELINUX=disabled 将enforcing改成disabled
...

[root@localhost ~]# reboot

③关闭 swap 交换分区

1
2
3
4
5
[root@localhost ~]# swapoff -a
[root@localhost ~]# vim /etc/fstab
...
#/dev/mapper/centos-swap swap swap defaults 0 0
注释这一行 ↑

④路由转发

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# vim /etc/sysctl.conf 
... 添加以下三行 ↓
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

加载模块
[root@localhost ~]# modprobe br_netfilter
从刚刚写的文件里读取值
[root@localhost ~]# sysctl -p

⑤物理机 scp 上传Kubernetes.zip文件

再解压.zip文件

[root@localhost ~]# unzip Kubernetes.zip

⑥先备份/etc/yum.repos.d/下的所有 Centos-xxx 文件,再配置本地 yum 源(只留这一个文件)

⑦重启服务

[root@localhost Kubernetes]# systemctl restart network

⑧安装 docker

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# yum -y install docker*

启动docker服务并设置开机自启
[root@localhost ~]# systemctl start docker ; systemctl enable docker

查看docker信息
[root@localhost ~]# docker info

重启加载服务
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start docker ; systemctl enable docker
部署 MySQL 容器
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
拉取mysql映像
[root@localhost ~]# docker pull mysql

创建mysql容器
[root@localhost ~]# docker run -d -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 --name db_mysql_wordpress mysql

进入mysql容器,按题目要求创建数据库和表
[root@localhost ~]# docker exec -it db_mysql_wordpress /bin/bash
bash-4.4# mysql -uroot -p123456

mysql> create database SZPT;
mysql> use SZPT;
mysql> create table Cloud(stuno varchar(8),stuname varchar(8),stulaojia varchar(8),stuage varchar(2));
mysql> insert into Cloud(stuno,stuname,stulaojia,stuage) values
-> ('20940702','xiaolai','meizhou','20'),
-> ('20940715','xiaoding','hunan','20'),
-> ('20940700','zhiquan','maoming','21'),
-> ('20940688','youjun','shenzhen','20'),
-> ('20940676','xiaopan','zhuhai','20'),
-> ('18240683','xixi','shenzhen','22'),
-> ('20940680','cc','shenzhen','19');
mysql> select * from Cloud where Cloud.stuage='20'; '本人年龄'

退出(exit)
导出'mysql'映像tar包
[root@localhost ~]# docker save -o mysql.tar mysql
安装 wordpress
1
2
3
4
5
6
7
8
拉取wordpress映像
[root@localhost ~]# docker pull wordpress

创建wordpress容器
[root@localhost ~]# docker run -d --link db_mysql_wordpress -p 9090:80 --name wb_wordpress wordpress

关闭防火墙
[root@localhost ~]# systemctl stop firewalld

浏览器访问即可

IP地址/9090

image-20220709205122302

后续根据需求 post 博客即可~