Loading

期末作业放着用

期末作业先放着,考试的时候直接 Copy

1:双节点registry仓库部署

server

hostnamectl set-hostname server
logout
systemctl stop firewalld
setenforce 0
systemctl start docker
docker pull alpine
docker pull nginx
docker images
yum -y install vsftpd
echo "anon_root=/mnt" >> /etc/vsftpd/vsftpd.conf
systemctl start vsftpd
mount /dev/sr0 /mnt/
mv /etc/yum.repos.d/* /media
cat > /etc/yum.repos.d/local.repo << EOF
[LOCAL]
name=local
baseurl=ftp://10.0.0.11
gpgcheck=0
enabled=1
EOF
yum repolist

work

hostnamectl set-hostname work
logout
systemctl stop firewalld
setenforce 0
systemctl start docker
mv /etc/yum.repos.d/* /media

server

scp /etc/yum.repos.d/local.repo 10.0.0.12:/etc/yum.repos.d/
docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
cat > /etc/docker/daemon.json << EOF
{
  "insecure-registries": ["10.0.0.11:5000"]
}
EOF
systemctl restart docker
docker tag alpine:latest 10.0.0.11:5000/alpine:latest
docker tag nginx:latest 10.0.0.11:5000/nginx:latest
docker push 10.0.0.11:5000/alpine
docker push 10.0.0.11:5000/nginx
curl -X GET http://10.0.0.11:5000/v2/_catalog

work

cat > /etc/docker/daemon.json << EOF
{
  "insecure-registries": ["10.0.0.11:5000"]
}
EOF
systemctl restart docker
docker pull 10.0.0.11:5000/nginx
docker run -d -p 80:80 -v /www/html:/usr/share/nginx/html nginx
echo 'hello--world!' > /www/html/index.html
curl 10.0.0.12

2:实战案例——部署主从数据库

mysqld1

hostnamectl set-hostname mysqld1
logout
yum -y install mariadb mariadb-server
sed -i '/\[mysqld\]/a log_bin = mysql-bin\nbinlog_ignore_db = mysql\nserver_id = 1' /etc/my.cnf
systemctl start mariadb
mysqladmin -uroot -p password asd123.
mysql -uroot -pasd123.
grant replication slave on *.* to 'taosec'@'10.0.0.12' identified by 'asd123.';
exit

mysqld2

hostnamectl set-hostname mysqld2
logout
yum -y install mariadb mariadb-server
sed -i '/\[mysqld\]/a log_bin = mysql-bin\nbinlog_ignore_db = mysql\nserver_id = 2' /etc/my.cnf
systemctl start mariadb
mysqladmin -uroot -p password asd123.
mysql -uroot -pasd123.
change master to master_host='10.0.0.11',master_user='taosec',master_password='asd123.';
start slave;
show slave status\G

mysqld1&mysqld2 验证

# mysqld1
mysql -uroot -pasd123.
create table tao(name varchar(255), age int(11), gender varchar(255));
insert into tao(name, age, gender) values('zhangsan', '18', 'male');

# mysqld2
mysql -uroot -pasd123.
select * from taosec.tao;

3:容器底层技术与编排技术

# 步骤1:创建一个nginx容器,并查看此容器的CPU资源份额值。
docker pull nginx
docker run -d --name nginx -p 80:80 nginx
docker inspect xxx | grep "CpuShares"

# 步骤2:创建一个alpine容器并分配CPU份额值为500,并查看结果。
docker pull alpine 
docker run -itd --name ap1 --cpu-shares=500 alpine /bin/sh
docker inspect xxx | grep "CpuShares"

# 步骤3:创建一个alpine容器实现每1秒使用单个CPU的0.5秒时间,并查看结果。
docker run -itd --name ap2 --cpu-period=1000000 --cpu-quota=500000 alpine
docker inspect xxx | grep -E "CpuPeriod|CpuQuota"

# 步骤4:创建一个alpine容器并分配memory为10M,并查看结果。
docker run -itd --name ap3 --memory=10M alpine
docker inspect xxx | grep -m 1 "Memory"

# 步骤5:下载wordpress6.zip文件包,并在windwos环境下部署wordpress,截关键图。
直接用 phpstudy 一键部署

# 步骤6:下载docker-compose-Linux-x86_64文件,并安装好docker-compose,查看docker-compose 版本。
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
docker compose version

# 步骤7:下载mysql和wordpress镜像,并分别启动mysql和wordpress容器,利用容器完成wordpress 应用部署,截关键图。
docker pull mysql
docker pull wordpress
docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=asd123. -P mysql
docker run -itd --name wordpress --link mysql -p 8080:80 wordpress
docker exec -it mysql /bin/bash
mysql -uroot -pasd123.
create database wordpress;
exit
docker inspect xxx | grep  "IPAddress"

# 步骤8:利用docker-compose.yml文件,启动nginx和httpd服务,并浏览器访问成功,截关键图。
docker rm -f mysql
docker rm -f wordpress
docker pull httpd
docker pull nginx
cat > docker-compose.yaml << EOF
version: '3'

services:
  nginx:
    image: nginx:latest
    ports:
      - "8080:80"
  
  httpd:
    image: httpd:latest
    ports:
      - "8081:80"
EOF
docker compose up -d

# 步骤9:修改docker-compose.yml文件,启动mysql和wordpress服务,并浏览器访问成功,截关键 图。
docker rm -f nginx
docker rm -f httpd
rm -rf docker-compose.yaml
cat > docker-compose.yaml << EOF
version: '3'
services:
  mysql:
    image: mysql
    container_name: mysql
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_ROOT_PASSWORD: asd123.
    ports:
      - "3306:3306"
  wordpress:
    depends_on:
      - mysql
    image: wordpress
    container_name: wordpress
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_PASSWORD: asd123.
EOF
docker compose up -d
posted @ 2024-06-16 23:51  忽如一夜春风来~  阅读(18)  评论(0编辑  收藏  举报