centos8.2 elasticsearch7.11.1 kibana安装 成功

1. 下载elasticsearch

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.11.1-linux-x86_64.tar.gz
cd elasticsearch-7.11.1
./bin/elasticsearch

2.启动elasticsearch

   2.1 创建专用用户组和用户,root无法启动

groupadd es
useradd esuser -g es
passwd esuser

  2.2更改文件夹及内部文件的所属用户及组

chown -R esuser:es /usr/local/elasticsearch-7.11.1

  2.3 切换用户 到esuser

su esuser

  2.4 elasticsearch 配置

vim /usr/local/elasticsearch-7.11.1/config/elasticsearch.yml

添加两行,注意:冒号后面要带一个空格

network.host: 0.0.0.0

cluster.initial_master_nodes: ["node-1"]

  2.5 设置elasticsearch用户拥有的内存权限,至少需要262144

su root
vim /etc/sysctl.conf

 末尾添加一行:
 vm.max_map_count=262144

/sbin/sysctl -p

 2.6 jvm内存调小一些

vim /usr/local/elasticsearch-7.11.1/config/jvm.options

新增两行,将内存调整至512m

  -Xms512m
  -Xmx512m

2.7 自定义管理脚本

vim /etc/init.d/elasticsearch在其中输入下方的脚本代码
复制代码
#!/bin/bash
#chkconfig: 2345 80 90
#description:elasticsearch
export ES_HOME=/usr/local/elasticsearch-7.11.1
case $1 in
        start)
                su esuser<<!        
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
                ;;
        stop)
                pid=`cat $ES_HOME/pid`
                kill -9 $pid
                echo "elasticsearch is stopped"
                ;;
        restart)
                pid=`cat $ES_HOME/pid`
                kill -9 $pid
                echo "elasticsearch is stopped"
                sleep 1
                su esuser<<!    
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
        ;;
    *)
        echo "start|stop|restart"
        ;;  
esac
exit 0 
复制代码
#在命令行执行下面命令,赋予脚本执行权限
chmod +x elasticsearch

 

 命令:

#启动
/etc/init.d/elasticsearch start
#停止
/etc/init.d/elasticsearch stop
#重启
/etc/init.d/elasticsearch restart

启动后,命令行输入curl -XGET http://localhost:9200,得到以下响应说明启动成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "name" "localhost.localdomain",
  "cluster_name" "elasticsearch",
  "cluster_uuid" "_na_",
  "version" : {
    "number" "7.11.1",
    "build_flavor" "default",
    "build_type" "tar",
    "build_hash" "ff17057114c2199c9c1bbecc727003a907c0db7a",
    "build_date" "2021-02-15T13:44:09.394032Z",
    "build_snapshot" false,
    "lucene_version" "8.7.0",
    "minimum_wire_compatibility_version" "6.8.0",
    "minimum_index_compatibility_version" "6.0.0-beta1"
  },
  "tagline" "You Know, for Search"
}

4、kibana安装

curl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-7.11.1-linux-x86_64.tar.gz
tar xzvf kibana-7.11.1-linux-x86_64.tar.gz
cd kibana-7.11.1-linux-x86_64/
./bin/kibana

都是开箱即用,建议手动移动目录到/usr/local/下

启动kibana

   4.1 创建专用用户组和用户,root无法启动

Kibana should not be run as root. Use --allow-root to continue.

useradd kibana -g es
passwd kibana

  4.2更改文件夹及内部文件的所属用户及组

chown -R esuser:es /usr/local/kibana-7.11.1-linux-x86_64

仿照搞一个kibana的启动脚本

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
#!/bin/bash
#chkconfig: 2345 80 90
#description:kibana
 
 
export KB_HOME=/usr/local/kibana-7.11.1-linux-x86_64
case $1 in
        start)
                su kibana<<!
                cd $KB_HOME
                nohup ./bin/kibana &
                exit
!
                echo "kibana is started"
                ;;
        stop)
                pid=`cat $KB_HOME/pid`
                kill -9 $pid
                echo "kibana is stopped"
                ;;
        restart)
                pid=`cat $KB_HOME/pid`
                kill -9 $pid
                echo "kibana is stopped"
                sleep 1
                su kibana<<!
                cd $KB_HOME
                nohup ./bin/kibana &
                exit
!
                echo "kibana is started"
        ;;
    *)
        echo "start|stop|restart"
        ;;
esac
exit 0

赋予权限:

#在命令行执行下面命令,赋予脚本执行权限
chmod +x elasticsearch

脚本启动命令

#启动
/etc/init.d/kibana start
#停止
/etc/init.d/kibana  stop
#重启
/etc/init.d/kibana restart

此处停止、重启命令都不好使,需要使用查找进程、杀死进程的方法,不然运行停止、重启命令不好使还找不到哪里的问题!!

至此,本可以通过/etc/init.d/kibana运行,但是报错,所以修改上面脚本中的启动命令为:

1
nohup ./bin/kibana &

至此,可以启动kibana了 ,然后需要开放5601端口

在浏览器中输入ip:5601显示无法打开,应该是端口没开放的原因,查看端口状态命令:firewall-cmd --query-port=5601/tcp
 
开启端口命令:firewall-cmd --zone=public --add-port=5601/tcp --permanent
 
重新加载防火墙:firewall-cmd --reload
 
再输入地址端口号,可以正确显示页面

配置#

修改es的配置文件:elasticsearch.yml,添加如下配置

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

es的bin目录下,执行设置用户名和密码的命令

./elasticsearch-setup-passwords interactive

这里会设置六个账号的密码:elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.

image-20210425122400164

修改kibana的配置kibana.yml

image-20210425123351140

es修改密码的命令如下:

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://192.168.140:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

重启es和kibana

访问http://192.168.1.40:9200,需要输入账号密码才可以访问

image-20210425123533151

访问:http://192.168.1.40:5601/

同样需要认证才可登陆,登陆账号密码为elastic/123456

image-20210425123637430

posted @ 2022-03-15 09:06  _海阔天空  阅读(150)  评论(0编辑  收藏  举报