概述:工具集

安装过程

Step 1 环境准备

cat /etc/redhat-release # 查看 CentOS 版本
sudo yum update # 升级所有包到最新
cat /etc/redhat-release # 再次查看 CentOS 版本是否已经更新

# 安装包管理器管理器
sudo yum install -y yum-utils \\
  device-mapper-persistent-data \\
  lvm2 
# 安装 nginx
sudo rpm -ivh <http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm>
sudo yum repolist # 检查是否有 nginx repo
sudo yum install nginx -y
# 启动 nginx
sudo systemctl enable nginx
sudo systemctl start nginx

# 检查 nginx 是否已经安装成功
nginx -v
# 安装 docker
sudo yum repolist # 检查是否有 extras repo
sudo yum remove docker \\
                  docker-client \\
                  docker-client-latest \\
                  docker-common \\
                  docker-latest \\
                  docker-latest-logrotate \\
                  docker-logrotate \\
                  docker-engine # 卸载旧版本 docker(如果有)
sudo yum-config-manager \\
    --add-repo \\
    <https://download.docker.com/linux/centos/docker-ce.repo>
sudo yum update
sudo yum install docker-ce docker-ce-cli containerd.io -y

# 启动 docker
sudo systemctl start docker
sudo systemctl enable docker
# 检查 docker 是否已经安装并启动成功
sudo docker run hello-world

# 安装 docker-compose
sudo curl -L "<https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$>(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 检查 docker-compose 是否已经安装成功
docker-compose --version

Step 2 安装 Wordpress

新建 wordpress 目录,在里面新建 docker-compose.yml 文件,写入以下内容

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
     volumes:
      - wordpress:/var/www/html
			- php:/usr/local/etc/php
volumes:
    db: 
    wordpress:
	  php:

运行 docker-compose up -d 进行配置

Step 3 配置反向代理

在 nginx 配置文件目录 /etc/nginx/conf.d 下新增一个 blog.conf 文件,写入以下内容

server {
    charset utf-8;
    listen       80;
    #server_name  localhost;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass <http://127.0.0.1:8000>;
    }

}

然后执行 nginx -t 检测是否有问题,没有问题执行 nginx -s reload 加载配置文件

<aside> 💡 在刚刚完成了 docker 启动后执行 netstat -anpt 出现端口状态在等待而非监听是正常的,wordpress 初始化需要数分钟时间

</aside>

问题解决

配置 HTTPS 支持