zoukankan      html  css  js  c++  java
  • windows server2019环境下安装openssh进行jenkins代码golang发布

    1.安装好压软件,下载地址作为压缩包的解压和iso的虚拟光驱工具

    http://haozip.2345.cc/

    2.安装openssh

    下载openssh

    https://github.com/PowerShell/Win32-OpenSSH/releases

    https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-Win64.zip

    本次是直接解压到c:openssh目录

    到C:WindowsSystem32WindowsPowerShellv1.0目录下,管理员身份运行powershell.exe,执行以下命令进行安装openssh

    powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

    sc config ssh start=auto

    要在cmd下安装服务

    把ssh安装成服务后,打开隐藏目录选项

    可以看到在 C:ProgramDatassh 目录下生成了配置文件,如果想配置免秘钥登录windows的openssh下的administrator账号

    1. 在c:/users/administrator创建.ssh目录(命令行),并在其中把centos下的账号公钥拷贝到authorized_keys 这个文件中(因为本次我们使用了jenkins的publish over ssh功能,直接输入账号密码不需要配置免秘钥登录

    b. 修改配置C:ProgramDatasshsshd_config

    注释掉:

    #Match Group administrators

    #       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

    jenkins配置部分

    ftp下载传输的配置:

    添加防火墙规则,对指定的ip ssh端口放行(主要是用来jenkins和windows之间进行代码传输)

    查看端口是否开启成功

    这是配置Jenkins服务器免秘钥登录windows2019后的效果

    jenkins编译golang代码的配置

    jenkins中配置golang环境
    
    wget https://golang.org/dl/go1.15.2.linux-amd64.tar.gz
    tar xf go1.15.2.linux-amd64.tar.gz -C /usr/local
    
    vim /etc/profile
    
    export PATH=$PATH:/usr/local/go/bin
    
    [root@jenkins_server:/usr/local/go]# source /etc/profile
    [root@jenkins_server:/usr/local/go]# go version
    go version go1.15.2 linux/amd64
    
    
    jenkins中编译golang的脚本
    
    /data/jenkins_home/workspace/chinasoft.com.api.chinasoft.com_prod]# more init.sh 
    #!/bin/bash -l
    
    ENV=$1
    
    # 复制环境变量
    cp .env.$ENV .env
    
    # 处理依赖
    go mod tidy
    go mod vendor
    
    # 构建启动程序
    GOARCH=amd64 GOOS=windows go build -o api.exe main.go
    
    # 退出
    exit 0
    
    
    # golan g主配置文件
    [root@jenkins_server:/data/jenkins_home/workspace/chinasoft.com.api.chinasoft.com_prod]# more main.go 
    package main
    
    import (
        "api-golang/cache"
        "api-golang/conf"
        "api-golang/lib/logger"
        "api-golang/model"
        "api-golang/router"
        "context"
        "log"
        "net/http"
        "os"
        "os/signal"
        "time"
    )
    
    func init() {
        // 配置初始化
        conf.Init()
        // 初始化日志
        logger.Init()
        // 初始化db
        model.Init()
        // 初始化缓存
        cache.Init()
    }
    
    func main() {
        // 装载路由
        r := router.Init()
    
        srv := &http.Server{
            Addr:    ":8700",
            Handler: r,
        }
    
        go func() {
            // 服务连接
            if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
                log.Fatalf("listen: %s
    ", err)
            }
        }()
    
        // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
        quit := make(chan os.Signal)
        signal.Notify(quit, os.Interrupt)
        <-quit
        log.Println("Shutdown Server ...")
    
        ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
        defer cancel()
        if err := srv.Shutdown(ctx); err != nil {
            log.Fatal("Server Shutdown:", err)
        }
        log.Println("Server exiting")
    }

    windows server2019下相关的bat脚本C:UsersAdministratorwwwrootgo.chinasoft.comash
    
    auto.bat
    
    @echo off
    cd /d %~dp0
    
    echo 1 >Temp.txt
    exit
    
    automonitor.bat
    
    @echo off
    cd /d %~dp0
    
    setlocal enabledelayedexpansion
    
    for /f %%a in (Temp.txt) do (
    set value=%%a
    if "!value!"=="1" (
        call autorun.bat
        echo 0 >Temp.txt
    )
    )
    exit
    
    
    autorun.bat
    
    @echo off
    cd /d %~dp0
    
    ::
    C:wwwrootgo.chinasoft.com.exewinapi.exe stop
    
    ping 127.1 -n 3 >nul 2>nu
    
    ::
    xcopy C:wwwrootgo.chinasoft.comconf* C:wwwrootgo.chinasoft.com.execonf* /s /e /y /d
    xcopy C:wwwrootgo.chinasoft.comapi.exe C:wwwrootgo.chinasoft.com.exeapi.exe /y /d
    xcopy C:wwwrootgo.chinasoft.com.env C:wwwrootgo.chinasoft.com.exe.env /y /d
    xcopy C:wwwrootgo.chinasoft.comwinapi.xml C:\wwwrootgo.chinasoft.com.exewinapi.xml /y /d
    
    ::
    C:wwwrootgo.chinasoft.com.exewinapi.exe start
  • 相关阅读:
    apache http server 和tomcat的区别 以及nginx
    2020-2-12 这样提升自己的口才
    两种常用的队列
    栈的实现与应用
    线性表
    Nginx实现虚拟主机
    将apache添加到服务
    apache安装
    最小生成树
    图的深度优先搜索
  • 原文地址:https://www.cnblogs.com/reblue520/p/13681014.html
Copyright © 2011-2022 走看看