龙芯3A3000搭建分布式存储服务etcd

http://ask.loongnix.org/?/article/93

etcd 是一个应用在分布式环境下的 key/value 存储服务。
 
 

timg.jpg


 

由于Kubernetes要使用到etcd,所以第一步就是进行etcd的搭建。
 
etcd是一个Go语言编写的软件。

 搭建环境
 
本文的实验都是在龙芯3A3000机器上。
操作系统是loongnix(Fedora21)20170512版本。
GO版本:go1.7.5 linux/mips64le
 
开始搭建
 
首先打开终端,配置GOPATH

# export GOPATH=/usr/lib/golang

进入GOPATH目录下

# cd $GOPATH

在$GOPATH的src目录下创建嵌套文件夹github.com/coreos

# mkdir -p $GOPATH/src/github.com/coreos

进入创建的文件夹下

# cd $GOPATH/src/github.com/coreos

下载etcd 2.3.6版本

# git clone  -b  v2.3.6 https://github.com/coreos/etcd.git


进入下载的etcd 文件夹下

# cd etcd

开始编译

# ./build

出现如下错误

github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt
Godeps/_workspace/src/github.com/boltdb/bolt/db.go:98: undefined: maxMapSize
Godeps/_workspace/src/github.com/boltdb/bolt/db.go:98: invalid array bound maxMapSize

根据maxMapSize关键字找原因,使用grep "maxMapSize"  ./* -r 找出路径

# grep "maxMapSize" ./* -r

搜索出如下内容

./Godeps/_workspace/src/github.com/boltdb/bolt/db.go:	data     *[maxMapSize]byte
./Godeps/_workspace/src/github.com/boltdb/bolt/db.go:	if size > maxMapSize {
./Godeps/_workspace/src/github.com/boltdb/bolt/db.go:	if sz > maxMapSize {
./Godeps/_workspace/src/github.com/boltdb/bolt/db.go:		sz = maxMapSize
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_windows.go:	db.data = ((*[maxMapSize]byte)(unsafe.Pointer(addr)))
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_386.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_386.go:const maxMapSize = 0x7FFFFFFF // 2GB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_amd64.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_amd64.go:const maxMapSize = 0xFFFFFFFFFFFF // 256TB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_ppc64le.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_ppc64le.go:const maxMapSize = 0xFFFFFFFFFFFF // 256TB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix_solaris.go:	db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0]))
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_arm64.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_arm64.go:const maxMapSize = 0xFFFFFFFFFFFF // 256TB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_s390x.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_s390x.go:const maxMapSize = 0xFFFFFFFFFFFF // 256TB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_arm.go:// maxMapSize represents the largest mmap size supported by Bolt.
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_arm.go:const maxMapSize = 0x7FFFFFFF // 2GB
./Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:	db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0]))


 根据错误提示分析,是因为在 ./Godeps/_workspace/src/github.com/boltdb/bolt 文件夹下,
缺少了支持mips64le平台的文件。
进入这个目录下添加bolt_mips64le.go文件:

# cd ./Godeps/_workspace/src/github.com/boltdb/bolt
# cp bolt_arm.go  bolt_mips64le.go

重新进入etcd文件夹下,开始编译

# cd $GOPATH/src/github.com/coreos/etcd
# ./build

出现如下错误

2017-11-02 11:58:50.257747 E | etcdmain: etcd on unsupported platform without ETCD_UNSUPPORTED_ARCH=mips64le set.

这是因为没有配置ETCD_UNSUPPORTED_ARCH环境变量
配置环境变量

# export ETCD_UNSUPPORTED_ARCH=mips64le

再次编译

# ./build

执行通过,在etcd文件夹里会生成bin文件夹,进入bin文件夹

# cd bin 

 
把bin文件夹下的etcd、etcdctl两个文件拷贝到/usr/bin文件夹下

# cp etcd  /usr/bin/ 
# cp etcdctl /usr/bin/



 进入/usr/bin下

# cd /usr/bin


 执行测试

 执行etcd文件

# ./etcd
2017-11-02 19:57:52.098590 W | etcdmain: running etcd on unsupported architecture "mips64le" since ETCD_UNSUPPORTED_ARCH is set
2017-11-02 19:57:52.099742 W | flags: unrecognized environment variable ETCD_UNSUPPORTED_ARCH=mips64le
2017-11-02 19:57:52.099870 I | etcdmain: etcd Version: 2.3.6
2017-11-02 19:57:52.099924 I | etcdmain: Git SHA: 128344c
2017-11-02 19:57:52.099974 I | etcdmain: Go Version: go1.7.5
2017-11-02 19:57:52.100021 I | etcdmain: Go OS/Arch: linux/mips64le
2017-11-02 19:57:52.100074 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4
2017-11-02 19:57:52.100145 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2017-11-02 19:57:52.101051 I | etcdmain: listening for peers on http://localhost:2380
2017-11-02 19:57:52.101273 I | etcdmain: listening for peers on http://localhost:7001
2017-11-02 19:57:52.101483 I | etcdmain: listening for client requests on http://localhost:2379
2017-11-02 19:57:52.101683 I | etcdmain: listening for client requests on http://localhost:4001
2017-11-02 19:57:52.105386 I | etcdserver: name = default
2017-11-02 19:57:52.105674 I | etcdserver: data dir = default.etcd
2017-11-02 19:57:52.105741 I | etcdserver: member dir = default.etcd/member
2017-11-02 19:57:52.105794 I | etcdserver: heartbeat = 100ms
2017-11-02 19:57:52.105845 I | etcdserver: election = 1000ms
2017-11-02 19:57:52.105896 I | etcdserver: snapshot count = 10000
2017-11-02 19:57:52.105968 I | etcdserver: advertise client URLs = http://localhost:2379,http://localhost:4001
2017-11-02 19:57:52.106025 I | etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
2017-11-02 19:57:52.106204 I | etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
2017-11-02 19:57:52.115937 I | etcdserver: starting member ce2a822cea30bfca in cluster 7e27652122e8b2ae
2017-11-02 19:57:52.116104 I | raft: ce2a822cea30bfca became follower at term 0
2017-11-02 19:57:52.116172 I | raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2017-11-02 19:57:52.116223 I | raft: ce2a822cea30bfca became follower at term 1
2017-11-02 19:57:52.116829 I | etcdserver: starting server... [version: 2.3.6, cluster version: to_be_decided]
2017-11-02 19:57:52.118591 E | etcdmain: failed to notify systemd for readiness: No socket
2017-11-02 19:57:52.118642 E | etcdmain: forgot to set Type=notify in systemd service file?
2017-11-02 19:57:52.119456 N | etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae
2017-11-02 19:57:52.516914 I | raft: ce2a822cea30bfca is starting a new election at term 1
2017-11-02 19:57:52.517204 I | raft: ce2a822cea30bfca became candidate at term 2
2017-11-02 19:57:52.517241 I | raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 2
2017-11-02 19:57:52.517327 I | raft: ce2a822cea30bfca became leader at term 2
2017-11-02 19:57:52.517369 I | raft: raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 2
2017-11-02 19:57:52.518315 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 7e27652122e8b2ae
2017-11-02 19:57:52.518664 I | etcdserver: setting up the initial cluster version to 2.3
2017-11-02 19:57:52.525866 N | etcdserver: set the initial cluster version to 2.3


 再另一个终端中测试

# etcdctl set /foo/bar  “hello world”

输出“hello world”说明启动成功。
 
这样,etcd就搭建成功了,整个过程还是很简单的,改动的代码不算多,运行也比较顺利。
 
后面将继续移植Kubernetes,好期待啊!

1.png

猜你喜欢

转载自blog.csdn.net/weixin_40065369/article/details/85471675