# screen_write **Repository Path**: Zhao_Y_Kun/screen_write ## Basic Information - **Project Name**: screen_write - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-31 - **Last Updated**: 2026-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Love Note 一个适合异地使用的实时手写小纸条。双方用手机浏览器打开网页,输入同一个邀请码,即可同步画板内容。 ## 项目结构 ```text . ├── Makefile ├── src/main.cpp ├── web/ │ ├── index.html │ ├── app.js │ └── style.css └── deploy/ ├── nginx.conf ├── nginx-https.conf └── love-note.service ``` ## CentOS 7.9 注意事项 CentOS 7 已于 2024 年 6 月 30 日停止维护,不再收到安全更新。公开部署建议尽快迁移到 Rocky Linux 9、AlmaLinux 9 或其他仍受支持的系统。 如果暂时只能使用 CentOS 7.9,不能直接依赖系统默认开发环境: - 默认 GCC 4.8 太旧,无法编译本项目使用的 C++17。 - 默认 Boost 1.53 不包含 Boost.Beast。 - CentOS 7 的常规软件源可能已经失效,需要先切换到 Vault 归档源。 下面的步骤适用于临时在 CentOS 7.9 上部署。 ## 1. 恢复 Vault 软件源 如果 `yum install` 已经正常工作,跳过这一步。 ```bash sudo sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-*.repo sudo sed -i 's|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*.repo sudo yum clean all sudo yum makecache ``` ## 2. 安装 GCC 7、Make 和 Nginx 使用 Software Collections 提供的新版编译器: ```bash sudo yum install -y centos-release-scl sudo yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++ make curl tar nginx scl enable devtoolset-7 bash g++ --version ``` 如果安装 `devtoolset-7` 时提示 SCLo 软件源不可用,将 SCLo 源切换到 CentOS Vault: ```bash sudo sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-SCLo-*.repo sudo sed -i 's|^# *baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-SCLo-*.repo sudo yum clean all sudo yum makecache sudo yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++ ``` 后续每次重新登录并需要编译时,先运行: ```bash scl enable devtoolset-7 bash ``` ## 3. 下载头文件依赖并编译 项目使用 Boost.Beast。下载较新的 Boost 头文件,而不是 CentOS 7 自带的 Boost 1.53: ```bash cd /var/www/love-note mkdir -p third_party/include/nlohmann curl -L https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.gz | tar -xz -C third_party curl -L https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp \ -o third_party/include/nlohmann/json.hpp make ``` 编译后的程序是: ```text /var/www/love-note/love-note-server ``` 后台只监听 `127.0.0.1:8080`,由 Nginx 对外提供网页和 WebSocket 反向代理。 ## 4. 配置 Nginx 和 systemd 将 `deploy/nginx.conf` 中的 `note.example.com` 替换为你的域名,然后执行: ```bash sudo cp deploy/nginx.conf /etc/nginx/conf.d/love-note.conf sudo cp deploy/love-note.service /etc/systemd/system/love-note.service sudo chown -R root:nginx /var/www/love-note sudo chmod -R a+rX /var/www/love-note sudo systemctl daemon-reload sudo systemctl enable --now love-note sudo nginx -t sudo systemctl enable --now nginx sudo systemctl reload nginx ``` 如果启用了 SELinux 和 firewalld,还需要执行: ```bash sudo setsebool -P httpd_can_network_connect 1 sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload ``` 检查后台状态: ```bash sudo systemctl status love-note curl -I http://127.0.0.1 ``` ## 5. 配置 HTTPS 手机浏览器访问时应使用 HTTPS。CentOS 7 上的 Certbot 安装链路已经比较老,建议使用不依赖 Python 的 `acme.sh`。 先确保域名已经解析到服务器,并且云服务器安全组放行 TCP `80` 和 `443`。将下面的域名和邮箱替换成自己的值: ```bash sudo -i curl https://get.acme.sh | sh -s email=your-email@example.com /root/.acme.sh/acme.sh --issue --server letsencrypt \ -d note.example.com \ -w /var/www/love-note/web mkdir -p /etc/nginx/ssl/love-note /root/.acme.sh/acme.sh --install-cert -d note.example.com \ --key-file /etc/nginx/ssl/love-note/key.pem \ --fullchain-file /etc/nginx/ssl/love-note/fullchain.pem \ --reloadcmd "systemctl reload nginx" exit ``` 将 `deploy/nginx-https.conf` 中的 `note.example.com` 替换为你的域名,再启用 HTTPS 配置: ```bash sudo cp deploy/nginx-https.conf /etc/nginx/conf.d/love-note.conf sudo nginx -t sudo systemctl reload nginx ``` 浏览器最终访问: ```text https://你的域名 ``` ## 开发备注 - 房间数据暂存在内存中,服务重启后会清空。 - 一个房间最多缓存约两万条绘制事件,超过后会丢弃最旧的一部分。 - 第一版没有账号系统。邀请码相当于共享密码,请使用不容易猜到的组合。 - 页面由 Nginx 提供,`/ws` 会被代理到 C++ WebSocket 服务。