X–1 docs / 07 主站

部署手册

07-A00-部署手册.md · 2342 字

部署手册

项目代号: A00
项目名称: TJFS集团官方网站及Web服务器
文档类型: 部署手册
创建日期: 2026-03-05
编制人: TBs
文档版本: V1.0
文档状态: 已批准


目录

  1. 部署概述
  2. 环境准备
  3. 部署步骤
  4. 配置说明
  5. 验证测试
  6. 故障排查
  7. 运维指南
  8. 附录

一、部署概述

1.1 部署目标

将TJFS集团官方网站部署到生产环境,提供稳定、高效的Web服务。

1.2 部署架构

┌─────────────────────────────────────────────────────────────┐
│                        客户端                                │
│  ┌──────────────┐ ┌──────────────┐ ┌──────────────┐        │
│  │   PC端       │ │   平板端      │ │   手机端      │        │
│  └──────────────┘ └──────────────┘ └──────────────┘        │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼ HTTP/HTTPS
┌─────────────────────────────────────────────────────────────┐
│                        Web服务器                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │              Python HTTP Server                      │   │
│  │              Port: 80 / 8537                         │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                        静态资源                              │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐                  │
│  │ HTML文件  │  │ CSS样式  │  │ JS脚本   │                  │
│  └──────────┘  └──────────┘  └──────────┘                  │
└─────────────────────────────────────────────────────────────┘

1.3 部署清单

部署项说明状态
服务器环境Python 3.10+待部署
Web服务Python HTTP Server待部署
静态文件HTML/CSS/JS待部署
配置文件服务器配置待部署

二、环境准备

2.1 硬件要求

硬件项最低配置推荐配置
CPU2核4核
内存4GB8GB
硬盘20GB50GB
网络10Mbps100Mbps

2.2 软件要求

软件项版本要求说明
操作系统Windows 10+/Linux/macOS支持跨平台
Python3.10+运行环境
浏览器Chrome/Firefox/Safari/Edge访问验证

2.3 端口要求

端口用途说明
80HTTP服务默认端口
8537HTTP服务(备用)端口80被占用时使用

2.4 网络要求

要求项说明
外网访问服务器需要外网IP或端口映射
防火墙开放80/8537端口
DNS配置域名解析(可选)

三、部署步骤

3.1 准备工作

3.1.1 检查Python环境

# Windows
python --version
# 或
python3 --version

# 预期输出: Python 3.10.x 或更高版本

如果Python未安装,请访问 https://www.python.org/downloads/ 下载安装。

3.1.2 创建部署目录

# Windows
mkdir D:\Projects\A00\web.sever
cd D:\Projects\A00\web.sever

# Linux/macOS
mkdir -p /var/www/web.sever
cd /var/www/web.sever

3.2 部署文件

3.2.1 复制项目文件

将以下文件复制到部署目录:

web.sever/
├── index.html          # 主页面
├── css/
│   └── style.css       # 样式文件
├── js/
│   └── main.js         # 脚本文件
├── sgstudio/           # SG Studio子站点
│   ├── index.html
│   ├── css/
│   ├── js/
│   └── projects/
├── tbs/                # TBs科技子站点
│   ├── index.html
│   ├── css/
│   ├── js/
│   └── projects/
└── start-server.py     # 服务器启动脚本

3.2.2 验证文件完整性

# Windows PowerShell
Get-ChildItem -Recurse | Select-Object FullName, Length

# Linux/macOS
find . -type f -exec ls -lh {} \;

3.3 配置服务器

3.3.1 端口配置

编辑 start-server.py 文件,配置服务端口:

# 默认使用80端口
PORT = 80

# 如果80端口被占用,使用8537端口
# PORT = 8537

3.3.2 CORS配置

服务器已默认配置CORS支持,无需额外配置:

def end_headers(self):
    self.send_header('Access-Control-Allow-Origin', '*')
    self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
    self.send_header('Access-Control-Allow-Headers', 'Content-Type')
    super().end_headers()

3.4 启动服务

3.4.1 使用Python脚本启动

# Windows
cd D:\Projects\A00\web.sever
python start-server.py

# Linux/macOS
cd /var/www/web.sever
python3 start-server.py

3.4.2 使用批处理文件启动(Windows)

双击运行 start-server.bat 文件:

@echo off
cd /d "D:\Projects\A00\web.sever"
python start-server.py
pause

3.4.3 使用后台运行(Linux/macOS)

# 使用nohup后台运行
cd /var/www/web.sever
nohup python3 start-server.py > server.log 2>&1 &

# 查看进程
ps aux | grep start-server

# 停止服务
kill <PID>

3.5 服务验证

3.5.1 检查服务状态

# Windows - 查看端口占用
netstat -ano | findstr :80

# Linux/macOS
netstat -tlnp | grep :80
# 或
ss -tlnp | grep :80

3.5.2 访问测试

在浏览器中访问:

http://localhost           # 本地访问
http://服务器IP            # 局域网访问
http://域名                # 公网访问(需配置DNS)

四、配置说明

4.1 服务器配置

4.1.1 主要配置项

配置项默认值说明
PORT80服务端口
DIRECTORY脚本所在目录静态文件根目录
CORS*允许所有跨域访问

4.1.2 配置文件示例

#!/usr/bin/env python3
"""
TJFS Web服务器配置
"""
import http.server
import socketserver
import os
from pathlib import Path

# 服务器配置
PORT = 80                           # 服务端口
DIRECTORY = Path(__file__).parent.resolve()  # 服务目录

# CORS配置
CORS_ORIGIN = '*'                   # 允许的跨域来源
CORS_METHODS = 'GET, POST, OPTIONS' # 允许的HTTP方法
CORS_HEADERS = 'Content-Type'       # 允许的请求头

4.2 防火墙配置

4.2.1 Windows防火墙

# 添加入站规则(管理员权限)
New-NetFirewallRule -DisplayName "TJFS Web Server" -Direction Inbound -Protocol TCP -LocalPort 80,8537 -Action Allow

# 查看规则
Get-NetFirewallRule -DisplayName "TJFS Web Server"

# 删除规则
Remove-NetFirewallRule -DisplayName "TJFS Web Server"

4.2.2 Linux防火墙(iptables)

# 开放80和8537端口
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8537 -j ACCEPT

# 保存规则
sudo iptables-save > /etc/iptables/rules.v4

4.2.3 Linux防火墙(firewalld)

# 开放80和8537端口
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=8537/tcp
sudo firewall-cmd --reload

# 查看状态
sudo firewall-cmd --list-ports

4.3 域名配置(可选)

4.3.1 DNS配置

在域名服务商处添加A记录:

记录类型主机记录记录值
A@服务器IP地址
Awww服务器IP地址

4.3.2 本地Hosts配置(测试用)

# Windows: C:\Windows\System32\drivers\etc\hosts
# Linux/macOS: /etc/hosts

服务器IP    tjfs.com
服务器IP    www.tjfs.com

五、验证测试

5.1 功能验证

5.1.1 首页访问

# 使用curl测试
curl -I http://localhost

# 预期输出
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: xxx
Access-Control-Allow-Origin: *

5.1.2 静态文件访问

# 测试CSS文件
curl -I http://localhost/css/style.css

# 测试JS文件
curl -I http://localhost/js/main.js

# 预期输出
HTTP/1.0 200 OK
Content-Type: text/css
# 或
Content-Type: application/javascript

5.2 性能验证

5.2.1 响应时间测试

# 测试响应时间
curl -o /dev/null -s -w "%{time_total}\n" http://localhost

# 预期结果: < 100ms

5.2.2 并发测试

# 使用ab工具(Apache Bench)
ab -n 1000 -c 100 http://localhost/

# 预期结果
# Requests per second: > 100
# Time per request: < 100ms

5.3 浏览器验证

在以下浏览器中验证网站显示:

浏览器版本验证结果
Chrome最新版□
Firefox最新版□
Safari最新版□
Edge最新版□

5.4 设备验证

在以下设备中验证响应式布局:

设备类型分辨率验证结果
PC1920x1080□
笔记本1366x768□
平板768x1024□
手机375x667□

六、故障排查

6.1 常见问题

问题1: 端口被占用

现象:

PermissionError: [Errno 13] Permission denied
# 或
OSError: [Errno 98] Address already in use

解决方案:

# 查找占用端口的进程
# Windows
netstat -ano | findstr :80
taskkill /PID <PID> /F

# Linux/macOS
sudo lsof -i :80
sudo kill -9 <PID>

# 或使用备用端口
# 修改start-server.py中的PORT为8537

问题2: Python未安装

现象:

'python' 不是内部或外部命令

解决方案:

  1. 访问 https://www.python.org/downloads/
  2. 下载并安装Python 3.10+
  3. 安装时勾选"Add Python to PATH"

问题3: 防火墙阻止

现象:

解决方案:

  1. 检查防火墙规则(见4.2节)
  2. 检查安全组配置(云服务器)
  3. 临时关闭防火墙测试(仅用于诊断)

问题4: 文件权限不足

现象:

PermissionError: [Errno 13] Permission denied

解决方案:

# Linux/macOS
sudo chmod -R 755 /var/www/web.sever
sudo chown -R $USER:$USER /var/www/web.sever

6.2 日志查看

6.2.1 服务器日志

服务器运行时会输出访问日志:

127.0.0.1 - - [05/Mar/2026 10:00:00] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2026 10:00:01] "GET /css/style.css HTTP/1.1" 200 -

6.2.2 错误日志

查看错误信息:

# Linux/macOS后台运行
tail -f server.log

# Windows
# 直接在命令行窗口查看输出

6.3 诊断命令

命令用途示例
ping测试网络连通ping tjfs.com
telnet测试端口连通telnet localhost 80
curl测试HTTP请求curl -I http://localhost
netstat查看端口状态netstat -ano \findstr :80
nslookup测试DNS解析nslookup tjfs.com

七、运维指南

7.1 日常监控

7.1.1 服务状态检查

# 检查进程是否存在
# Windows
tasklist | findstr python

# Linux/macOS
ps aux | grep start-server

7.1.2 资源使用监控

# 查看CPU和内存使用
# Windows
tasklist /fi "imagename eq python.exe"

# Linux/macOS
top -p $(pgrep -d',' -f start-server)

7.2 备份策略

7.2.1 文件备份

# 备份网站文件
# Windows
xcopy D:\Projects\A00\web.sever D:\Backup\web.sever\%date:~0,4%%date:~5,2%%date:~8,2% /E /I /H

# Linux/macOS
tar -czvf /backup/web.sever-$(date +%Y%m%d).tar.gz /var/www/web.sever

7.2.2 备份清单

备份项备份频率保留周期
网站文件每日7天
配置文件每次修改永久
日志文件每周30天

7.3 更新维护

7.3.1 更新流程

1. 备份当前版本
2. 上传新版本文件
3. 重启服务
4. 验证更新
5. 回滚(如有问题)

7.3.2 重启服务

# 停止服务
# Windows
Ctrl + C

# Linux/macOS
kill <PID>

# 启动服务
python start-server.py

7.4 安全建议

建议项说明
定期更新及时更新Python和操作系统补丁
访问控制限制不必要的端口开放
日志审计定期审查访问日志
备份验证定期验证备份文件可恢复

八、附录

附录A: 部署检查清单

部署前检查

部署中检查

部署后检查

附录B: 快速启动命令

# Windows快速启动
cd D:\Projects\A00\web.sever && python start-server.py

# Linux/macOS快速启动
cd /var/www/web.sever && python3 start-server.py

# 后台运行(Linux/macOS)
nohup python3 start-server.py > server.log 2>&1 &

附录C: 常用端口

端口用途状态
80HTTP默认端口首选
443HTTPS端口预留
8537HTTP备用端口备用
8080HTTP备用端口可选

附录D: 变更记录

版本日期变更内容变更人
V1.02026-03-05初始版本TBs

文档编制日期: 2026-03-05
编制单位: SG Studio - 松果工作室
文档版本: V1.0