ELK组件之Elasticsearch官方Yum源安装部署案例
官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.12/rpm.html#rpm-repo
配置仓库:在 /etc/yum.repos.d/ 目录下创建 .repo文件,写入如下内容:
cat <<EOF > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
EOF
Elasticsearch官方Yum源安装部署
sudo yum install --enablerepo=elasticsearch elasticsearch -y
启动elasticsearch与查看启动日志
//启动elasticsearch
systemctl start elasticsearch
//如果启动失败可以通过以下命令查看系统日志定位问题
sudo journalctl -f
验证安装、启动是否正常:
配置文件:
[root@yihubaijia-redis yum.repos.d]# vim /etc/elasticsearch/elasticsearch.yml
安装目录:
[root@yihubaijia-redis yum.repos.d]# cd /usr/share/elasticsearch
启用xpack插件,认证登录
[root@yihubaijia-redis yum.repos.d]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
[root@yihubaijia-redis yum.repos.d]# systemctl restart elasticsearch.service
[root@yihubaijia-redis bin]# ./elasticsearch-setup-passwords interactive
[root@yihubaijia-redis yum.repos.d]# vim /etc/kibana/kibana.yml
elasticsearch.username: "elastic"
elasticsearch.password: "BH@yihubai!"
[root@yihubaijia-redis yum.repos.d]# systemctl restart kibana.service
或是自动生成密码打印在控制台:
bin/elasticsearch-setup-passwords auto -u "http://172.19.19.71:9200"
常见问题:
一、can not run elasticsearch as root
思路:
为了安全不允许使用root用户启动,es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户(使用yum安装,会自动创建elasticsearch用户,使用systemctl启动,不会出现该问题)。
解决:
[root@yihubaijia-redis yum.repos.d]# adduser elasticsearch //创建用户:elasticsearch
[root@yihubaijia-redis yum.repos.d]# passwd elasticsearch //创建用户密码,需要输入两次
[root@yihubaijia-redis yum.repos.d]# chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/ //将对应的文件夹权限赋给该用户
[root@yihubaijia-redis yum.repos.d]# su elasticsearch //切换至elasticsearch用户
[elasticsearch@yihubaijia-redis bin]# ./elasticsearch -d //进入启动目录启动 /usr/share/elasticsearch/bin 使用后台启动方式:./elasticsearch -d
二、future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_111/jre] does not meet this requirement
思路:
这个问题是因为Elasticsearch要求的jdk版本是java11 ,而本机安装的是java8,因系统环境而定,java8其实也能正常使用,如未出现上述错误请忽略即可。
安装jdk11,yum自动部署最新
yum install jdk -y
修改elasticsearch可执行文件:vim /usr/share/elasticsearch/bin/elasticsearch
#配置自己的jdk11
export JAVA_HOME=/usr/share/jdk-11.*.*
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/jdk-11.*.*/bin/java"
else
JAVA=`which java`
fi
ELK组件之Elasticsearch官方Yum源安装部署案例
https://cn.10691.cn//archives/10016