I. Configuration of the environment

  • 1. Install go on the centos server

    wget https://dl.google.com/go/go1.16.5.linux-amd64.tar.gz
    Copy the code
  • 2. Decompress the package to a directory

    sudo Tar -c /usr/local-xf go1.16.5.linux-amd64.tar.gz
    Copy the code
  • 3. Modify ~/. Bash_profile

    # go programs
    export PATH=$PATH:/usr/local/go/bin
    Copy the code
  • 4. Configuration generation is valid

    source ~/.bash_profile
    Copy the code
  • 5. Check whether the installation is successful

    go env
    Copy the code
  • 6. Enable the mod and configure the proxy

    go env -w GO111MODULE=on
    # configure proxy
    go env -w GOPROXY=https://goproxy.cn,direct
    Copy the code
  • 7. Install the Supervisor

    yum install supervisor
    Copy the code
  • 8, if your project depends on mysql, redis please install yourself

Ii. Project packaging

Method one: direct usegitPull code on the server

  • 1. Use git pull code directly on the server

  • 2. Synchronize project dependency packages

    go mod vendor
    Copy the code
  • 3. Package projects

    go run build
    Copy the code

The same waybeeTools package

  • 1. Install bee tools according to the official mode of Beego, and connect the address

  • 2. Enter the project directory and package directly

    bee pack -be GOOS=linux
    Copy the code
  • 3. Upload the project to the centos server

    This tool can be installed on a server running Windows
    yum install lrzsz
    # Macs use SCP directly
    Copy the code
  • Unzip the project on the server

    tar -xvf gin-admin-api.tar.gz
    Copy the code

Three, use,supervisorDeployment project

  • 1. View the supervisor configuration address

    cat /etc/supervisord.conf
    Copy the code

    It is small enough that the xx.ini file it is creating is stored in the container it is handling

    ; setting can list multiple files (separated by whitespace or
    ; newlines). It can also contain wildcards. The filenames are
    ; interpreted as relative to this file. Included files *cannot*
    ; include files themselves.
    
    [include]
    files = supervisord.d/*.ini
    [root@iZwz9et2qekjwu8mwmxgxhZ supervisord.d]# pwd
    /etc/supervisord.d
    [root@iZwz9et2qekjwu8mwmxgxhZ supervisord.d]# 
    Copy the code
  • It is designed to create a gin-admin-api.ini file in the directory it is handling. D /

    # gin-admin-api indicates the project name
    [program:gin-admin-api]                                                                                                                  
    # project folder
    directory = /home/gin-admin-api                                                                                                          
    # project executable location
    command = /home/gin-admin-api/main                                                                                                       
    autostart = true                                                                                                                         
    startsecs = 5                                                                                                                            
    user = root                                                                                                                              
    redirect_stderr = true                                                                                                                   
    The location of the output log file
    stdout_logfile = /home/gin-admin-api/logs/supervisor.log                                                                                 
                                                                                                                                             
    port=127.0.0.1:9090 
    Copy the code
  • 3. Run the startup command

    supervisord -c /etc/supervisord.conf
    Copy the code

    The container is designed for handling the container and is designed for handling the container. The container is designed for handling the container and is designed for handling the container

    • Just look at the process and kill it

      ps aux | grep supervisord
      Copy the code
  • 4. It can be seen the information on the container

    supervisorctl
    Copy the code
    • View all the states

      status
      Copy the code
    • Start all configuration

      start all
      Copy the code
    • Update the configuration

      update
      Copy the code
    • Re-read configuration

      reread
      Copy the code
  • 5. Check the current port number and ensure that 9090 is started

    netstat -ntlp
    Copy the code
  • 6. Access directly from the client (note that Ali Cloud should open the port of 9090)

  • 7. Configure the nginx reverse proxy to port 9090

  • 8. View logs

    tail The -f filename
    Copy the code
  • 9. Refer to the GIN project, which you can use to practice deployment