Skip to content

Commit 288132d

Browse files
committedDec 4, 2018
add note
1 parent bda713f commit 288132d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
7.Linux环境go部署安装
2+
===
3+
4+
使用阿里云服务器
5+
6+
通过mac上的shell命令连接远程服务器
7+
```shell
8+
ssh 用户名@云主机ip
9+
// 如阿里云的是
10+
ssh root@120.xx.xx.xx
11+
```
12+
然后输入连接密码和实例密码即可。
13+
14+
想要退出ssh的连接可以执行exit命令。
15+
16+
- 安装go
17+
18+
去官网选择下载的版本,获取下载地址:
19+
[Golang Downloads](https://golang.org/dl/)
20+
21+
```shell
22+
wget https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz
23+
```
24+
下载完成后
25+
```shell
26+
tar zxvf go1.11.2.linux-amd64.tar.gz
27+
mv go /usr/local/
28+
cd /usr/local/go/
29+
vim /root/.bashrc
30+
```
31+
32+
然后添加一下内容:
33+
```
34+
###########
35+
#go
36+
export GOROOT=/usr/local/go
37+
export GOPATH=/data/server/go
38+
export PATH=$PATH:$GOROOT/bin
39+
###########
40+
```
41+
重启虚拟机或者执行source /root/.bashrc
42+
然后执行:
43+
```shell
44+
go env
45+
```
46+
即可查看配置
47+
48+
上面我们将GOPATH设置成了/data/server/go,这里我们先创建该目录,然后在go目录里面分别创建pkg、src、bin目录,以后就需要将我们要部署的go应用的源代码拷贝到src目录中。
49+
50+
本地dos执行:
51+
```shell
52+
scp -r main.go 用户名@云主机地址:/data/server/go/src
53+
// 如阿里云的为
54+
scp -r main.go root@1xx.xx.xx.xxx:/data/server/go/src
55+
```
56+
57+
然后登陆到远程服务器,首先去下载程序所有的依赖包:
58+
```shell
59+
go get "github.com/astaxie/beego"
60+
```
61+
62+
然后安装程序
63+
```shell
64+
cd data/server/go/src/
65+
go build main.go
66+
// 然后会生成本地可执行的二进制文件main,执行./main可运行,执行下面的命令可以后台运行
67+
nohup ./main &
68+
```
69+
70+
这个时候会发现还访问不了,这是因为默认情况下阿里云值允许内网访问,我们要修改安全组规则,将其设置为全局可以访问。
71+
<img src="https://raw.githubusercontent.com/CharonChui/Pictures/master/aliyun_safe_setting.png?raw=true" width="50%"/>
72+
73+
然后重启即可。
74+
75+
76+
当然这样只是简单的开启了服务器,如果要保证进程的存活性,可以用上一篇文章说的[日志和部署中的Supervisord](https://github.com/CharonChui/GolangStudyNote/blob/master/Golang%E8%BF%9B%E8%A1%8CWeb%E5%BC%80%E5%8F%91/6.%E6%97%A5%E5%BF%97%E5%92%8C%E9%83%A8%E7%BD%B2(%E5%85%AD).md)
77+
78+
- [上一篇:6.日志和部署](https://github.com/CharonChui/GolangStudyNote/blob/master/Golang%E8%BF%9B%E8%A1%8CWeb%E5%BC%80%E5%8F%91/6.%E6%97%A5%E5%BF%97%E5%92%8C%E9%83%A8%E7%BD%B2(%E5%85%AD).md)
79+
80+
---
81+
82+
- 邮箱 :charon.chui@gmail.com
83+
- Good Luck!

0 commit comments

Comments
 (0)