es集群一键安装、启动、停止脚本

释放双眼,带上耳机,听听看~!

** es集群一键安装脚本**


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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
1#!/bin/bash
2#配置ES的安装目录 修改的地方1 脚本可以自己创建
3currentTime=$(date '+%Y-%m-%d %H:%M:%S')
4echo -e "请输入es的安装目录,不存在脚本自动创建,最后一个/不要写 /bigdata/install"
5read esinstallpath
6
7#创建ES安装的目录
8if [ ! -d $esinstallpath ]; then
9   mkdir -p $esinstallpath
10fi
11if [ ! -d $esinstallpath ]; then
12  echo "创建目录$esinstallpath失败!请检查目录是否有权限"
13  exit
14fi
15
16#解压tar包
17currentdir=$(cd $(dirname $0); pwd)
18ls | grep 'elasticsearch-.*[gz]$'
19if [ $? -ne 0 ]; then
20   #当前目录没有es的压缩包
21   echo "在$currentdir下没有发现elasticsearch-*.tar.gz,请自行上传!"
22   exit
23else
24   #解压
25   tar -zxvf $currentdir/$(ls | grep 'elasticsearch-.*[gz]$') -C $esinstallpath
26fi
27
28esbanben=`ls $esinstallpath| grep 'elasticsearch-.*'`
29
30#PATH设置
31#末行插入
32echo "">>~/.bash_profile
33echo "#ES $currentTime">>~/.bash_profile
34echo "export ES_HOME=$esinstallpath/$esbanben">>~/.bash_profile
35echo 'export PATH=$PATH:$ES_HOME/bin'>>~/.bash_profile
36source ~/.bash_profile
37
38confpath=$esinstallpath/$esbanben/config
39
40#修改配置文件
41echo -e "请输入cluster.name的值:一个集群的名字保证一样 例如 gskjescluster"
42read esname
43echo "cluster.name: $esname" >>$confpath/elasticsearch.yml
44
45echo -e "请输入node.name的值:唯一值 例如 1"
46read nodename
47echo "node.name: node-$nodename">>$confpath/elasticsearch.yml
48
49
50echo -e "请输入path.data的值:例如 /es6.5.4/data/data/"
51read pathdata
52echo "path.data: $pathdata">>$confpath/elasticsearch.yml
53
54echo -e "请输入path.logs的值:例如 /es6.5.4/data/logs/"
55read pathlogs
56echo "path.logs: $pathlogs">>$confpath/elasticsearch.yml
57
58echo "bootstrap.memory_lock: false">>$confpath/elasticsearch.yml
59echo "bootstrap.system_call_filter: false">>$confpath/elasticsearch.yml
60echo "network.host: 0.0.0.0">>$confpath/elasticsearch.yml
61
62echo -e "请输入httpport的值 默认值 9200"
63read httpport
64echo "http.port: $httpport">>$confpath/elasticsearch.yml
65
66echo -e "请输入transporttcpport的值 默认值 9300"
67read transporttcpport
68echo "transport.tcp.port: $transporttcpport">>$confpath/elasticsearch.yml
69
70
71echo -e '请输入es集群的所有节点,严格符合以下格式  "cdh01","cdh02","cdh03" '
72read unicasthosts
73echo "discovery.zen.ping.unicast.hosts: [$unicasthosts]">>$confpath/elasticsearch.yml
74
75array=(${unicasthosts//,/ })
76len=${#array[@]}
77masternodes=`expr $len / 2 + 1`
78#判断集群节点个数>2,才加
79if [[ $len > 2 ]]; then
80  echo "discovery.zen.minimum_master_nodes: $masternodes">>$confpath/elasticsearch.yml
81fi
82
83
84echo -e "是否修改jvm.options 请输入y/n"
85read jvmisflag
86if [[ $jvmisflag == "y" ]]; then
87 echo -e "请输入jvm大小,注意g是小写 例如 16g"
88 read jvmsize
89 sed -i "s/^-Xms1g/-Xms$jvmsize/" $confpath/jvm.options
90 sed -i "s/^-Xmx1g/-Xmx$jvmsize/" $confpath/jvm.options
91 
92fi
93
94#修改并分发安装文件
95echo -e "是否远程复制 请输入y/n"
96read flag
97if [[ $flag == "y" ]]; then
98
99espath=$esinstallpath/$esbanben
100espathtemp=$esinstallpath/$esbanben-temp
101cp -r $espath $espathtemp
102
103echo "以下输入的节点必须做免密登录"
104echo -e '请输入除当前之外的节点(当前节点cdh01),严格符合以下格式IP:esID,空格隔开, cdh02:2 cdh03:3 cdh04:4 cdh05:5'
105read allnodes
106user=`whoami`
107array2=(${allnodes// / })
108for allnode in ${array2[@]}
109do
110 array3=(${allnode//:/ })
111 ip=${array3[0]}
112 esid=${array3[1]}
113 echo ======= $ip  =======
114
115 #修改文件
116 ssh $ip "rm -rf $espath"
117 ssh $ip "mkdir -p $espath"
118
119 bak_dir="node.name: node-$nodename"
120 new_dir="node.name: node-$esid"
121 sed -i "s!${bak_dir}!${new_dir}!g" $espathtemp/config/elasticsearch.yml
122
123 scp -r $espathtemp/* ${user}@$ip:$espath/
124
125 ssh $ip "echo ''>>~/.bash_profile"
126 ssh $ip "echo '#ES $currentTime'>>~/.bash_profile"
127 ssh $ip "echo 'export ES_HOME=$esinstallpath/$esbanben'>>~/.bash_profile"
128 ssh $ip 'echo "export PATH=\$PATH:\$ES_HOME/bin">>~/.bash_profile'
129 ssh $ip "source ~/.bash_profile"
130
131
132 #再次修改回来 防止修改错误
133 new_dir="node.name: node-$nodename"
134 bak_dir="node.name: node-$esid"
135 sed -i "s!${bak_dir}!${new_dir}!g" $espathtemp/config/elasticsearch.yml
136
137 echo ======= $ip 远程复制完成  =======
138done
139
140#删除临时文件
141rm -rf $espathtemp
142
143for allnode in ${array3[@]}
144do
145 echo ======= 在 $allnode 手动执行 source ~/.bash_profile 在通过 elasticsearch 查看是否安装成功 =======
146done
147
148fi
149
150
151

 

es集群一键启动脚本


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1#!/bin/bash
2#配置ES的安装目录 修改的地方1 脚本可以自己创建
3esServers='cdh01 cdh02'
4#启动所有的zk
5for es in $esServers
6do
7    ssh -T $es <<EOF
8    source ~/.bash_profile
9    elasticsearch -d
10EOF
11echo 从节点 $es 启动elasticsearch...[ done ]
12sleep 5
13done
14

 

es集群一键停止脚本


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1#!/bin/bash
2
3esServers='cdh01 cdh02'
4#启动所有的zk
5for es in $esServers
6do
7    ssh -T $es <<EOF
8    source ~/.bash_profile
9    ps aux |grep elasticsearch |grep -v grep |awk '{print \$2}' |xargs kill -9
10EOF
11echo 从节点 $es 停止elasticsearch...[ done ]
12sleep 5
13done
14
15

 

 

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

详解Node.js API系列 Crypto加密模块(2) Hmac

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索