美文网首页
在阿里云上以DevOps简单实现网站搭建

在阿里云上以DevOps简单实现网站搭建

作者: 今晚写bug | 来源:发表于2020-02-02 16:06 被阅读0次
    屏幕快照 2020-02-02 下午3.54.56.png

    1. 基本业务代码实现 (业务面webserver管理面deployserver)

    webserver
    package main
    
    import (
        "io"
        "net/http"
    )
    
    func firstPage(w http.ResponseWriter, r *http.Request)  {
        io.WriteString(w,"<h1>Hello, 彭琳琳!</h1>")
    }
    
    func main() {
        http.HandleFunc("/",firstPage)
        http.ListenAndServe(":8000",nil)
    }
    
    编译 生成 linux平台可运行的 可执行文件
     env GOOS=linux GOARCH=amd64 go build
    
    webserver
    package main
    
    import (
        "io"
        "log"
        "net/http"
        "os/exec"
    )
    
    func reLaunch() {
        cmd := exec.Command("sh","./deploy.sh")
        err := cmd.Start()
        if err != nil {
            log.Fatal(err)
        }
        err = cmd.Wait()
    }
    
    func firstPage(w http.ResponseWriter, r *http.Request)  {
        io.WriteString(w,"<h1>Hello,this is my deploy server!</h1>")
        reLaunch()
    }
    
    func main() {
        http.HandleFunc("/",firstPage)
        http.ListenAndServe(":8080",nil)
    }
    
    
    env GOOS=linux GOARCH=amd64 go build
    

    2. 代码的编译构建打包以及简单的DevOps自动化

    shell脚本

    deploy.sh

    #! /bin/sh
    kill -9 $(pgrep webserver)
    cd ~/go_duke_linux/newweb
    git pull https://github.com/TechDataCenter/newweb.git
    cd webserver/
    ./webserver &
    
    cp newweb/deployserver/deployserver deployserver
    cp newweb/deploy.sh deploy.sh
    
    github webhooks

    一旦newweb 代码有提交就会 访问 http://39.105.102.24:8080/
    触发 deploy.sh脚本

    屏幕快照 2020-02-02 下午3.56.42.png

    3. 利用阿里云完成网站的部署和监控

    屏幕快照 2020-02-02 下午4.01.54.png 屏幕快照 2020-02-02 下午4.02.03.png
    当监控到 服务异常时:

    会通知到 相关监控组人员。


    4601B96F8BD817CE49763A7F35E0619D.png

    相关文章

      网友评论

          本文标题:在阿里云上以DevOps简单实现网站搭建

          本文链接:https://www.haomeiwen.com/subject/lbdqxhtx.html