GoLand远程调试在Multipass上部署Ubuntu应用

4 篇文章 0 订阅

1. 远程调试结构

在这里插入图片描述
本地机器与远程机器通过SSH连接。

local
remote
远程启动Delve
远程Ubuntu 安装 Go
本地GoLand配置Remote Debugging
远程Ubuntu安装Delve
同步本地与远程程序
本地GoLand配置Deployment
远程Ubuntu配置SSH
本地Multipass launch Ubuntu实例go-gdal
本地安装Multipass

1.1 本地机器

Windows 10

1.2 远程机器

在Windows 10上安装部署的Ubuntu虚拟机。

2. 远程机器环境配置

2.1 SSH

设置SSH。

2.1.1 检查SSH状态

$ ps -e | grep ssh
root@test:~# ps -e | grep ssh
   2511 ?        00:00:00 sshd
   2628 ?        00:00:00 sshd
   3466 ?        00:00:00 sshd
   3467 ?        00:00:00 sshd
   3553 ?        00:00:00 sshd
   3555 ?        00:00:00 sshd

2.1.2 安装SSH服务

2.1.3 启动SSH服务

$ sudo /etc/init.d/ssh start

$ sudo systemctl start ssh

2.1.4 修改SSH配置文件

编辑配置文件

$ sudo vi /etc/ssh/sshd_config

修改配置文件:

修改

PermitRootLogin withou-password
...
PasswordAuthentication no
...

为:

PermitRootLogin yes
...
PasswordAuthentication yes
...

2.1.5 重启SSH服务

$ sudo systemctl restart ssh

2.2 安装Go

2.2.1 下载go

go1.16.linux-amd64.tar.gz

2.2.2 解压至/usr/local下

$ tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin

2.3 安装Delve

2.3.1 下载Delve

$ cd /home/ubuntu
$ mkdir software
$ cd /home/ubuntu/software/
$ git clone https://github.com/go-delve/delve

2.3.2 安装Delve

$ cd /home/ubuntu/software/delve/cmd/dlv
$ go build
$ cp dlv /usr/local/bin
$ dlv version
Delve Debugger
Version: 1.6.0
Build: $Id: 8cc9751909843dd55a46e8ea2a561544f70db34d $

3. 本地机器环境配置

3.1 安装GoLand

GoLand,安装在Windows上,作为客户端。

3.2 安装Multipass

安装Multipass虚机,部署Ubuntu,作为远程机器。

下载multipass-1.6.2+win-win64.exe,并安装。

C:\Users\Administrator>multipass find
Image                       Aliases           Version          Description
core                        core16            20200818         Ubuntu Core 16
core18                                        20200812         Ubuntu Core 18
snapcraft:core18                              20201111         Snapcraft builder for Core 18
snapcraft:core20                              20201111         Snapcraft builder for Core 20
16.04                       xenial            20210224         Ubuntu 16.04 LTS
18.04                       bionic            20210224         Ubuntu 18.04 LTS
20.04                       focal,lts         20210223         Ubuntu 20.04 LTS
20.10                       groovy            20210303         Ubuntu 20.10
appliance:adguard-home                        20200812         Ubuntu AdGuard Home Appliance
appliance:mosquitto                           20200812         Ubuntu Mosquitto Appliance
appliance:nextcloud                           20200812         Ubuntu Nextcloud Appliance
appliance:openhab                             20200812         Ubuntu openHAB Home Appliance
appliance:plexmediaserver                     20200812         Ubuntu Plex Media Server Appliance

安装Ubuntu 20.04

$ multipass launch 20.04 --name go-gdal

3.3 查看远程机器IP地址

multipass info -all
C:\Users\Administrator>multipass info --all
Name:           test
State:          Running
IPv4:           172.18.146.95
Release:        Ubuntu 20.04.2 LTS
Image hash:     bba6582030e5 (Ubuntu 20.04 LTS)
Load:           0.08 0.02 0.01
Disk usage:     1.7G out of 4.7G
Memory usage:   463.0M out of 916.9M

3.4 测试远程机器IP地址(ping)

$ ping 172.18.146.95
C:\Users\Administrator>ping 172.18.146.95

正在 Ping 172.18.146.95 具有 32 字节的数据:
来自 172.18.146.95 的回复: 字节=32 时间<1ms TTL=64
来自 172.18.146.95 的回复: 字节=32 时间=1ms TTL=64
来自 172.18.146.95 的回复: 字节=32 时间<1ms TTL=64
来自 172.18.146.95 的回复: 字节=32 时间<1ms TTL=64

172.18.146.95 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 1ms,平均 = 0ms

3.5. GoLand配置

3.5.1 FTP/SFTP Connectivity

要远程调试,需要本地与远程之间的连接与同步。在GoLand中需要安装FTP/SFTP Connectivity插件。
在这里插入图片描述

3.5.2 Deployment

Tool --> Deployment --> Configurations…

配置远程部署,使用SFTP类型。
在这里插入图片描述

3.5.3 SSH配置

在这里插入图片描述Host为远程Ubuntu的地址(IP地址,或Multipass的名称),由于每次Multipass启动Ubuntu后,IP地址都会改变,所以最好使用名称。
例如,根据前面Multipass安装Ubuntu时,通过–name参数,给定的名称为go-gdal,则此处的Host可设置为:go-gdal.mshome.net

3.5.4 目录映射(Mappings)

建立远程路径与本地路径之间的映射关系。
在这里插入图片描述

4. 远程Ubuntu运行Delve

$ cd /root/go/src/img/src
root@go-gdal:~/go/src/img/src# ls
go.mod  goroutine1  goroutine1.go  m
root@go-gdal:~/go/src/img/src# dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient goroutine1.go
API server listening at: [::]:2345

在这里插入图片描述

5. 本地Windows运行GoLand

5.1 配置远程调试(Remote Debugging)

在这里插入图片描述

5.2 运行本地远程调试

在本地(Windows 10)上运行GoLand的远程调试。
在这里插入图片描述
运行本地远程调试后,会在断点处挂起。
在这里插入图片描述

参考

[1] 解决ubuntu下SSH无法连接的问题
[2] goland远程调试
[3] goland 调试docker容器中的go代码
[4] goland连接linux主机进行dlv远程调试
[5] Overview of Remote Debugging
[6] 如何在Ubuntu 20.04上安装Go
[7] ubuntu安装go语言调试器dlv
[8] win10下goland&dlv&docker打造远程断点调试环境
[9] 在GoLand中使用Docker插件生成镜像与创建容器
[10] docker安装ubuntu镜像

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值