[Linux environment configuration] 7. Linux deployment code-server

Install code-server

There are two methods, one is online installation and the other is local installation. Because the host may report a 443 error when accessing github, I recommend using the local installation method here !

local installation method

Enter github, search code-server to find the project address: https://github.com/coder/code-server/releases

Find the version suitable for your own system and download
insert image description here
it. After downloading, use the ftp tool to transfer it to the host to be deployed. I am using FileZilla, and after linking to the host IP, drag the file directly into it.

Then enter the corresponding directory on the host and tarexecute the command to decompress.

tar -zxvf code-server-4.10.0-linux-amd64.tar.gz -C .

For tarthe use of commands, you can read this article: [Linux study notes] 9. Linux packaging and decompression command tar .

insert image description here

Online installation method

From the readme.md file of the github project address, you can see the installation command:
insert image description here

Enter the following command in the terminal to automatically complete the download, installation and startup

curl -fsSL https://code-server.dev/install.sh | sh

Deploy code-server

Enter the code-server directory installed earlier, you can see:

There is a code-server executable program in the bin directory, enter

./bin/code-server

The code-server service can be started.

After the first startup, a ~/.config/code-server/config.yamlfile will be generated in the home directory. Press Ctrl+C to stop the service.

Next, configure the external network access function.

vim ~/.config/code-server/config.yaml

Modify the bind-addr field and password field:

bind-addr: 0.0.0.0:{
    
    让哪个端口运行code-server}
auth: password
password: {
    
    设置登陆密码}
cert: false

insert image description here
re-enter

./bin/code-server &

It is possible to run code-server in the startup background.

Telnet

In two cases

  • If it is your own device (such as Raspberry Pi, virtual machine, etc.) under the LAN, use the intranet to log in.
  • If it is a purchased cloud server (such as Tencent Cloud, Alibaba Cloud, etc.), use the public network to log in.

Intranet login

ifconfigEnter to view the host ip at the host terminal where the code-server is deployed .

Enter the host ip: port obtained above in the local computer browser, for example 192.168.123.123:8080, you can access the host.

insert image description here

Public network login

4.12.123.1:8080If you are using a cloud server to deploy code-server, assuming that the server's public network ip is 4.12.123.1, then you cannot directly access the server by typing in the browser according to the above method.

Custom ports also need to be released in the server security group, and the system firewall also needs to be released .

insert image description here
As shown in the figure above, 0.0.0.0/0 means to listen to all IPs, and the port 8888 should be ~/.config/code-server/config.yamlthe same as that set in the previous file. For example, if the port I entered earlier is 8080, just change the port 8888 in the figure above to 8080.

At this point, the code-server deployment of the server is completed, open your computer browser, enter the server public network ip: port, such as: , you can enter the 43.xx.xxx.x:8888login interface, and then enter the user name and password to enter the web version vscode is up.
insert image description here

Configure autostart

Execute the following command to enable code-server to start automatically

sudo systemctl enable code-server@$USER

Configure the resident background

Install using package manager

# Ubuntu 、 Debian
sudo apt-get install tmux
# CentOS 、 Fedora
sudo yum install tmux

create new session

tmux new -s vscode_online

Execute the code-server start command in that session

bin/code-server --port 8888 --host 0.0.0.0 --auth password

In the above command, bin/code-serveryou need to change it to your own path. I use an absolute path.

After running the above command in this session, the code-server starts to run. At this time, you can press ctrl+b, and then press d to exit the session. When needed, you can tmux attachreturn to this session by typing in the terminal.

In this way, the service can stay in the background and can be accessed at any time. Use the following commands to view/close the service

# 接入会话
tmux a -t vscode_online
# 结束会话
tmux kill-session -t vscode_online

Refer to Deploying code-server from a server .

uninstall code-server

First stop the code-server service

sudo systemctl stop code-server@$USER

Execute the following command to delete all related files to complete the uninstallation

rm -rf /usr/lib/code-server
rm -rf ~/.local/share/code-server
rm -rf ~/.config/code-server

Reference: Ubuntu Linux installation and deployment code-server online code writing environment (including uninstallation tutorial)

Guess you like

Origin blog.csdn.net/weixin_45636061/article/details/129227186