安装 docker
1 2 3 4 5
| # CentOS Linux release 7.3.1611 (Core) # 使用官方的脚本安装docker sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun # 启动docker服务 sudo systemctl start docker
|
登录阿里云容器镜像仓库
https://cr.console.aliyun.com/cn-shenzhen/instances/repositories
按照文档进行配置镜像加速器
docker 配置 nginx
1 2
| # 拉取centos镜像 sudo docker pull centos:7.7.1908
|
编写 DockerFile 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| FROM centos:7.7.1908 RUN \ yum install -y wget && \ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \ yum clean all && \ yum makecache && \ rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm && \ yum install -y nginx && \ yum install -y git && \ yum install -y vim && \ git init --bare ~/blogs.git && \ echo "git --work-tree=/usr/share/nginx/html --git-dir=/root/blogs.git checkout -f" >~/blogs.git/hooks/post-receive && \ chmod a+x ~/blogs.git/hooks/post-receive && \ yum install -y openssh openssh-server openssh-clients && \ ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key && \ ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \ ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key EXPOSE 22 EXPOSE 80 CMD ["nginx","-g","daemon off;"]
|
script1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # 构建镜像 docker build -t hexoblogs . # 运行容器 sudo docker run --name myblog -p 8003:80 -p 8004:22 -d hexoblogs:latest # 前往浏览器查看容器内的Nginx是否配置成功 # 生成ssh公钥 ssh-keygen docker cp ~/.ssh/id_rsa.pub 容器id:/root/.ssh/ # 进入容器 docker exec -it 容器id bash # 复制id_rsa.pub内容到~/.ssh/authorized_keys cat id_rsa.pub >> ~/.ssh/authorized_keys # 启动sshd /usr/sbin/sshd
|
PC 配置 hexo
Windows 下安装 node 过程省略
1 2 3 4 5 6 7 8 9 10 11 12
| # 配置免密访问方式和linux一样,这里不再进行重复 npm install -g hexo-cli npm install hexo-deployer-git --save npm install hexo-server hexo init 本地路径 // 初始化hexo # 进入初始化的路径修改_config.yml文件 deploy: type: 'git' repo: 'ssh://用户名@xxx.xxx.xxx.xxx:8004/root/blogs.git' branch: master # 在项目路径执行 hexo clean && hexo g -d
|
服务端配置 Nginx 反向代理
script1 2
| # 安装lnmp环境,按需求进行选择 wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh lnmp
|
由于早期的配置失误我这边就直接在实体机再起一个 nginx 反向代理 docker 内的 nginx。好在应该是我服务起的少,网站的启动速度在 600ms 以内。可以接受。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| # 编辑服务器nginx配置文件 sudo vim /usr/local/nginx/conf/nginx.conf server{ listen 443 ssl; server_name blog.lopponia.com; ssl_certificate pem文件绝对路径; ssl_certificate_key key文件绝对路径; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_pass http://blog.lopponia.com:8003; } } server { listen 80; server_name blog.lopponia.com; return 301 https://$server_name$request_uri; } # 重新加载nginx配置 systemctl reload nginx
|
至此 hexo 搭建完成