分布式学习(2)etcd@1@goreman

一、什么是goreman

goreman是一个go语言编写的多进程管理工具,是对Ruby下广泛使用的foreman的重写(foreman原作者也实现了一个golang版:forego,不过没有goreman好用)相比较monit、supervisor而言要简单的多,而且可以在项目级别管理进程,比较适合开发环境使用。比如快速运行和一项目相关的所有进程,goreman就可以派上用场。coreos的etcd就是使用的goreman来一键启停单机版的etcd集群。

二、安装

cd ~/go/src
mkdir -p golang.org/x
cd golang.org/x
git clone https://github.com/golang/sys.git

cd $GOPATH/src
mkdir gopkg.in
cd gopkg.in
git clone https://github.com/go-yaml/yaml.git
mv yaml yaml.v2
cd yaml.v2
go install

cd $GOPATH/src
git clone https://gitee.com/szysyyxtl/goreman.git

cd goreman
go build
./goreman help

#添加环境变量
临时设置

export PATH=/root/go/src/goreman/:$PATH

当前用户的全局设置

vim ~/.profile,添加行: 
export PATH=/root/go/src/goreman/:$PATH 
使生效 
source .profile

所有用户的全局设置

vim /etc/profile 
在里面加入: 
export PATH=/root/go/src/goreman/:$PATH 
使生效 
source /etc/profile

三、使用案例

goreman -f string
string 是文件名即:proc file (default "Procfile")
#如果你创建的名字是Procfile,那么直接 >> goreman start
#如果你创建的名字不是Procfile,那么输入>> goreman -f filename start

传入参数:

我可以携带多个参数来运行,比如Procfile文件为:

hello1: ./helloworld --name=$NAME --age=$AGE
hello2: ./helloworld
hello3: ./helloworld

运行命令为

NAME=Song AGE=18 goreman start

运行单个命令

goreman start hello1

进程控制

当我们通过goreman start命令启动了一组相关的进程后,我们可以在另外的shell中,进入到相同的目录,执行一些进程控制的命令:

goreman run start hello 启动指定的命令
goreman run stop hello 停止指定的进程
goreman run restart hello 重启指定的进程
goreman run restart-all 重启所有进程
goreman run status 查看进程列表和状态,其中前面带*号的标示正在运行中
goreman run list 查看命令名称列表

猜你喜欢

转载自blog.csdn.net/qq_36336522/article/details/104710508