code-server安装使用

coder-server提供一个在线IDE,界面和vscode一模一样。其公司coder之前本身就提供IDE的在线使用(ide.coder.com),但不知道什么原因,网站的该功能已经关闭了。
现在只能以自建的形式使用:将code-server远程部署在服务器上,在任何浏览器上使用网页版VScode。

官网:http://www.coder.com/
github:https://github.com/cdr/code-server

一、安装:

1、下载、解压:

#环境
$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

cd /usr/local
#github上的下载连接:https://github.com/cdr/code-server/releases,根据不同环境下载二进制解压即可使用。
wget https://github.com/cdr/code-server/releases/download/3.4.1/code-server-3.4.1-linux-x86_64.tar.gz

tar -xvzf code-server-3.4.1-linux-x86_64.tar.gz

2、启动:

pwd
/usr/local
cd code-server-3.4.1-linux-x86_64
./code-server
***** Please use the script in bin/code-server instead!
***** This script will soon be removed!
***** See the release notes at https://github.com/cdr/code-server/releases/tag/v3.4.0
info  Using config file ~/.config/code-server/config.yaml
info  Using user-data-dir ~/.local/share/code-server
info  code-server 3.4.1 48f7c2724827e526eeaa6c2c151c520f48a61259
info  HTTP server listening on http://127.0.0.1:8080
info      - Using password from ~/.config/code-server/config.yaml
info      - To disable use `--auth none`
info    - Not serving HTTPS

在windows的浏览器上输入:http://remoteip:8080 后没有反应, code-server没有输出任何错误。所以,怀疑是这种方式的启动,只能在远程linux的本地通过浏览器访问,无法在windows的浏览器上访问,无奈远程linux没有窗口界面,输入--help查询看是否有其他参数:

./code-server --help
***** Please use the script in bin/code-server instead!
***** This script will soon be removed!
***** See the release notes at https://github.com/cdr/code-server/releases/tag/v3.4.0
info  Using config file ~/.config/code-server/config.yaml
code-server 3.4.1 48f7c2724827e526eeaa6c2c151c520f48a61259

Usage: code-server [options] [path]

Options
      --auth                The type of authentication to use. [password, none]
      --password            The password for password authentication (can only be passed in via $PASSWORD or the config file).
      --cert                Path to certificate. Generated if no path is provided.
      --cert-key            Path to certificate key when using non-generated cert.
      --disable-telemetry   Disable telemetry.
   -h --help                Show this output.
      --open                Open in browser on startup. Does not work remotely.
      --bind-addr           Address to bind to in host:port. You can also use $PORT to override the port.
      --config              Path to yaml config file. Every flag maps directly to a key in the config file.
      --socket              Path to a socket (bind-addr will be ignored).
   -v --version             Display version information.
      --user-data-dir       Path to the user data directory.
      --extensions-dir      Path to the extensions directory.
      --list-extensions     List installed VS Code extensions.
      --force               Avoid prompts when installing VS Code extensions.
      --install-extension   Install or update a VS Code extension by id or vsix.
      --uninstall-extension Uninstall a VS Code extension by id.
      --show-versions       Show VS Code extension versions.
      --proxy-domain        Domain used for proxying ports.
 -vvv --verbose             Enable verbose logging.

于是,使用下面方式启动:(也可以使用./code-server --port 8888 --host 0.0.0.0)

./code-server --bind-addr 0.0.0.0:8888
***** Please use the script in bin/code-server instead!
***** This script will soon be removed!
***** See the release notes at https://github.com/cdr/code-server/releases/tag/v3.4.0
info  Using config file ~/.config/code-server/config.yaml
info  Using user-data-dir ~/.local/share/code-server
info  code-server 3.4.1 48f7c2724827e526eeaa6c2c151c520f48a61259
info  HTTP server listening on http://0.0.0.0:8888
info      - Using password from ~/.config/code-server/config.yaml
info      - To disable use `--auth none`
info    - Not serving HTTPS

 在windows的浏览器上即可访问了。初次访问,需要输入登录密码,在命令行输出上粘贴即可。

code-server安装使用_第1张图片

为了不让ssh会话断开重新登陆,可以使用nohup ./code-server --bind-addr 0.0.0.0:8888 >/dev/null 2>&1 & 来启动。或者安装一个Screen软件,Screen可以建立如Windows多任务的效果进行切换并且不会因为SSH断开而导致code-server自动退出。

有一个疑问:为什么code-server的浏览器界面和桌面版的vscode如此相似(不,应该说是一模一样),而且在使用上也是一样额,要做到这中模仿基本上是不可能。不过想到vscode是一个开源项目,也有可能coder公司将其代码翻译成web版本...直到有一天,看了这篇文章,才知道真正的原因https://blog.csdn.net/liuxiao723846/article/details/107051209

二、使用:

code-server在使用上和vscode一模一样,早期的code-server还不支持在线安装插件,不过它提供了.VSIX方式的安装,目前版本已经支持在线商店安装插件了。

1、git版本升级:

远程linux上如果git的版本比较低,code-sever在浏览器上也会提示,要求升级。linux上升级git见:https://blog.csdn.net/liuxiao723846/article/details/106940099

 

 

参考:

https://juejin.im/post/5e2dd4566fb9a02fb75d6975

补充:

在coder官网上看到,除了code-server之外,他们还提供了一个sshcode的项目(https://github.com/cdr/sshcode),大概看了介绍,应该是通过ssh的方式远程连接服务,然后提供在线IDE功能。(code-server是通过http+密码的方式和远程建立连接的)

你可能感兴趣的:(web前端)