自动摘要
正在生成中……
安装
用官方提供的在线脚本安装
curl -fsSL https://code-server.dev/install.sh | sh
使用当前用户启动
sudo systemctl enable --now code-server@$USER
查看systemd日志可以看到
systemctl status code-server@$USER
● code-server@root.service - code-server
Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-09-23 15:35:39 CST; 2s ago
Main PID: 2155531 (node)
Tasks: 22 (limit: 4649)
Memory: 96.2M
CGroup: /system.slice/system-code\x2dserver.slice/code-server@root.service
├─2155531 /usr/lib/code-server/lib/node /usr/lib/code-server
└─2155574 /usr/lib/code-server/lib/node /usr/lib/code-server/out/node/entry
Sep 23 15:35:39 txhk systemd[1]: Starting code-server...
Sep 23 15:35:39 txhk systemd[1]: Started code-server.
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.471Z] info code-server 4.7.0 7f108c61ab670ccaae4cfde5de2909c003db1ce8
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.472Z] info Using user-data-dir ~/.local/share/code-server
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.497Z] info Using config file ~/.config/code-server/config.yaml
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.497Z] info HTTP server listening on http://127.0.0.1:8848/
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.497Z] info - Authentication is enabled
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.498Z] info - Using password from ~/.config/code-server/config.yaml
Sep 23 15:35:40 txhk code-server[2155531]: [2022-09-23T07:35:40.498Z] info - Not serving HTTPS
从这里可以看到用户数据目录、配置文件(在这里配置监听的端口、密码)。
#cat ~/.config/code-server/config.yaml
bind-addr: 127.0.0.1:8848
auth: password
password: 你的密码
cert: false
修改端口密码等配置后记得重启
sudo systemctl restart code-server@$USER
配置HTTPS
不配置 https 很多功能会受限,配置证书后,使用 nginx 反代如下:
server {
listen 127.0.0.1:4430 ssl http2;
listen 443 ssl http2;
server_name example.com; #修改为自己的域名
location / {
proxy_pass http://localhost:8848/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
...
访问 https://example.com 可以进入 code server 网页。
安装更新
收到更新提醒后,再次运行安装时的脚本,重启code server 进程即可。
curl -fsSL https://code-server.dev/install.sh | sh
systemctl daemon-reload && systemctl restart code-server@$USER
更新2023.03.30
如果不是使用网站根目录,而是其他子目录,比如 /code/ 目录,并且只允许特定ip连接,nginx配置需要这样修改:
location /code/ {
allow 127.0.0.1;
allow 1.2.3.4;
allow 192.168.0.0/24;
deny all;
proxy_pass http://localhost:8848/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
卸载
你可以直接使用 rm -r
命令删除 code-server
目录或二进制文件。它的安装位置取决于你在哪里安装的,但如果你使用的是默认的安装脚本,位于 /usr/lib/code-server
同时还会在 /usr/bin/code-server
中有一个可以删除的二进制符号链接。
如果你还想删除设置和数据,你可以删除 ~/.local/share/code-server
和 ~/.config/code-server
。
参考资料:
- https://github.com/coder/code-server