centos7环境安装go语言环境+beego框架运行使用流程步骤

2023-06-01 00:00:00 框架 环境 步骤

一.安装go环境

1.下载go语言安装包

wget https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz

2.解压至/use/local/ 目录下

tar -C /usr/local/ -xzf go1.15.6.linux-amd64.tar.gz

3.创建及编辑配置文件 指定go的PATH路径

vim /etc/profile.d/go.sh
输入配置:
export PATH=$PATH:/usr/local/go/bin

4.让配置文件生效

source /etc/profile.d/go.sh

5.go环境就安装完了,看看效果

[[email protected] ~]# go version
go version go1.15.6 linux/amd64

二.安装beego框架

1.创建go项目目录/home/goblog/src/

2.设置配置文件

vim /etc/profile.d/go.sh

输入配置:

export GOROOT=/usr/local/go
export GOPATH=/home/goblog
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:$GOBIN
export GO111MODULE="on"
export GOPROXY="https://goproxy.io"

3.让配置文件生效

source /etc/profile.d/go.sh

4.下载beego包及bee包

[[email protected] ~]# cd /home/goblog/
[[email protected] goblog]# go get github.com/astaxie/beego
go: downloading github.com/astaxie/beego v1.12.3
go: github.com/astaxie/beego upgrade => v1.12.3
...
[r[email protected] goblog]# go get github.com/beego/bee
go: downloading github.com/beego/bee v1.12.3
go: github.com/beego/bee upgrade => v1.12.3
...

4.创建go项目,使用bee

[[email protected] ~]# cd $GOPATH/src
[[email protected] src]# ll
total 0
[[email protected] src]# bee new test
2021/01/07 13:46:31 INFO     ▶ 0001 Getting bee latest version...
2021/01/07 13:46:32 WARN     ▶ 0002 Update available 1.12.0 ==> 2.0.2
...
2021/01/07 13:46:32 SUCCESS  ▶ 0007 New application successfully created!

5.运行beego框架

[[email protected] src]# cd test/
[[email protected] test]# go run main.go
go: finding module for package github.com/shiena/ansicolor
go: downloading gopkg.in/yaml.v2 v2.2.1
go: downloading github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
go: found github.com/shiena/ansicolor in github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
2021/01/07 13:48:45.473 [I] [asm_amd64.s:1374]  http server Running on http://:8080

6.配置nginx , 创建配置文件:/use/local/nginx/conf/vhost/goblog.conf ,并添加一下配置信息

server {
    listen       80;
    server_name  go.zongscan.com;
    charset utf-8;
    access_log  /home/wwwlogs/go.log;
    location /(css|js|fonts|img)/ {
        access_log off;
        expires 1d;
        root "/gblog/static";
        try_files $uri @backend;
    }
    location / {
        try_files /_not_exists_ @backend;
    }
    location @backend {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            $http_host;
        proxy_pass http://127.0.0.1:8080;
    }
}

7.添加解析,如果有购买域名直接用,如果没有的话就本地解析,添加hosts文件信息

windows7: C:\Windows\System32\drivers\etc 

ip地址   go.zongscan.com

8.访问一下

1.png

相关文章