您的位置:首页 > 其它

在ubuntu上安装并运行NATS Server -- gnastd:未找到命令

2016-04-13 11:32 567 查看
从昨天就开始整NATS,过程中遇到很多问题,今天总结一下。

其中最困扰的就是gnastd:未找到命令
好吧,还是先贴一段官方的介绍。

NATS

Open Source. Performant. Simple. Scalable.

A central nervous system for modern, reliable

and scalable cloud and distributed systems.

安装成功后启动NATS的界面



第一步 安装go环境

参考NATS官网

NATS Server

NATS provides a server that is written in the Go programming language. The executable name for the NATS server is gnatsd, which stands for Go NATS Deamon. The NATS server is provided as open source software under the MIT license. Apcera actively maintains and supports the NATS server.

通过官方的介绍我们知道NATS是用go语言写的,所以运行NATS首先得确保go环境已经安装配置好

Install and Run NATS Server

In this tutorial you install and run the NATS server (gnatsd). You can follow this same procedure anytime you want to run the NATS server.

Prerequisite

Set up your Go environment

1.1 下载go

下载地址

https://golang.org/dl/

根据自己电脑的型号选择相应的版本



进入到刚才下载文件所在目录,这里我在下载中

cd 下载




将go1.6.linux-amd64.tar.gz解压到/usr/local/

tar -zxvf go1.6.linux-amd64.tar.gz -C /usr/local


1.2 配置go

先贴出来我的配置/etc/profile



我的环境变量中除了go还有Java和Maven的,所以看着比较乱。

说一下go的环境变量都要什么,一个是GOPATH,一个是GOROOT,还有一个就是PATH的配置

On Mac OS X and Linux, by default Go is installed to directory /usr/local/go/, and the GOROOT environment variable is set to /usr/local/go/bin

Your Go working directory (GOPATH) is where you store your Go code. It can be any path you choose but must be separate from your Go installation directory (GOROOT).

GOROOT就是go的安装路径,而GOPATH是go的工作目录。

GOROOT配置到我们刚才解压的路径下,即/usr/local/go

GOROOT=/usr/local/go


我们在当前用户的目录下建一个目录

cd ~
mkdir go


我们把这个目录作为GOPATH,也就是存储代码的目录。

GOPATH=$HOME/go


配置环境变量,将$GOROOT/bin和$GOPATH/bin包含到PATH中去。

这里一定要将$GOPATH/bin也包含进去(一会儿再解释原因)。

到这里环境配置完成了。

1.3 测试go

在当前用户目录下建一个文件夹,存放代码,我将其命名为goworkspace

写一个go和helloworld

mkdir goworkspace
cd goworkspace
touch hello.go
vi hello.go


将下面的代码拷贝到hello.go并保存

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}


然后运行

go run hello.go




参考

http://nats.io/documentation/tutorials/go-install/

https://golang.org/doc/install#install

第二步 安装NATS server

## 2.1 安装NATS server

在终端执行以下命令

go get github.com/nats-io/gnatsd


这句命令会在我们刚才配置的GOPATH中安装gnatsd服务

执行这句指令的前提是电脑上还得配置安装了git

git的安装参考百度经验

ubuntu安装git

这句话执行完之后我们的GOPATH,也就是

$HOME/go目录下会多一些目录



而gnatsd就在其bin目录下

我们进入/usr/local/go/bin



我们发现其下面就只有go,godoc和gofmt

为了能在终端直接运行gnastd命令,我们必须将$GOPATH/bin包含到PATH中,如果PATH中没有$GOPATH/bin,那么执行

gnastd


会给出如下提示

gnastd:未找到命令




如果将$GOPATH/bin配置到PATH中,则将成功启动gnastd服务



参考

http://nats.io/documentation/tutorials/gnatsd-install/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  NATS