文章目录
待续…
ELK
- Elasticsearch: 分布式全文检索引擎,用于存储、检索数据,
- Logstash: 用于收集日志
- Kibana: 通过Web端的可视化界面来查看日志
es集群部署
环境介绍
-
三台虚拟机:
cache01
cache02
cache03 -
ES不能使用root用户来启动,必须使用普通用户来安装启动
创建用户组:
groupadd es
再创建用户:
useradd es -g es -G es -b /设置密码
passwd es 空格,按提示输入密码为普通用户es添加sudo权限
visudo
es ALL=(ALL) ALL
部署
上传 elasticsearch-6.7.0.tar.gz
上传 elasticsearch-6.7.0.tar.gz到/es目录下
mkdir -p /export/servers/es
chown -R es /export/servers/es
解压缩
tar -xvf elasticsearch-6.7.0.tar.gz -C /export/servers/es/
修改配置文件
cd /export/servers/es/elasticsearch-6.7.0
mkdir -p /export/servers/es/elasticsearch-6.7.0/logs
mkdir -p /export/servers/es/elasticsearch-6.7.0/datas
修改elasticsearch.yml
vi elasticsearch.yml
cluster.name: myes
node.name: node01
path.data: /export/servers/es/elasticsearch-6.7.0/datas
path.logs: /export/servers/es/elasticsearch-6.7.0/logs
network.host: 192.168.52.100
http.port: 9200
discovery.zen.ping.unicast.hosts: ["node01", "node02", "node03"]
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.cors.enabled: true
http.cors.allow-origin: "*"
修改jvm.option
修改jvm.option配置文件,调整jvm堆内存大小(每个人根据自己服务器的内存大小来进行调整)
分发其它节点及配置:
scp -r elasticsearch-6.7.0/ cache02:$PWD
scp -r elasticsearch-6.7.0/ cache03:$PWD
更改其它两个节点elasticsearch.yml文件中的参数:node.name和network.host
sudo vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
修改系统配置,解决启动时候的问题
由于现在使用普通用户来安装es服务,且es服务对服务器的资源要求比较多,包括内存大小,线程数等。所以我们需要给普通用户解开资源的束缚
解决启动问题一:普通用户打开文件的最大数限制
问题错误信息描述:
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
ES因为需要大量的创建索引文件,需要大量的打开系统的文件,所以我们需要解除linux系统当中打开文件最大数目的限制,不然ES启动就会抛错
三台机器使用es用户执行以下命令解除打开文件数据的限制
sudo vi /etc/security/limits.conf
添加如下内容: 注意*不要去掉了
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
解决启动问题二:普通用户启动线程数限制
问题错误信息描述
max number of threads [1024] for user [es] likely too low, increase to at least [4096]
修改普通用户可以创建的最大线程数
max number of threads [1024] for user [es] likely too low, increase to at least [4096]
原因:无法创建本地线程问题,用户最大可创建线程数太小
解决方案:修改90-nproc.conf 配置文件。
三台机器使用es用户执行以下命令修改配置文件
sudo vi /etc/security/limits.d/20-nproc.conf
找到如下内容:
* soft nproc 1024
#修改为
* soft nproc 4096
解决启动问题三:普通用户调大虚拟内存
错误信息描述:
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
调大系统的虚拟内存
原因:最大虚拟内存太小
每次启动机器都手动执行下。
三台机器执行以下命令
vi /etc/sysctl.conf
vm.max_map_count=262144 # 添加此行
退出文件后,执行命令:
sysctl -p 立即生效
启动
nohup /export/servers/es/elasticsearch-6.7.0/bin/elasticsearch 2>&1 &
启动成功之后jsp即可看到"Elasticsearch"进程,并且访问页面
http://cache01:9200/?pretty
能够看到es启动之后的一些信息
安装elasticsearch-head插件
由于es服务启动之后,访问界面比较丑陋,为了更好的查看索引库当中的信息,我们可以通过安装elasticsearch-head这个插件来实现,这个插件可以更方便快捷的看到es的管理界面
安装nodejs
cd es
wget https://npm.taobao.org/mirrors/node/v8.1.0/node-v8.1.0-linux-x64.tar.gz
tar -xvf node-v8.1.0-linux-x64.tar.gz -C /export/servers/es/
创建软连接
sudo ln -s /export/servers/es/node-v8.1.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
sudo ln -s /export/servers/es/node-v8.1.0-linux-x64/bin/node /usr/local/bin/node
sudo vim /etc/profile
export NODE_HOME=/export/servers/es/node-v8.1.0-linux-x64
export PATH=:$PATH:$NODE_HOME/bin
修改完环境变量使用source生效
source /etc/profile
验证安装成功
node01执行以下命令验证安装生效
node -v
npm -v
安装elasticsearch-head插件
直接使用提供的编译之后的源码包解压之后修改配置文件即可.
elasticsearch-head-compile-after.tar.gz
tar -xvf elasticsearch-head-compile-after.tar.gz -C /export/servers/es/
修改Gruntfile.js
cd /export/servers/es/elasticsearch-head
vi Gruntfile.js
connect: {
server: {
options: {
hostname: '192.168.80.10',
port: 9100,
base: '.',
keepalive: true
}
}
}
修改app.js
cd /export/servers/es/elasticsearch-head/_site
vi app.js ,更改this.base_uri 参数"http://cache01:9200"
app.App = ui.AbstractWidget.extend({
defaults: {
base_uri: null
},
init: function(parent) {
this._super();
this.prefs = services.Preferences.instance();
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://cache01:9200";
if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
// XHR request fails if the URL is not ending with a "/"
this.base_uri += "/";
}
if( this.config.auth_user ) {
var credentials = window.btoa( this.config.auth_user + ":" + this.config.auth_password );
$.ajaxSetup({
headers: {
"Authorization": "Basic " + credentials
}
});
}
启动
cd /export/servers/es/elasticsearch-head/node_modules/grunt/bin/
进程后台启动命令
nohup ./grunt server >/dev/null 2>&1 &
停止进程
netstat -nltp | grep 9100
kill -9 8328
访问页面
http://192.168.80.10:9100/
安装Kibana
cd /es
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.7.0-linux-x86_64.tar.gz
tar -xvf kibana-6.7.0-linux-x86_64.tar.gz -C /export/servers/es/
kibana.yml
cd /export/servers/es/kibana-6.7.0-linux-x86_64/config
vi kibana.yml
server.host: "cache01"
elasticsearch.hosts: ["http://cache01:9200"]
启动
nohup bin/kibana >/dev/null 2>&1 &
查看是否启动
ps -ef | grep node
访问页面
http://cache01:5601
安装LogStash
cd /es
下载 wget https://artifacts.elastic.co/downloads/logstash/logstash-6.7.0.tar.gz
解压 tar -xvf logstash-6.7.0.tar.gz -C /export/servers/es/