Debian9/10安装Go&SmartPing

发布于 2020-10-10  1,150 次阅读


Go

1.下载并校验Go

wget https://golang.org/dl/go1.15.4.linux-amd64.tar.gz
sha256sum go1.15.4.linux-amd64.tar.gz

最新安装包及对应SHA256 Checksum参见:
https://golang.org/dl/

Debian/Ubuntu:

apt-get install wget

Centos:

sudo yum -y install wget

2.提取Go

将软件包解压缩到/usr/local目录,root权限下不用加“sudo”:

tar -C /usr/local -xzf go1.15.4.linux-amd64.tar.gz

3.调整路径变量

当提取Go 软件包时,我们需要编辑PATH环境变量,以便我们的系统知道Go可执行二进制文件所在的位置。 我们可以通过将以下行附加到/etc/profile文件(用于系统范围的安装)或$HOME/.profile文件(用于当前用户安装)来完成此操作:

nano ~/.profile
export PATH=$PATH:/usr/local/go/bin

CTRL+X退出并保存文件,并将新的PATH环境变量应用于当前的shell会话:

source ~/.profile

4.测试Go

1>创建工作区目录

默认情况下,工作空间目录设置为$HOME/go,以创建它类型:

mkdir ~/go

2>创建一个输出Hello World的go文件

在工作区内创建一个新目录src/hello

mkdir -p ~/go/src/hello

在该目录创建一个名称为hello.go的文件

nano ~/go/src/hello/hello.go
package main

import "fmt"

func main() {
    fmt.Printf("Hello, World\n")
}

CTRL+X退出并保存文件

3>编译hello.go文件:

要构建文件切换到〜/go/src/hello目录并运行go build:

cd ~/go/src/hello
go build

4>运行可执行文件:

./hello

输出“Hello, World”内容即成功。

SmartPing

https://docs.smartping.org/install

这里使用的是源码编译:

安装前置

Debian:

apt-get install gcc -y
apt-get install git -y

CentOS:

yum install gcc

克隆ZIP的源码包

mkdir /root/go
mkdir /root/go/src
cd /root/go/src
git clone https://github.com/gy-games/smartping.git
cd smartping

Debian10:

sudo apt update
sudo apt install git

CentOS7:

1>启用EPEL存储库:

RHEL/CentOS 7 64位执行以下命令:

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm

RHEL/CentOS 7 32位执行以下命令:

get http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

2>安装git命令:

yum install -y git

Linux下:

chmod +x ./control
./control build

nano /root/go/src/smartping/conf/config-base.json

./control start
cd smartping
chmod +x ./control
./control start

Windows下:

control.cmd build
control.cmd start

SmartPing默认WEB服务端口为8899,管理界面默认密码为:smartping。若需要修改,请修改conf/config.json或conf/config-base.json。

集中配置管理(云模式)

https://docs.smartping.org/arch/cloud

在我们的实际使用中,当部署的点越来越多,对于配置的更新成本也越来越大,所以从0.5.0+以上的版本我们增加了一个新的功能,云模式,允许一台机器为主配置节点,其他节点在此节点拉取主要配置信息。
使用云模式时,需要有一个节点为本地模式,提供配置文件,剩余节点选择云模式,并将本地模式的节点config API配置上,默认为每分钟进行一次数据拉取。


Debian10通过rc.local设置开机自启

#查看rc.local服务配置文件
cat /lib/systemd/system/rc.local.service
#查看服务状态,默认是inactive
systemctl status rc-local

手工添加/etc/rc.local 文件

cat <<EOF >/etc/rc.local
#!/bin/sh -e
# 
# rc.local
# 
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# 
# In order to enable or disable this script just change the execution
# bits.
# 
# By default this script does nothing.

cd /root/go/src/smartping
./control start

exit 0
EOF
chmod +x /etc/rc.local
systemctl start rc-local

Love is merely a madness.