设为首页 收藏本站
查看: 2223|回复: 0

[经验分享] docker集群存储软件etcd安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-3-26 10:35:48 | 显示全部楼层 |阅读模式
Etcd是coreos开发的一个kv的软件,我使用他做存储数据,比如持久化固定ip,就是把固定的docker容器ip信息存放到etcd里,智能配置docker防火墙的信息也是存放到etcd里,这个软件很小型,并且支持集群,很是方便,现在给大家结束一下如何在centos6系统里安装此软件。
先简单介绍一下etcd,从网上复制的
1
2
3
4
5
6
etcd是一个高可用的键值存储系统,主要用于共享配置和服务发现。
etcd的特性如下:
简单: curl可访问的用户的API(HTTP+JSON)
安全: 可选的SSL客户端证书认证
快速: 单实例每秒 1000 次写操作
可靠: 使用Raft保证一致性



安装环境
系统:centos6.6
etcd版本0.4.6
虽然有最新的版本,但我一直使用这个版本,比较稳定
下面是安装过程

1、下载
1
curl -L  https://github.com/coreos/etcd/r ... -linux-amd64.tar.gz -o etcd-v0.4.6-linux-amd64.tar.gz



2、解压
1
2
tar xzvf etcd-v0.4.6-linux-amd64.tar.gz
cd etcd-v0.4.6-linux-amd64



3、复制程序到系统环境
1
2
cp etcd /usr/local/bin
cp etcdctl /usr/local/bin



4、设置运行脚本,绝对路径是/etc/init.d/etcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Copyright 2013, Nathan Milford
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# /etc/init.d/etcd
#
# Startup script for etcd
#
# chkconfig: 2345 20 80
# description: Starts and stops etcd

. /etc/init.d/functions

prog="etcd"
prog_bin="/usr/local/bin/$prog"
desc="etcd shared configuration and service discovery daemon"

if ! [ -f $prog_bin ]; then
  echo "$prog binary not found."
  exit 5
fi

if [ -f /etc/sysconfig/$prog ]; then
  . /etc/sysconfig/$prog
else
  echo "No sysconfig file found in /etc/sysconfig/$prog... exiting."
  exit 5
fi

start() {
  echo "Starting $desc ($prog): "
  su $ETCD_USER -c "nohup $prog_bin $ETCD_OPTS >>$ETCD_OUT_FILE 2>&1 &"
  RETVAL=$?
  return $RETVAL
}

stop() {
  echo "Shutting down $desc ($prog): "
  pkill -f $prog_bin
}

restart() {
    stop
    start
}

status() {
  if [ -z $pid ]; then
     pid=$(pgrep -f $prog_bin)
  fi

  if [ -z $pid ]; then
    echo "$prog is NOT running."
    return 1
  else
    echo "$prog is running (pid is $pid)."
  fi

}

case "$1" in
  start)   start;;
  stop)    stop;;
  restart) restart;;
  status)  status;;
  *)       echo "Usage: $0 {start|stop|restart|status}"
           RETVAL=2;;
esac
exit $RETVAL



5、设置etcd软件环境配置,根据自己的实际环境修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
09:21:19 # cat /etc/sysconfig/etcd
#!/bin/bash
# Copyright 2014, Nathan Milford
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
lib_dir='/var/lib/etcd/'
# Will be used to populate IP address values below.  Setting some items to
# '0.0.0.0' is not compatable with the discovery API.
#_MY_IPADDR=$(/sbin/ifconfig | grep 'inet'| grep -Ev '(127|117|172|::1|fe)' |awk '{print $2}'|head -n 1)
_MY_IPADDR=10.10.29.236
# Daemon User
#ETCD_USER="etcd"

# Cluster Seeds
#  You can specify a list here sepearated by commas, or leave it blank if
#  you're playing with a single node.
ETCD_SEEDS=""

# Discovery Endpoint
#  Leave it as the public URL unless you are running your own.
ETCD_DISCOVER_ENDPOINT="https://discovery.etcd.io/"

# Discovery Token
#  If you are using the discovery protocol you can grab your cluster token
#  from https://discovery.etcd.io/new if you are not hosting it yourself.
ETCD_DISCOVERY_TOKEN="cb5940a807d44287e05f29f3170883e3"

# This node's name as it represents itself on the cluster.
ETCD_NODE_NAME=$(hostname -s)

# Hostname and port for the etcd server to work on.
ETCD_LISTEN="$_MY_IPADDR:4001"

# Directory to store log and snapshot.
ETCD_DATA_DIR="/var/lib/etcd/"

# File to log stdout/stderr to.
ETCD_OUT_FILE="/var/log/etcd/etcd.log"

# Set logging vebosity for the file above.
#   Valid options are "", "v" or "vv"
ETCD_LOGGING=""

# Max size of the cluster.
ETCD_MAXSIZE=9

# Max size of result buffer.
ETCD_MAXRESULT=1024

# Number of retries to attempt while joining a cluster
ETCD_RETRIES=3

# Set security settings for the etcd server.
#  Leave blank if you do not plan to use this feature, otherwise add appropriate
#  paths.
ETCD_CAFILE=""
ETCD_CERT=""
ETCD_KEY=""

# Toggles snapshotting.
#  Keep blank or set to true.
ETCD_SNAPSHOT=""

# Hostname and port for the RAFT server to work on.
RAFT_LISTEN="$_MY_IPADDR:7001"

# Set security settings for the RAFT server.
#  Leave blank if you do not plan to use this feature, otherwise add appropriate
#  paths.
RAFT_CAFILE=""
RAFT_CERT=""
RAFT_KEY=""

# Below we build the opts to pass to the init script.

ETCD_OPTS="-name=${ETCD_NODE_NAME} \
          -addr=${ETCD_LISTEN} \
          -peer-addr=${RAFT_LISTEN} \
          -data-dir=${ETCD_DATA_DIR} \
          -max-result-buffer=${ETCD_MAXRESULT} \
          -max-cluster-size=${ETCD_MAXSIZE} \
          -max-retry-attempts=${ETCD_RETRIES}"

if [ x$ETCD_SEEDS != "x" ]; then
  ETCD_OPTS="$ETCD_OPTS -peers=${ETCD_SEEDS}"
fi

if [ x$ETCD_DISCOVERY_TOKEN != "x" ]; then
  ETCD_OPTS="$ETCD_OPTS -discovery=${ETCD_DISCOVER_ENDPOINT}${ETCD_DISCOVERY_TOKEN}"
fi

if [ "$ETCD_LOGGING" == "v" ]; then
  ETCD_OPTS="$ETCD_OPTS -v"
elif [ "$ETCD_LOGGING" == "vv" ]; then
  ETCD_OPTS="$ETCD_OPTS -vv"
fi

if [ x$ETCD_SNAPSHOT != "x" ]; then
  ETCD_OPTS="$ETCD_OPTS -snapshot"
fi
if [ ! -d $lib_dir ];then
  mkdir -p $lib_dir
fi
#if [ x$ETCD_CAFILE != "x" ] && [ x$ETCD_CERT != "x" ] && [ x$ETCD_KEY != "x" ]; then
#  ETCD_OPTS="$ETCD_OPTS -ca-file=${ETCD_CAFILE} -cert-file=${ETCD_CERT} -key-file=${ETCD_KEY}"
#fi

#if [ x$RAFT_CAFILE != "x" ] && [ x$RAFT_CERT != "x" ] && [ x$RAFT_KEY != "x" ]; then
#  ETCD_OPTS="$ETCD_OPTS -peer-ca-file=${RAFT_CAFILE} -peer-cert-file=${RAFT_CERT} -peer-key-file=${RAFT_KEY}"
#fi
#echo $ETCD_OPTS
# TODO
# Add support for:
#  -peers-file
#  -config
#  -cors
#  -cpuprofile



如果不想加入集群,就把ETCD_DISCOVER_ENDPOINT与ETCD_DISCOVERY_TOKEN给注释了,另外_MY_IPADDR是本机的ip
6、创建用户

1
useradd etcd -M -s /sbin/nologin



7、创建日志与数据存放目录
1
2
mkdir /var/log/etcd
mkdir /var/lib/etcd



8、授予权限
1
2
chown -R etcd:etcd /var/log/etcd
chown -R etcd:etcd /var/lib/etcd



9、启动
1
/etcd/init.d/etcd start



10、设置开机启动
1
chkconfig --level 345 etcd on



11、查看运行情况
查看集群主机ip
1
2
12:22:48 # curl -L http://127.0.0.1:4001/v2/machines
http://10.10.21.199:4001, http://10.10.27.221:4001, http://10.10.17.3:4001, http://10.10.17.4:4001, http://10.10.29.236:4001



查看集群主机列表(详细)
1
2
12:23:07 # curl -L http://127.0.0.1:4001/v2/keys/_etcd/machines
{"action":"get","node":{"key":"/_etcd/machines","dir":true,"nodes":[{"key":"/_etcd/machines/docker-test1","value":"etcd=http%3A%2F%2F10.10.21.199%3A4001\u0026raft=http%3A%2F%2F10.10.21.199%3A7001","modifiedIndex":1,"createdIndex":1},{"key":"/_etcd/machines/docker-test2","value":"etcd=http%3A%2F%2F10.10.27.221%3A4001\u0026raft=http%3A%2F%2F10.10.27.221%3A7001","modifiedIndex":9,"createdIndex":9},{"key":"/_etcd/machines/docker-test3","value":"etcd=http%3A%2F%2F10.10.17.3%3A4001\u0026raft=http%3A%2F%2F10.10.17.3%3A7001","modifiedIndex":16,"createdIndex":16},{"key":"/_etcd/machines/ip-10-10-17-4","value":"etcd=http%3A%2F%2F10.10.17.4%3A4001\u0026raft=http%3A%2F%2F10.10.17.4%3A7001","modifiedIndex":177304,"createdIndex":177304},{"key":"/_etcd/machines/ip-10-10-29-236","value":"etcd=http%3A%2F%2F10.10.29.236%3A4001\u0026raft=http%3A%2F%2F10.10.29.236%3A7001","modifiedIndex":2101510,"createdIndex":2101510}],"modifiedIndex":1,"createdIndex":1}}



查看集群header
1
2
12:23:15 # curl -L http://127.0.0.1:4001/v2/leader
http://10.10.17.4:7001



详细请参考https://github.com/coreos/etcd

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-50719-1-1.html 上篇帖子: 没有了 下篇帖子: etcd 2.1 发布,高可用 Key/Value 存储系统 软件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表