一、vultr能够用微信或支付宝充值,方便。好像推荐别人用还能挣美分,懒得弄了,参加了一个充10刀送50刀的活动,感受实惠(实际用时感受有点小贵)。html
二、注册登陆后,控制面板上billing可查看余额。servers中可部署操做系统,我部署了一个最便宜的Centos7(能够部署多个,我部署完查看余额少了1美分)linux
三、部署的server名最右边有三个点,点击后的菜单中有View Console,是一个运行在浏览器中的Consol。(点开部署的server,能够找到用户名root和密码),登陆View Console后进入了远程的centos7系统中了。golang
四、输入uname -a 无效; 输入:file /bin/ls 有了x86-64字样 ; 输入cat /etc/os-release,有了centos 7的字样web
五、输入yum 或wget 或 rpm 或vi (在vi中用 :q 退出)都有,OK!shell
六、直接 yum install golang 安装成功。 输入go version 查看go版本。输入whereis go 和whereis golang 查看安装位置windows
七、从本地windows向centos7传文件,看了下xshell 收费。仍是用putty (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html),安装运行.centos
安装putty目录中还有个PuTTygen ,首先用它生成(运行后晃动鼠标生成)SSH key (https://www.vultr.com/docs/how-do-i-generate-ssh-keys/),浏览器
而后点save private key,再将public key的所有内容复制server的SSH key中保存。用putty链接后发现仍是不能上传下载文件,还要用安装WinSCP或者Filezilla。感受putty与View Console没区别。忽然发现putty目录中有psftp ,运行后按提示open ,链接成功,可在远程用ls cd 等命令查看了。微信
八、在psftp中,运行 get xxx 就将xxx 从远程下载到psftp所在目录中了。将如下代码保存为main.go,并放到psftp目录中ssh
package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", IndexHandler) http.ListenAndServe(":9090", nil) } func IndexHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "hello world!!!") }
执行 put main.go,上传到了远程的/usr/bin/main.go;而后执行go run main.go 不行。
九、用liteide将上面的main.go交叉编译为linux64程序,名为gohttphello。再用psftp上传后,用 chmod +x gohttphello 加上执行权限,
用 ./gohttphello 运行,提示Text file busy , 先用yum install psmisc 来安装 fuser ,而后 fuser gohttphello 无效果。从新./gohttphello无效
十、从新用psftp上传 put main.go ,而后在putty中 go build -o gohello main.go ,再./gohello ,看到程序运行了(我在代码中加一句控制台输出),但经过浏览器远程没法访问。
十一、经过View Console执行 firewall-cmd --state ,显示防火墙running ;用systemctl stop firewalld.service ,而后http://X.X.X.X(远程IP),终于成功显示出hello world!!!
十二、最后:用systemctl start firewalld.service 重启防火墙 .用如下命令开放9090端口
输入 nohup gohello & 使程序在后台运行
用 ps a 查看当前终端下的全部进程信息,包括其余用户的进程。
用kill -9 PID数字 结束进程
firewall-cmd --get-active-zones (无显示,应该是zone为空) firewall-cmd --zone=public --add-port=9090/tcp --permanent (永久开放9090端口) firewall-cmd --reload (重启防火墙) firewall-cmd --query-port=9090/tcp (查看端口是否开放)
参考:(一并致谢)
http://www.javashuo.com/article/p-quuijtaa-dc.html
http://www.javashuo.com/article/p-bpvpzhbc-et.html
http://www.javashuo.com/article/p-hnsvtled-em.html
https://blog.csdn.net/bihailan123/article/details/80067663
http://www.javashuo.com/article/p-yerqqdxp-eb.html
https://blog.csdn.net/iw1210/article/details/16862147
https://blog.csdn.net/Evan_QB/article/details/79811949
http://www.javashuo.com/article/p-ooekqyac-hk.html