MongoDB集群分析软件Keyhole的下载安装

MongoDB集群分析软件Keyhole的下载安装,第1张

Keyhole下载安装 Keyhole 是一个开源项目,源代码可在 GitHub 上获得。建议从源代码构建您自己的 Keyhole 可执行文件。或者,可以从 Docker Hub 下载 Keyhole 可执行文件,可用的可执行文件适用于 Linux、macOS 和 Windows。Build and Download Keyhole (simagix.com) Build from GitHub

必须先安装 Golang,然后才能构建。下面的命令显示了如何从 GitHub 克隆并构建 Keyhole 可执行文件:

mkdir -p $GOPATH/src/github.com/simagix
cd $GOPATH/src/github.com/simagix
git clone --depth 1 https://github.com/simagix/keyhole.git
cd keyhole
# 在实践中此步骤发现若提示"go mod download xxxxxx",安装项目所需依赖,原因是go clone只会下载项目所需代码而不会下载所需依赖包
go mod tiny
# 构建keyhole
go build main/keyhole.go

开发者也提供了一个 build.sh 脚本来在 macOS 或 Linux 上构建 Keyhole。只需运行脚本:

./build.sh

build.sh内容:

#! /bin/bash
# Copyright 2020 Kuei-chun Chen. All rights reserved.
die() { echo "$*" 1>&2 ; exit 1; }
VERSION="v$(cat version)-$(date "+%Y%m%d")"
REPO=$(basename "$(dirname "$(pwd)")")/$(basename "$(pwd)")
LDFLAGS="-X main.version=$VERSION -X main.repo=$REPO"
[[ "$(which go)" = "" ]] && die "go command not found"
[[ "$GOPATH" = "" ]] && die "GOPATH not set"
[[ "${GOPATH}/src/github.com/$REPO" != "$(pwd)" ]] && die "building keyhole should be under ${GOPATH}/src/github.com/$REPO"
mkdir -p dist
if [[ "" == "all" ]]; then
  docker rmi -f $(docker images -f "dangling=true" -q) > /dev/null 2>&1
  docker build  -f Dockerfile . -t $REPO
  id=$(docker create $REPO)
  docker cp $id:/dist - | tar vx
else
  if [ "" == "cross-platform"  ]; then
    env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/keyhole-osx-x64 main/keyhole.go
    env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/keyhole-linux-x64 main/keyhole.go
    env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$LDFLAGS" -o dist/keyhole-win-x64.exe main/keyhole.go
  else
    rm -f keyhole
    go build -ldflags "$LDFLAGS" main/keyhole.go
    if [[ -f keyhole ]]; then
      ./keyhole -version
    fi
  fi
fi
Cross Platform Builds

为三个不同的平台构建,它们分别是 macOS、Linux 和 Windows。命令是:

./build.sh cross-platform

输出在 dist 目录下创建。

ls dist

keyhole-linux-x64     keyhole-osx-x64       keyhole-win-x64.exe

如果需要在其他Linux系统机器上面安装keyhole,可直接复制/dist文件夹下面的keyhole-liux-x64文件至目标机器,运行文件即可。

Build on Windows

下面是从 Windows 命令终端构建 Keyhole v1.0.5 的命令。

go build -ldflags "-X main.version=v1.0.5" main/keyhole.go

上面的命令将在当前目录中输出一个可执行文件,keyhole。版本号存储在名为 version 的文件中。

> type version

1.0.5
在Ubuntu安装后建立软连接

我在安装keyhole之后发现输入keyhole时会提示 Command not found ,通过建立软连接解决

cd /user/local/bin/

ln -s /root/gowork/src/github.com/simagix/keyhole/keyhole ./keyhole

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995451.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存