因为在服务器上部署了hexo,每次又不想在本地再pull一份下来修改,就在服务器上又部署了一个code-server,这样就可以直接在网页修改代码,然后发布到github上,方便快捷,如果有点什么开发也可以直接网页调试,无需远程调试了。在部署的时候碰到几个问题,这里记录一下。
服务端口被占用
因为在服务器上安装了很多服务,例如像127.0.0.1:8080端口早就被别的服务占用了
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
sudo dpkg -i code-server_${VERSION}_amd64.deb
sudo systemctl enable --now code-server@$USER
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
systemctl status报错如下:
root@kubernetes-master:/# systemctl status code-server@root
× code-server@root.service - code-server
Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2024-02-05 09:52:00 CST; 37min ago
Main PID: 3855609 (code=exited, status=1/FAILURE)
CPU: 892ms
Feb 05 09:52:00 kubernetes-master systemd[1]: code-server@root.service: Scheduled restart job, restart counter is at 5.
Feb 05 09:52:00 kubernetes-master systemd[1]: Stopped code-server.
Feb 05 09:52:00 kubernetes-master systemd[1]: code-server@root.service: Start request repeated too quickly.
Feb 05 09:52:00 kubernetes-master systemd[1]: code-server@root.service: Failed with result 'exit-code'.
Feb 05 09:52:00 kubernetes-master systemd[1]: Failed to start code-server.
但是这时配置文件也没有生成,查看service文件也没有提示有配置文件
~ cat /lib/systemd/system/code-server@.service
[Unit]
Description=code-server
After=network.target
[Service]
Type=exec
ExecStart=/usr/bin/code-server
Restart=always
User=%i
[Install]
WantedBy=default.target
这时尝试手工执行code-server命令,就会在用户目录下生成.config文件夹了,这时的报错也比较明显了:
~ code-server
[2024-02-05T02:30:25.326Z] info Wrote default config file to /root/.config/code-server/config.yaml
[2024-02-05T02:30:25.687Z] info code-server 4.20.1 e76afa4a2bf4667a3c9f71bf56ef34b8ad365fbe
[2024-02-05T02:30:25.687Z] info Using user-data-dir /root/.local/share/code-server
[2024-02-05T02:30:25.692Z] error listen EADDRINUSE: address already in use 127.0.0.1:8080
这时只需要去修改/root/.config/code-server/config.yaml文件,修改绑定的地址和端口就可以了。
PS:也可能是我之前装了又删了导致,可能没有可复现性,而且既然装好了,自然也就不再折腾了
domain.name/code页面提示报错
nginx的配置是这样的:
location /code/ {
proxy_pass http://127.0.0.1:9000;
# sendfile off;
add_header X-debug-message "/code/" always;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/code/(.*) /$1 break;
}
报错是:
An unexpected error occurred that requires a reload of this page.
The workbench failed to connect to the server (Error: WebSocket close with status code 1006)
加上以下3行即可:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
自带的terminal不能使用之前的alias,不能使用方向键
直接使用bash就可以了,反正部署在云端,24小时不关机,bash一下,以后无忧。