Table of contents
Recently I have been developing service engines, and compilation is done in the server environment. It is troublesome to use vim every time for debugging.To modify. Finally, I found that I can use the graphical interface for remote development and debugging. I tried it and it worked, so I recorded it for next time. linux
gdb
vscode
1. Set upvscode
remote development process
vscode
The process of setting up a remote development environment is very simple. Generally speaking, it is divided into four steps (as shown below):
- Installation under host environment (windows)
vscode
- Install plug-ins in the host environment, permanently connect remotely, etc.
- Installation in remote environment (linux)
vscode-server
- Install remote environment plug-ins for development and debugging, etc.
Understanding this construction process, you can better understand the role of each step. The following operations are all centered around these four steps.
2. Build environment online
-
Download one for local environment
vscode
Installation -
Install plug-ins to connect to remote servers in the plug-in market
Remote-SSH
andRemote - SSH: Editing Configuration Files
The plug-in is installed
vacode
There will be a computer icon in the left column
-
Connect to remote environment
3.1. Configuring the server environment
As shown in the picture above, open the remote plug-in, and the remote connection configuration file will pop up.
As shown above, you can see that the configuration file contains the following attributes:
>Host:服务器名称
>
>HostName: 服务器ip
>
>Uer:登录用户名
>
>Port: ssh默认是22端口,如果不确定是否为22可不写。
3.2. Connecting to the server
Complete the above steps, re-enter vscode to open the remote plug-in, and you can see the server device you just added. To connect to the server, you need to select the server system and enter the password to open the server folder you want to operate.
Select the folder you want to open to perform visual editing operations.
Note: You need to wait for a while when connecting to the server. During this period, the server will automatically download and install vscode-server based on the local vscode version. and connect to the client. You can find that a .vscode-server or .vscode-server-insiders folder is generated in the server's file home (depending on the type of vsCode installed on the server)~/
-
Server environment installation plug-in
Due to the need for programming development, the corresponding help plug-in needs to be installed. For example, if I develop C++, I need to install the C/C++ plug-in.
Previously installed plug-ins are available locally in the host environment. The environment of vscode-server and the local environment are independent of each other, and plug-ins need to be installed in their respective environments before they can be used. Remote development uses plug-ins in the vscode-server environment. So it needs to be installed separately. Install the plug-in for vscode-server in a network environment just like vscode from the plug-in market.
Once the plug-in is installed, you can enjoy cross-platform visual development.
3. Build environment offline
Installation is relatively simple when there is a network, but many companies develop on the internal network and cannot access the external network. Automatic download and installation cannot be done. At this time, we need to install offline. The essence is to manually download the corresponding server and plug-in for manual installation. The whole process is also Same as above, please refer to the online installation steps:
-
Download and install vscode
Official version (stable) vscode download: https://code.visualstudio.com/
-
Download and install the plug-in
Official plug-in download address: https://marketplace.visualstudio.com/VSCode
Enter the official plug-in website and enter remote to search for the plug-in. DownloadRemote-SSH
andRemote - SSH: Editing Configuration Files
,
After downloading the plug-in, install the plug-in manually. The manual installation plug-in process is as follows. Select the plug-in downloaded in the previous step to install it.
- Download and install vscode-server
At this time, the vscode of the local host environment has been configured. Before installing vscode-server, use vscode to remotely connect to the server. The remote connection without a network will definitely fail. However, the .vscode-server or .vscode-server-insiders file will be generated in the server. folder.
As introduced during online installation, the server will automatically download and install vscode-server when connecting remotely. The download failed because it cannot connect to the network. However, the folder corresponding to the version number has been created. You can see it a>There is a folder named by id under ~/vscode-server/bin
.
With this ID, you can download it to the corresponding version of vscode-server. Use the ID to replace the ID in the link below.
stable 版本 VsCode : https://update.code.visualstudio.com/commit:ID/server-linux-x64/stable
insiders 版本 VsCode : https://update.code.visualstudio.com/commit:ID/server-linux-x64/insider
Copy the downloaded package to the ~/vscode-server/bin/id/
folder and unzip it.
At this point, the installation of offline vscode-server is completed and remote connection can be made.
-
Download and install the vscode-server plug-in
-
Go to the plug-in official website to download the corresponding plug-in, copy it to the server, install the plug-in manually, and refer to the host environment plug-in installation.
-
Still give the server the same Internet access as the server, install vscode-serve and the corresponding plug-in online, and manually copy the
~/vscode-serve
folder to the intranet server. If you only want to copy the plug-in, you can copy~/vscode-serve/extensions
That’s it.
-
4. SSH password-free login and set whitelist
In order to avoid entering the password every time you log in, you can add the host public key to the server whitelist.
The host public key is generated using git. Copy the public key to the server authentication file authorized_keys , you can realize automatic verification every time you log in.
cd ~
mkdir .ssh
mv id_rsa.pub .ssh
cd .ssh
cat id_rsa.pub >> authorized_keys
sudo chmod 600 authorized_keys
service sshd restart
5. Reference documents:
- https://mp.weixin.qq.com/s?__biz=MzU3MzkzMzEyMg==&mid=2247483742&idx=1&sn=16071b0444ec679f9617407249045b4c&scene=21#wechat_redirect
- https://mp.weixin.qq.com/s/JcfHSQDdhR0BM93M1sBCdA