背景
目前在公司运维开发中逐步使用golang作为首选语言,同时使用vscode+插件作为开发环境,最近的一个项目就是用beego开发的,目前使用的数据量和goroutine都比较大了,办公机已经开始变得比较卡,所以今天研究一下vscode的remote ssh+golang环境设置。
Centos7 Server 配置
安装go环境
# wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz
# tar -C /usr/local -xzf go1.12.7.linux-amd64.tar.gz
# echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/golang.sh
升级git2.x,vscode推荐用git 2.x
# yum remove git -y
# yum install -y https://centos7.iuscommunity.org/ius-release.rpm
# yum -y install git2u-all gitflow
# git version
git version 2.16.5
配置用户环境
# useradd xxx
# passwd xxx 这里配置用户xxx的密码
# su - xxx
$ mkdir -p go/{src,bin,pkg}
$ echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.bash_profile
$ echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
配置git https免密
$ echo 'https://username:password@gitlab.domain' > ~/.git-credentials
$ git config --global credential.helper store --file ~/.git-credentials
下面配置git让其和windows git提示符一致,如果不需要可以跳过
$ wget -O .git-completion.bash https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
$ wget -O .git-prompt.sh https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
$ echo 'export ~/.git-completion.bash' >> ~/.bashrc
$ echo 'export ~/.git-prompt.sh' >> ~/.bashrc
$ echo "export PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '" >> ~/.bashrc
部署代码和工具
$ cd go/src/
$ git clone https://gitlab.domain/xxx/projectname
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh # install dep tool
$ go get github.com/beego/bee # install beego bee
$ cd projectname
$ dep ensure # run dep ensure download dependency
办公机配置
配置ssh免密登录
# 在办公机上运行
ssh-copy-id xxx@centos7_server_ip
vscode配置
- 安装vscode-remote-extensionpack
2. 配置ssh server
配置ssh server
3. 安装扩展
安装扩展
好了,现在开始coding