1、獨立部署
GF
*nixLinuxMacOS*BSDUbuntuGF
nohup
nohupnohup
nohup ./gf-app &
tmux
tmuxubuntusudo apt-get install tmux
tmux new -s gf-app./gf-appcrtB & Dtmux attach -t gf-app
supervisor
supervisorPythondaemon
[program:gf-app]
user=root
command=/var/www/main
stdout_logfile=/var/log/gf-app-stdout.log
stderr_logfile=/var/log/gf-app-stderr.log
autostart=true
autorestart=true

使用步驟以下:golang

sudo service supervisor startsupervisor/etc/supervisor/conf.d/gf-app.confsudo supervisorctlsupervisorreloadsupoervisorupdatestart gf-appstatussupervisor
2、代理部署
WebServerGolangGolangWebServer
GolangWebServerWebServernginxapacheGolang WebServer
Nginx
Nginx

靜態文件後綴

nginxgolang
server {
    listen       80;
    server_name  goframe.org;

    access_log   /var/log/gf-app-access.log;
    error_log    /var/log/gf-app-error.log;

    location ~ .*\.(gif|jpg|jpeg|png|js|css|eot|ttf|woff|svg|otf)$ {
        access_log off;
        expires    1d;
        root       /var/www/gf-app/public;
        try_files  $uri @backend;
    }

    location / {
        try_files $uri @backend;
    }

    location @backend {
        proxy_pass                 http://127.0.0.1:8199;
        proxy_redirect             off;
        proxy_set_header           Host             $host;
        proxy_set_header           X-Real-IP        $remote_addr;
        proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}
8199golangWebServer
http://goframe.org/my.png

靜態文件目錄

nginxgolang
server {
    listen       80;
    server_name  goframe.org;

    access_log   /var/log/gf-app-access.log;
    error_log    /var/log/gf-app-error.log;

    location ^~ /public {
        access_log off;
        expires    1d;
        root       /var/www/gf-app;
        try_files  $uri @backend;
    }

    location / {
        try_files $uri @backend;
    }

    location @backend {
        proxy_pass                 http://127.0.0.1:8199;
        proxy_redirect             off;
        proxy_set_header           Host             $host;
        proxy_set_header           X-Real-IP        $remote_addr;
        proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}
8199golangWebServer
http://goframe.org/piblic/my.png
3、容器部署
dockergolang

1. 編譯程序

golangLinuxamd64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gf-app main.go
gf-app

2. 編譯鏡像

gf-appdockerGolangalpine
Dockerfilegf-homeDcokerfile
FROM loads/alpine:3.8

LABEL maintainer="john@johng.cn"

###############################################################################
#                                INSTALLATION
###############################################################################

ADD ./gf-app /bin/main
RUN chmod +x /bin/main

###############################################################################
#                                   START
###############################################################################

CMD main
loads/alpine:3.8Dockerfile
docker build gf-app .gf-appdocker

3. 運行鏡像

使用如下命令運行鏡像:

docker run gf-app

4. 鏡像分發

docker

5. 容器編排

dockerkubernetesdocker swarm