1. 程式人生 > >龍芯3A3000搭建分散式儲存服務etcd

龍芯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