[toc]

第一步:更新yum库:

1
yum update

第二步、安装依赖软件包

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

第三步、设置[yum源]

1
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/dockerce/linux/centos/docker-ce.repo

第四步、[安装docker]

1
2
3
yum install docker-ce 
systemctl enable --now docker
systemctl daemon-reload

1~4不要,或者:

1
2
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce -y

5

1
2
mkdir -p /root/data/nginx/
vim /root/data/nginx/default.conf

下面有3处要改

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
upstream 192.168.117.146{ # IP地址是当前虚拟机的IP
server web1;
server web2;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://192.168.117.146; # 配置负载均衡
#root /usr/share/nginx/html; # 这边被注释了
#index index.html index.htm; # 这边被注释了
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ { # 这边注释被去除了
proxy_pass http://192.168.117.146; # 配置php请求负载均衡
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param
#SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include #fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

image-20240322110742726

5.5

1
2
3
systemctl enable --now docker
systemctl daemon-reload
docker run -it -v /root/data/nginx:/data --rm nginx cp /etc/nginx/conf.d/default.conf /data

6

1
2
docker run -d -v /root/data/html:/var/www/html --rm --name web1 php:5.6-apache
docker run -d -v /root/data/html:/var/www/html --rm --name web2 php:5.6-apache

7

1
2
3
docker run -d --rm --name lb -p 80:80 -v /root/data/nginx:/etc/nginx/conf.d --link web1:web1 --link web2:web2 nginx

systemctl daemon-reload

状态:

1
docker ps

8.在 /root/data/html 中创建php探针文件

1
2
3
4
5
6
cd /root/data/html

vim info.php
<?php
phpinfo();
?>
1
systemctl daemon-reload

9(这边有两个文件写入)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd /root/data/html
vim sources.list
deb http://archive.debian.org/debian stretch main
deb http://archive.debian.org/debian-security stretch/updates main

# 由于原版的镜像源失效了 这边我们重新封装一个源进去

vim Dockerfile
FROM php:5.6-apache
ADD http://pecl.php.net/get/memcached-2.2.0.tgz /root
ADD sources.list /etc/apt/sources.list
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
&& apt-get update \
&& apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install /root/memcached-2.2.0.tgz

RUN docker-php-ext-install mysql && docker-php-ext-enable mysql \
&& docker-php-ext-install mysqli && docker-php-ext-enable mysqli \
&& docker-php-ext-enable memcached \

10

1
2
3
4
5
6
docker build -t myphp .
docker images
docker run --rm -v /root/data/phpini:/data myphp cp -r /usr/local/etc/php/. /data
vim /root/data/phpini/php.ini
session.save_handler = memcache # 大概在1416行的地方
session.save_path = "tcp://session:11211" # 大概在1445行的地方
1
2
3
docker run -d -p 81:80 \
-v /root/data/html:/var/www/html \
-v /root/data/phpini:/usr/local/etc/php --rm --name web1 myphp
1
2
docker run --name db --rm \
-v /root/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mariadb:5.5.64
1
docker rm -f `docker ps -qa`
1
docker run -d --restart=always --name session memcached
1
2
docker run --name db --restart=always \
-v /root/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mariadb:5.5.64
1
2
3
4
5
6
docker run -d --link db:db --link session:session \
-v /root/data/html:/var/www/html \
-v /root/data/phpini:/usr/local/etc/php --restart=always --name web1 myphp
docker run -d --link db:db --link session:session \
-v /root/data/html:/var/www/html \
-v /root/data/phpini:/usr/local/etc/php --restart=always --name web2 myphp
1
docker run -d --restart=always --name lb -p 80:80 -v /root/data/nginx:/etc/nginx/conf.d --link web1:web1 --link web2:web2 nginx
1
docker exec -it db mysql -uroot -p123456 -e "create database typecho;show databases;"
1
2
3
4
cd /root/data/html
在这个文件目录下放入typecho.zip
typecho.zip获取链接:
https://www.yuque.com/g/wushi-ls7km/sq639b/av9yam8xv6g252gc/collaborator/join?token=KBu9P432TjpcGy2y&source=doc_collaborator# 《准备工具》
1
unzip typecho.zip

之后登录ip后进入typecho界面

按要求建文件,输入代码:

对了:

数据库:db

密码:123456