ElasticSearch
单机搭建
操作说明
- 所有命令都在root用户操作
安装JDK环境
下载ElasticSearch
解压并改名
tar -zxvf elasticsearch-6.7.0.tar.gz
mv elasticsearch-6.7.0 elasticSearch
cd elasticSearch
添加用户组/用户
- 因不能用root用户启动elasticSearch,会提示:org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
- 增加用户组:groupadd elastic
- 增加用户并归到用户组:useradd elsearch -g elastic
- 修改密码:passwd elastic
修改目录所属用户和用户组
chown -R elastic:elastic elasticSearch
修改系统相关配置
修改文件数上限
- 如果没有增加,启动会报错:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
- vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
- 检查是否修改成功
ulimit -n
修改内存权限
- 如果没有增加,启动会报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- 不能通过sysctl -w vm.max_map_count=262144这种方式(重启会失效),必须采用下面文件方式
- vim /etc/sysctl.conf
vm.max_map_count=655360
fs.file-max=655360
4.检查是否修改成功
sysctl -p
修改elasticsearch.yml
- vim config/elasticsearch.yml
- 通过/network查找,修改为虚拟机的IP
- 通过/http.port查找,修改为9200
启动
- 编写启动脚本
su -l elastic -c "/home/software/elasticsearch/bin/elasticsearch -d &"
- 启动脚本
./start.sh
访问
- 浏览器访问http://xxx.xxx.xxx.xxx:9200
- 看到如下表示成功
[外链图片转存中…(img-onFpT0qC-1606272749158)]
关闭
- 编写关闭脚本
pid=`ps -ef|grep elastic | grep -v grep |awk '{print $2}'`
kill -9 $pid
- 启动脚本
./shutdown.sh
问题解决过程
- 进入创建的elastic用户,执行sysctl -w vm.max_map_count=262144报错:permission denied on key 'vm.max_map_count
- 尝试解决
https://stackoverflow.com/questions/40451288/elasticsearch-failed-to-start-in-centos,
依然报错:xxx is not in the sudoers file.This incident will be reported-7 - 最后exit elastic,用root用户执行该命令,https://www.cnblogs.com/zox2011/archive/2013/05/28/3103824.html
- Java HotSpot™ 64-Bit Server VM warning: Cannot open file logs/gc.log due to Permission denied
- 第一次启动es使用了root用户,在config目录下创建了文件elasticsearch.keystore,只需要进入之后把文件删除,然后用es的用户启动就可以了,链接
Kibana
单机搭建
操作说明
- 所有命令都在root用户操作
下载Kibana
解压并改名
tar -zxvf kibana-6.7.0-linux-x86_64.tar
mv kibana-6.7.0-linux-x86_64 kibana
cd kibana
修改kibana.yml
- vim config/kibana.yml
server.port: 5601
elasticsearch.url: elasticSearch的访问地址
server.host: "192.168.52.167"
kibana.index: ".kibana"
启动
- 编写启动脚本
nohup ./kibana > ../logs/nohup.out 2> ../logs/error.out &
- 启动脚本
./start.sh
访问
- 浏览器访问http://xxx.xxx.xxx.xxx:5601
- 看到如下表示成功
[外链图片转存中…(img-pfhQNWbw-1606272749162)]
关闭
- 编写关闭脚本
pid=`ps -ef | netstat -tunlp | grep 5601 | awk '{print $7}' | cut -d/ -f 1`
kill $pid
- 启动脚本
./shutdown.sh
问题解决过程
- 如何关闭kibana
- 通过ps -ef|grep kibana找不到进程,因为 kibana 是node 写的。所以kibana 运行的时候是运行在node 里面
- ps -ef | netstat -tunlp | grep 5601 | awk ‘{print $7}’| cut -d / -f -1
- awk使用
- cut使用
- kibana进程找不到的原因
- 关闭kibana
Logstash
单机搭建
操作说明
- 所有命令都在root用户操作
下载Logstash
解压并改名
tar -zxvf logstash-6.7.0.tar.gz
mkdir logstash
mkdir jar
mv logstash-6.7.0 logstash/
cd logstash
修改gem源
vim Gemfile
修改source为https://gems.ruby-china.com/
下载插件
有网环境
- 去https://rubygems.org/搜索想要的插件gem
- 以logstash output jdbc为例
cd bin/
logstash-plugin install logstash-output-jdbc
无网环境
- 在能上网的机器,按有网环境步骤下载
- 以logstash output jdbc为例
cd logstash-6.7.0/vendor/bundle/jruby/2.5.0
cd gems,复制logstash-output-jdbc-5.4.0到无网机器的logstash安装目录同个位置
cd ..
cd specifications,复制logstash-output-jdbc-5.4.0.gemspec到无网机器的logstash安装目录同个位置
cd logstash-6.7.0/
vim Gemfile,找到gem "logstash-output-jdbc"并添加到到无网机器的logstash安装目录的Gemfile
启动
nohup ./logstash-6.7.0/bin/logstash -f ./logstash-6.7.0/config/dataQuality/dataQuality.conf > ./logstash-6.7.0/log-243/nohup.out &
查看日志
tail -f -n300 ./logstash-6.7.0/log-243/nohup.out
关闭
pid=`jps | grep Logstash | awk '{print $1}'`
kill $pid
问题解决过程
- Validating logstash-output-jdbc
Unable to download data from https://gems.ruby-china.com/ - SocketError: Failed to open TCP connection to gems.ruby-china.com:443 (initialize: name or service not known) (https://gems.ruby-china.com/latest_specs.4.8.gz)
ERROR: Installation aborted, verification failed for logstash-output-jdbc
- 因为ping外网都ping不通
- vim /etc/sysconfig/network-scripts/ifcfg-ens33,BOOTPROTO改为dhcp
- systemctl restart network