CentOS7下搭建elasticsearch集群

下载

1
2
3
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.0-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.13.0-linux-x86_64.tar.gz
wget https://github.com/lmenezes/cerebro/releases/download/v0.9.4/cerebro-0.9.4.tgz

解压

1
2
3
4
5
6
7
8
9
10
11
mkdir \home\es
mv elasticsearch-7.13.0-linux-x86_64.tar.gz \home\es
mv kibana-7.13.0-linux-x86_64.tar.gz \home\es
mv cerebro-0.9.4.tgz \home\es
cd \home\es
tar xvf elasticsearch-7.13.0-linux-x86_64.tar.gz
tar xvf kibana-7.13.0-linux-x86_64.tar.gz
tar xvf cerebro-0.9.4.tgz
mv elasticsearch-7.13.0 node-1
mv kibana-7.13.0-linux-x86_64 kibana
mv cerebro-0.9.4 cerebro

安装

Elasticsearch

配置es

节点相关配置

1
2
3
4
5
6
7
8
9
10
11
12
echo -e "\n" >> /home/es/node-1/config/elasticsearch.yml
echo "cluster.name: es_cluster_1" >> /home/es/node-1/config/elasticsearch.yml
echo "node.name: node-1" >> /home/es/node-1/config/elasticsearch.yml
echo "path.data: ./data" >> /home/es/node-1/config/elasticsearch.yml
echo "path.logs: ./logs" >> /home/es/node-1/config/elasticsearch.yml
echo "http.port: 9211" >> /home/es/node-1/config/elasticsearch.yml
echo "transport.port: 9301" >> /home/es/node-1/config/elasticsearch.yml
echo "network.host: 0.0.0.0" >> /home/es/node-1/config/elasticsearch.yml
echo "discovery.seed_nodes: [\"localhost:9301\"]" >> /home/es/node-1/config/elasticsearch.yml
echo "cluster.initial_master.nodes: [\"node-1\",\"node-2\",\"node-3\"]"
echo "-Xms1g" >> /home/es/node-1/config/jvm.options
echo "-Xmx1g" >> /home/es/node-1/config/jvm.options
启动es

es不能以root用户运行,所以先配置一个用户

1
2
3
4
adduser es
chown -R es:es /home/es
su es
/home/es/node-1/bin/elasticsearch -d
查看es日志
1
2
cd /home/es/node-1/logs
less es_cluster_1.log

Kibana

配置kibana
1
2
echo -e '\nserver.host: "0.0.0.0"' >> /home/es/kibana/config/kibana.yml
echo -e '\nelasticsearch.hosts: ["http://localhost:9211"]' >> /home/es/kibana/config/kibana.yml
启动kibana
1
2
cd /home/es/kibana
./bin/kibana >> run.log 2>&1 &
浏览kibana
1
localhost:5601

Cerebro

配置Cerebro
1
2
3
4
5
6
7
8
cd /home/es/cerebro
sed -i 's/server.http.port = ${?CEREBRO_PORT}/server.http.port = 9800/g' conf/application.conf
echo -e '\nhosts = [
{
host = "http://localhost:9211"
name = "es_cluster_1"
}
]' >> conf/application.conf
启动Cerebro
1
./bin/cerebro >> run.log 2>&1 &