易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 40|回复: 6
收起左侧

elasticsearch8版本安装详细步骤(集群安装)

[复制链接]
发表于 2024-10-31 15:53:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
7 N! _* Q- z# R; K( k
, Z' H* D3 |. S+ A
elasticsearch8版本安装详细步骤
3 {6 C* [; e. l) Q3 U; Y
5 `0 A- H' `, v* K7 @/ d+ Z+ `# M0 D
+ G" g$ J5 b" x! y3 A5 }
1、设置虚拟内存
- S/ f( X# e6 ~3 Csysctl -w vm.max_map_count=2621443 |* K  j2 g* L4 S% v
echo "vm.max_map_count=262144" >> /etc/sysctl.conf,
  B- p3 h2 g8 C% i8 |3 k0 J: N. W: \echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
8 m0 X- Q1 F3 O6 F$ X
3 ^1 Y# ~0 V0 O2 |8 i- K
3 O3 h4 l+ K% a/ [
4 `+ M, ^  M  v. i* Z

+ O8 U7 w# K$ I  y4 x9 |. G  W. g加入:vm.max_map_count=262144$ |9 H9 [2 \( \- k' r
使配置生效:sysctl -p3 T% ~, D6 }' d( P

, k  e) A! i2 U# w/ q/ z, S

4 ?7 d5 ?8 e  g2 t2、设置文件打开数:* K, O; ?5 b9 X& w
cat >>/etc/security/limits.conf<<EOF
5 A0 z+ w5 c5 r* soft nofile 65535" [. s3 Z  n" @) S: O$ x; C: T
* hard nofile 65535
9 |' r/ f8 S+ s( H0 X* soft nproc 65535& R) Q3 a0 O2 o2 C0 F
* hard nproc 65535
+ Z, x& F4 J2 u1 yEOF* O- i- _) p' V7 I6 N1 B

$ K- Z% W# X2 Y( {  ?: U' J
" z2 h1 C( @% \' Y" k! }

9 m: T" r' p7 Z6 w( O& K9 n. a

( Y" I; X# ~0 V- ?4 L: h设置pam配置:! Y% a7 o* \0 B2 ?) ^, c
echo "session    required pam_limits.so" >> /etc/pam.d/login
: s/ X+ V; q3 t+ k7 t& G! L' E4 W3 b$ @1 ^( `
1 J" t5 ?/ ]( N. [* Q; Y

. O( C$ j- q; j  L+ {/ v$ c

/ g0 l& X( L& I; A! _, u3、禁用swap交换分区+ p" e" w0 G% P8 j
swapoff -a                #临时禁用
) m3 z. L) r2 W8 `% P0 v# T! U* cvi /etc/fstab        #永久禁用  R1 H4 o; S; N& D
找到swap这一行前面使用#符号禁用掉
4 J* s1 g* C3 H0 Q
: X% |0 a8 q- m2 l0 W

# I- P9 `0 d' [3 Z' o% F( b4、设置TCP重传超时8 g. e5 L, B; k
sysctl -w net.ipv4.tcp_retries2=50 |* w  q# e2 X$ B
编辑配置文件:echo "net.ipv4.tcp_retries2 = 5" >> /etc/sysctl.conf
( E- Q3 y& I% c1 m
& ~2 q% \' i$ U/ r( L
( {1 W* S" [5 [& V. j8 c
5、创建一个用户# t8 H& p4 a. s$ V) Z! i
useradd es
6 L. [" V! T. n
$ D/ x4 ?/ Y  U/ [, ?$ A
2 W. v! {  z' [% f( H; w9 ^# P
6、创建安装目录, o" j# M+ D: J8 ?, A7 }* W
mkdir /data/elasticsearch/- ~, s! w) W# m  r6 ~- O9 U
mkdir /data/elasticsearch/elastic-cluster1
$ c# Q3 B* `5 h, m
! x2 C4 Y3 O- |& `2 f

  ?" M$ p. b9 l' Pmkdir /data/elasticsearch/elastic-cluster2
3 X7 A- `, N& Y$ s7 r; o" y# e$ P
# k7 ]- ]- O6 |# y4 n# R8 T

* K, `+ K  F* g  p% a) ]2 ~) y6 k9 @& J0 l: N% [! v

0 X0 X% P2 @+ H( H+ u1 W6 C2 K
* G9 b& [! N6 h9 ?. m
[root@it-elassearch ~]# ls -p /data/elasticsearch& j/ }$ o$ q0 l! W9 J' g" P
elastic-cluster1/  elastic-cluster2/
3 P7 m1 p1 S  n- S2 e+ x# E' n
: J' ?8 c4 X1 K6 U, W
; r2 v* ?* L" u; i$ u) |
. Q3 n8 ~# x4 J/ A

) P8 [9 m9 b- ?* P8 q
/ A3 T; l0 N# i( R$ x8 O# x! h
' H4 V3 ~* ~4 [) W7 i# P  Q$ Q
7、下载官网安装包. D5 n! n' B' u$ Z# P* j
官网下载地址,选择对应版本的elasticsearch和kibana:https://www.elastic.co/cn/downloads/past-releases#elasticsearch: v; C+ E+ y6 E: I" X7 s) f4 t
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
8 H' ?+ j0 T7 U( x7 K: Q2 M6 U5 A1 E/ |  j
* T" D, B: {1 r' R- [# L8 c
[root@it-elassearch-2 ~]# chown es:es elasticsearch-8.15.0-linux-x86_64.tar.gz ; m  z  h% r5 ]
[root@it-elassearch-2 ~]# mv elasticsearch-8.15.0-linux-x86_64.tar.gz /data/elasticsearch/
  H# c& @* j! A9 R2 V
) K3 u! _; N. `% F

% E, X  h5 {8 I0 w0 ^切换到es账号:! ?: k- E0 Z; ~" k" V5 [

7 s( O  Q/ g# @1 K+ S8 P

6 r* ?( x# D& W) p7.1 解压:我的安装包下载到了目录下,解压到/elasticsearch/elastic-cluster1/目录下0 C# A+ S! t8 m' z/ V: m2 s1 C

- v! t. ]6 k, E4 z% h

9 |  m; z- y) ^cd /data/elasticsearch/elastic-cluster15 q+ W2 p% F% u$ a# D
[es@it-elassearch elastic-cluster1]$ ls
2 B+ n/ i; m  `' G+ z3 M  O8 c8 ^8 N' D, o/ W0 h! w6 J# `
elasticsearch-8.15.0-linux-x86_64.tar.gz2 I9 v6 n% i. A, M

; D- g( P$ z; z% Q1 X$ ]
' Y1 p; p8 F; F  Y' I
/data/elasticsearch/elastic-cluster2
# U  ^( p3 j" y[es@it-elassearch-2 elastic-cluster2]$ ls
/ {4 I8 T& Q$ |7 W: j5 qelasticsearch-8.15.0-linux-x86_64.tar.gz- m9 f. v# `1 R6 P6 W- Z
4 K1 X* Q  {" A* }
2 f& s. L# b, `1 C
解压:
0 ]  U  B2 }# \9 O+ K0 b/ {
2 h+ V, X+ E8 w' r% M[es@it-elassearch elastic-cluster1]$ tar -zxvf elasticsearch-8.15.0-linux-x86_64.tar.gz
- T, I) O8 D  M! G" H( a
+ s  [3 k4 E8 Z/ i
" V; A5 [, U0 }, Z3 b/ p

! T! h& T& k8 Q4 p

! g0 h" R! L, f$ c[es@it-elassearch-2 elastic-cluster2]$ tar -zxvf elasticsearch-8.15.0-linux-x86_64.tar.gz9 M) q. R6 o3 s) `$ h0 P1 r4 W2 o
# z! Z1 Y* @* k1 A8 w0 U/ [% o
2 ?" K; u7 ?: A0 z1 i5 Z3 H& l
进入对应目录下:cd /elasticsearch/elastic-cluster1
3 ~4 k: d- t8 K2 R4 w5 s6 Q+ c4 N8 F4 E% d) L

% }6 S3 A5 R: ^" h配置es参数文件:: T+ u5 v7 G- V4 |
: C+ S4 A- s, z2 ]8 t* G
4 p1 j2 O/ z  f* P
节点一配置:( z. J  H6 g  s7 }4 o
#vim elasticsearch-8.15.0/config/elasticsearch.yml
' p8 F4 ]) ^  I. L3 F; K& M! l
; S# l6 w( y/ p7 f" I. t

8 Z+ m2 R  V# s$ Z7 Y" o; q: ncluster.name: essearch7 J! N' f5 F; S2 Q  e
node.name: it-elassearch8 b5 Q! A1 t4 a4 w: X9 J- R; s
path.data: ./elasticsearch-8.15.0/data
/ O* \4 j( w' _path.logs: ./elasticsearch-8.15.0/logs
  J  W: k) w$ O4 r' R9 [network.host: 0.0.0.0
' J4 H2 v( m9 Z: w) E+ Rhttp.port: 9200! E4 j1 v; e% e* i8 ^0 h1 Q
discovery.seed_hosts: ["172.24.110.125", "172.24.110.126"]! n& {! e* X, V
cluster.initial_master_nodes: ["it-elassearch", "it-elassearch-2"]
4 n) b( [& d; |$ U, x#node.master: true8 k  A7 {! x! [
#node.data: true
. w& F0 M% n# f. {" v: Y) E& q( l; S' i, Z& s0 C( N9 `

+ t( r5 U8 O! ?% Fxpack.security.transport.ssl.enabled: false
" {0 Z* s$ m3 ixpack.security.enabled: false
# p9 w2 a/ \# V# l, U8 V5 j4 ~0 u7 {$ `! K8 n7 j4 \

0 J+ Y! U6 W3 b  j下面是加鉴权的配置:9 q  g8 @: e" _
cluster.name: essearch; m, v' w5 _( c  ]2 x9 f: [+ A% e
node.name: it-elassearch7 U* q3 M; D. b  k1 c" M( m6 x
path.data: ./elasticsearch-8.15.0/data; Q! Z4 S, U  I. ]+ j
path.logs: ./elasticsearch-8.15.0/logs
4 ]1 B$ V2 p  qnetwork.host: 0.0.0.0
9 l/ e) E& U- I7 [: {. z2 vhttp.port: 92003 Z. ^- \6 r" D  [) a& V
discovery.seed_hosts: ["172.24.110.125", "172.24.110.126"]1 s9 V8 L* Q  t- g
cluster.initial_master_nodes: ["it-elassearch", "it-elassearch-2"]
" j  t$ N6 y3 ohttp.cors.enabled: true5 O! U8 B( ]4 h* z; h9 n! K8 K* r
http.cors.allow-origin: "*"
: G( k4 A5 u# T2 w6 v* B& c2 xhttp.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length7 ]. H4 D( ~# t% h4 X7 s
xpack.security.enabled: true
  R1 q! l( r) W#xpack.security.authc.accept_default_password: true
# L, }& C: Q0 Q! Z6 m: r9 z: Sxpack.security.transport.ssl.enabled: true
5 d: @4 Y3 q/ ~6 Txpack.security.transport.ssl.verification_mode: certificate; {8 ^+ S+ \5 t8 p
xpack.security.transport.ssl.keystore.path: /data/elasticsearch/elastic-cluster1/elasticsearch-8.15.0/config/certificates/elastic-certificates.p12$ Y7 n. R( q$ m  T
# V  f5 S% i" q& ~" I3 t
xpack.security.transport.ssl.truststore.path: /data/elasticsearch/elastic-cluster1/elasticsearch-8.15.0/config/certificates/elastic-certificates.p12
# b  g* D) @8 x, J8 N! X: B2 \8 I3 S9 H3 Q' J. v3 @1 R" ]: R) R
: C' \: g8 Z' g6 o0 }9 b

! C$ c" t+ W- s. `" u9 ~
8 ?0 T& p" n; ?- T
节点二配置
) @* c" `: @  L7 y3 _#vim elasticsearch-8.15.0/config/elasticsearch.yml
7 A% N* I4 M; [7 u* D  H3 M- o+ r( G

7 ^; y9 n3 A6 [. ]4 s5 m2 d/ h3 Y. ~cluster.name: essearch6 }2 {- A. i4 H6 t  }
node.name: it-elassearch-2
* @$ E! _+ K6 N' q" cpath.data: ./elasticsearch-8.15.0/data2 y# d: l( N- b4 q" ?/ f+ b1 W% W
path.logs: ./elasticsearch-8.15.0/logs
8 E, r# h7 X7 O7 Mnetwork.host: 0.0.0.0
9 F, f3 a5 R) zhttp.port: 9200! P+ @& i- i5 d% }. H$ I
discovery.seed_hosts: ["172.24.110.125", "172.24.110.126"]
7 U+ b' e8 A5 Acluster.initial_master_nodes: ["it-elassearch", "it-elassearch-2"]9 a- t# G2 c1 y! J, J3 x" u2 J
#node.master: true
1 T% c& R7 j  @+ V; {" M: G3 i#node.data: true
7 n' V9 Y3 ]# z. g! W8 \! @7 b! A8 u5 J0 e+ n0 g9 m& Z
/ w& M( o1 d0 a! f6 _9 K, E3 m
xpack.security.transport.ssl.enabled: false1 U. H* k. X7 _5 t! U+ h: ?
xpack.security.enabled: false
- u2 y7 @) @9 e+ N9 U
' z* F0 T% v# K6 ^* Y; }
2 S, P' s+ d/ g. ^  _
下面是鉴权的配置:  n; ~, J3 f% c& \/ c
cluster.name: essearch( H. z. f+ L9 M: t
node.name: it-elassearch-2* N! m6 v. O! i; h2 i
path.data: ./elasticsearch-8.15.0/data
# J" E" h: u* B5 gpath.logs: ./elasticsearch-8.15.0/logs9 u8 M9 ^1 i1 ]- ^+ A' R" o
network.host: 0.0.0.0, G6 s2 q- I/ L7 V0 q
http.port: 9200
% k8 C  U; b/ N/ B2 ^: G* zdiscovery.seed_hosts: ["172.24.110.125", "172.24.110.126"]
1 {, Y( I) b5 {1 c6 i* {cluster.initial_master_nodes: ["it-elassearch", "it-elassearch-2"]
/ F* V6 q# u; @8 chttp.cors.enabled: true
$ ]/ z' l! o' g8 }- ohttp.cors.allow-origin: "*"0 U1 L6 G+ ^; k# I, I
http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length
% _6 ?+ }+ t$ Q% ]1 Uxpack.security.enabled: true! g: y- ~7 B$ F( Y* i
#xpack.security.authc.accept_default_password: true$ G/ ]7 g- _, |9 u* Q
xpack.security.transport.ssl.enabled: true
1 o# n" S2 P2 }xpack.security.transport.ssl.verification_mode: certificate
4 M" e0 `$ j1 i# Mxpack.security.transport.ssl.keystore.path: /data/elasticsearch/elastic-cluster2/elasticsearch-8.15.0/config/certificates/elastic-certificates.p127 D7 M$ x# Y* R* X% l: I( k

1 _6 n; U! O. Xxpack.security.transport.ssl.truststore.path: /data/elasticsearch/elastic-cluster2/elasticsearch-8.15.0/config/certificates/elastic-certificates.p127 r  _* y: N' Z) d- i
+ t0 K( x, ~1 g* U

7 K* ?. Z( X$ o- r3 E6 ^1 w
9 Y/ y3 v( X) }7 s6 K$ ]9 C

7 h+ I7 E  n0 I' Y( R- |3 \[color=rgba(0, 0, 0, 0.75)]JVM堆内存大小设置
  z8 D, t1 z! A  C' Q设置内存大小:
" O! d7 c7 N$ D/ e4 H# i' |" C8 j
( ?7 r$ L$ i( }

- L( x9 t; p. @$ C; R. `
  E& |0 |% |* L

1 q! x( }+ A0 d' Y+ w! Tvim elasticsearch-8.15.0/config/jvm.options+ v- F- P- Y9 l5 j) y( b

; I$ q6 Y% C, }1 r4 B

/ d+ p& j. W, e7 C* T3 N! o: A1 K7 s8 Q, J% B# w8 B$ W

: _7 U) Z5 a, G6 l/ z-Xms4g0 |$ b) E; B* H
-Xmx4g
  t3 L: ?+ F# ^8 {1 R( y% o
+ z. N# ^2 \: ], P

, d. |) X* O3 }. B' |" \
0 q+ ]& G7 z6 @) f* \
  b2 S' N6 d! Z* Q9 D% W$ f
实际业务线上环境,建议所有Elasticsearch节点都是独立节点,不要部署其他程序、其他后台进程,以提高性能。如果内存足够大,比如:128GB、256GB,单节点是浪费,建议通过虚拟化方式切分开。
6 c) e' _( [+ U/ B  Q9 A! ^$ L  T
( z5 Y' N$ D, |5 w! t
7 b1 h  i4 e& P1 q3 i% }6 ^1 E
/ I; V2 F" \7 N1 I% K% M7 O

8 d- W! {# V, j( Q) K0 U+ K. D' Z, S# a4 W0 p, l+ Q
% _" K* ^+ P) ?
解释:+ J/ D$ L  u: R: w  \, {3 t$ g
+ n6 w; n0 a( K% `2 `; O& V8 K
% N& \9 x: D& \5 b& c
目录结构/ G9 A/ D- u  H# z9 h2 T- u+ C) W, n. V3 R
Type        Description        Default Location        Setting
* x* u' L0 s) R$ }1 S6 Ahome        Elasticsearch 主目录或 $ES_HOME        Directory created by unpacking the archive        5 D8 Q4 C  E3 w
bin        二进制脚本,包括用于启动节点的 elasticsearch 和用于安装插件的 elasticsearch-plugin        $ES_HOME/bin        0 d2 m  I% E+ U" T& y
conf        配置文件,包括但不限于elasticsearch.yml        $ES_HOME/config        ES_PATH_CONF
+ O( X7 `# d+ y5 t- jconf        为传输层和 HTTP 层生成 TLS 密钥和证书        $ES_HOME/config/certs        
: C. z3 A! \6 G* b* N; qdata        节点上分配的每个索引/分片的数据文件的位置        $ES_HOME/data        path.data
. L1 A. U4 z% ~( U: tlogs        日志文件位置        $ES_HOME/logs        path.logs
( j. [+ K9 Y: y" J' b1 t- F. Aplugins        插件文件位置。每个插件将包含在一个子目录中        $ES_HOME/plugins        # _6 l9 v5 Y2 D  b  z* r7 J& O
repo        共享文件系统存储库位置。可以容纳多个位置。文件系统存储库可以放置在此处指定的任何目录的任何子目录中        Not configured        path.repo
# [+ z' c- C9 g1 S
# |) H& M7 i: v1 p2 p集群名称设置:cluster.name:
3 u' w" k" y( P节点名称:node.name:
" m( ]8 r1 [* I1 r/ r* @. o: M, i, o网络主机设置:network.host:0 B1 r: u! u/ g3 c' B  \' a7 F' Y
发现形成集群:discovery.seed_hosts:
9 B1 Q5 v  l' p" S3 `选举主节点master资格的节点:cluster.initial_master_nodes:- D3 N+ R. p- X: Y1 s- \
设置集群间通信端口:transport.port:
+ x0 \3 R: H1 X5 y设置数据存放位置:path.data:$ N$ @1 p$ w5 m+ ^3 x0 x$ D
设置日志存放位置:path.logs:
) v3 f/ ]- K% W3 h4 y
( I  \3 s* K/ `) ~4 q0 lcluster.name: CollectorDBCluster
* R; L" B0 @2 ?: D$ epath.data:/data/elasticsearch/data
# K% v6 ^7 C' Bpath.logs: /data/cusc-logs
: }# ]3 r  x, K' k: E+ ]' pnetwork.host: 10.153.61.71
" `; q! F5 A. s$ m4 whttp.pち中o砗rt: 9200( \" d. g: t3 z/ Z9 u  c7 z
node.name:node-1
0 T0 c* o, t. _5 dcluster.initial master nodes: ["node-1”1) i7 i+ b% w& w7 D' d
各配置项含义:
- w- c" y# Z0 \4 Q0 gcluster.name 集群名称,各节点配成相同的集群名称。0 ]+ _1 H( a  g- T, \4 G% m( P% t8 x
node.name 节点名称,各节点配置不同。1 L( V6 ]% m0 k, d+ _" e
node.master 指示某个节点是否符合成为主节点的条件。: W6 n: A1 U" M+ J5 p7 T/ ^
node.data 指示节点是否为数据节点。数据节点包含并管理索引的一部分,
$ G7 L' r# g) |path.data 数据存储目录。
' y  ^6 T6 v: r# Bpath.logs 日志存储目录。, y% ~: K/ i6 i* D2 y& E
bootstrap.memory lock 内存锁定,是否禁用交换7 X6 z  q8 M/ o  A
bootstrap.system call filter 系统调用过滤器。1 d9 h: n$ A4 U1 }  K; F' }
network.host 绑定节点IP。' X; ?. ]! X- G& a
http.port 端囗。
1 {0 @8 Q$ A5 A, u4 t5 k
0 g" |3 H3 q5 H) w4 O- v4 V" x启动集群:  h8 @: k! G5 M3 }3 b3 f, d$ {
: r, C. {, I3 F, D- T# m/ ~
& E* {2 V9 ?; f! i1 O+ e3 s

9 _9 @. Q6 V6 D% I

  O  ^3 Z7 J* ^9 E+ A* D配置文件属组权限,并启动
; o' V/ P8 k' W: C' k' s1 Y[root@it-elassearch elasticsearch]# chown -R es:es elastic-cluster1/3 l, T# R0 Q2 T, Y/ \
[root@it-elassearch-2 elasticsearch]# chown -R es:es elastic-cluster2/6 ~) H/ [9 L# o8 c8 B3 A" X

; N5 d1 V5 J* H$ D7 y
6 l/ a! O. G: r4 N- {
如果直接用es账号配置的,可以不做上面的操作:
. ?1 p6 P/ u- ]
* l) w* p6 R3 b' s) T# u0 J+ `2 K
7 g/ M/ x/ U: Z0 P
$ D4 P* j# Q" C' y: `
3 N3 H! n6 t! G
如果添加鉴权配置请按照此处配置,不配置即可略过:/ [( d. F/ j+ [) k* X7 F# g% m

1 l6 e0 c( T4 y* T9 ^: {

! }; ]# |( I: q/ d) E6 Tes开启认证详细步骤:9 A% @4 [3 a) J

3 }" e7 k+ T; S6 V. h$ q% }

* ~" M6 D& H* M/ I$ Z1、生成证书:8 Y1 {0 X* g3 r; v0 i* j" Z# _
[es@it-elassearch elasticsearch-8.15.0]$ ./bin/elasticsearch-certutil ca! B* _0 N! z: S# L7 k; k1 P: x
This tool assists you in the generation of X.509 certificates and certificate
7 G* I. D! [5 c4 ~  Rsigning requests for use with SSL/TLS in the Elastic stack.! Y3 X/ W' ~& w0 m6 d" m0 j& V
1 a9 u# f, p1 ]/ j" s  ^$ f4 w& o
' d, I, {9 B! r. o3 t
The 'ca' mode generates a new 'certificate authority'
7 T; H2 J- }( f! z7 ]This will create a new X.509 certificate and private key that can be used8 D. y$ N! j3 _( }) h
to sign certificate when running in 'cert' mode.
$ \" E( i- ]; n& A$ w6 D* O5 i4 ~0 s+ c; I6 n1 s" |
/ Q, a9 X; y7 o0 x2 }; N1 ^
Use the 'ca-dn' option if you wish to configure the 'distinguished name'; i& g6 K7 N. I7 ~, r( Q; }
of the certificate authority1 \8 B7 j" b) w% M7 U* |! V
" F, k( p9 Z, r7 ~) P! q7 \3 K$ o
% }, n2 H6 S, I% O9 }
By default the 'ca' mode produces a single PKCS#12 output file which holds:
* l. k2 w% F" j! {0 n0 A6 C    * The CA certificate' f- ]. J4 q7 P! f" I" W+ f! f
    * The CA's private key
. n4 c' M2 O! h) ^# b3 P
8 D, b8 G2 L( o% a
% K7 |) I" u, g8 d: Y
If you elect to generate PEM format certificates (the -pem option), then the output will3 y2 T  J( Y, ?* B$ }
be a zip file containing individual files for the CA certificate and private key
: ?3 B; |: N  E; j3 J; V
, |" e& R6 ], G  H" T3 }! h

% g, L5 K; p% o/ z: a3 aPlease enter the desired output file [elastic-stack-ca.p12]:    【直接回车】& [+ l6 {; i, |) u* j( |" ]+ l
Enter password for elastic-stack-ca.p12 :    【输入密码】
9 d" t; _0 J& Z7 H
2 O0 Z, I7 i" q" m6 \

. U$ `/ A4 Y% T, y0 @1 Q* @4 Q  x3 u完成后会生成elastic-stack-ca.p12 文件/ [6 k0 x* j/ a4 s$ @$ H
$ Q# |  l+ P) J8 a
  U. |0 s+ W! e' u3 F$ K

4 u. Y- J3 C; `0 N% \/ G& G
( @( R) U2 w' _" f1 Q) N1 B7 o" L
2、生成密匙:& Z( c" H9 k2 [& q8 T( t  k/ |5 F

9 G/ E% B$ p' G! M& c

: V6 [& r" _3 |9 U, D' }: O) x8 P[es@it-elassearch elasticsearch-8.15.0]$ ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
- x/ C4 s. E# f7 m3 w) g+ IThis tool assists you in the generation of X.509 certificates and certificate
( K9 U, T) b) a. Fsigning requests for use with SSL/TLS in the Elastic stack.$ J/ b: T" Z) s* O& w
% X; S8 X$ F& z3 E! G+ _& t) E
The 'cert' mode generates X.509 certificate and private keys.! Y6 F/ I2 Y$ s' }% P4 M0 d7 [6 B
    * By default, this generates a single certificate and key for use
9 |& l9 J  j& [" M, P       on a single instance.' a  I; r: \) G9 ~* I% g/ d$ t) G
    * The '-multiple' option will prompt you to enter details for multiple) L- @$ X/ W! Q: H5 G
       instances and will generate a certificate and key for each one
. u  O% b+ b7 Z7 _- e/ S    * The '-in' option allows for the certificate generation to be automated by describing
4 Q% F, e( M& T) b  \" w4 n       the details of each instance in a YAML file# F+ e+ r# y, w, T6 o' T
& m. w  R" r9 g, a. t
    * An instance is any piece of the Elastic Stack that requires an SSL certificate./ Z9 y" T" D. i5 I3 ~4 P
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats) X1 f7 e/ {6 Y8 l6 L
      may all require a certificate and private key.( l' O, |# I6 b" J
    * The minimum required value for each instance is a name. This can simply be the: q8 f' ^1 `) u5 c- V
      hostname, which will be used as the Common Name of the certificate. A full& E+ a& z( i" Q! N1 w' H6 D
      distinguished name may also be used.
' o' G/ V( E6 Q9 ?. }    * A filename value may be required for each instance. This is necessary when the4 ~6 S0 P2 {5 M) U
      name would result in an invalid file or directory name. The name provided here
) \: g9 u$ ?) I2 m( n      is used as the directory name (within the zip) and the prefix for the key and
% M. j0 z% _+ R      certificate files. The filename is required if you are prompted and the name/ W) j4 z2 e7 _* a; A3 a2 H3 _, N: r. z
      is not displayed in the prompt.( i5 N% K# ]! f5 }: I
    * IP addresses and DNS names are optional. Multiple values can be specified as a1 b- a5 T2 c% B8 L+ j
      comma separated string. If no IP addresses or DNS names are provided, you may
/ _% L. d# y9 M: t      disable hostname verification in your SSL configuration.6 {- @& A  A" F, C" l( L1 r
2 A# R- |; r8 H) X7 w2 H

/ T. L  u6 t" u& B( a- b    * All certificates generated by this tool will be signed by a certificate authority (CA); ?/ F! k$ W1 z4 @  i
      unless the --self-signed command line option is specified.( ]* W  X+ k8 w
      The tool can automatically generate a new CA for you, or you can provide your own with
7 ]; Z) t! V% I( ^) d. k7 ]      the --ca or --ca-cert command line options.$ i" F1 @( I, d, G$ q' V3 C* \
8 f  D2 l$ u' n! M/ d2 y+ k

# ~3 i. ?3 T  p3 Q* }By default the 'cert' mode produces a single PKCS#12 output file which holds:
4 \8 _( S/ J) t" x" w) r! j. K    * The instance certificate
' R6 H0 C! V! ^: k5 @    * The private key for the instance certificate; I6 w) I3 q0 y; Y: u: z0 [
    * The CA certificate2 Y! }" J2 w4 q

( T' t  |, M- PIf you specify any of the following options:  _' ~( o5 W' k/ o8 D
    * -pem (PEM formatted output)
; F3 K: i, Y. g  |. l    * -multiple (generate multiple certificates), S, C+ i5 @, @$ k
    * -in (generate certificates from an input file)4 H9 \# w( p- N; h' j1 f
then the output will be be a zip file containing individual certificate/key files
+ d4 X( N2 D. h2 t4 F( l& q2 }$ l1 A# o7 J
Enter password for CA (elastic-stack-ca.p12) :    【输入密码】
" B% l) R0 v$ C8 J/ CPlease enter the desired output file [elastic-certificates.p12]:     【直接回车】
1 Z, @2 J2 z% x+ \8 ~' HEnter password for elastic-certificates.p12 :  【输入密码】
* i  t  Y& S+ e. V4 p9 s
( B/ q$ [6 R. w5 i; h* WCertificates written to /data/elasticsearch/elastic-cluster1/elasticsearch-8.15.0/elastic-certificates.p12' [# f  D* P0 f. G
% {- G, _% e$ n0 B- ]
This file should be properly secured as it contains the private key for 3 w) T" R0 T1 q( T
your instance.
2 ]/ Z2 L+ ^8 C7 A$ h, OThis file is a self contained file and can be copied and used 'as is'
* F% H/ v0 |" O$ B3 NFor each Elastic product that you wish to configure, you should copy$ S7 H, p; o# x+ y: N5 q# ^
this '.p12' file to the relevant configuration directory2 R9 Z& P2 B+ k( S# Y
and then follow the SSL configuration instructions in the product guide.' n' D7 v4 Z4 r+ l8 |5 b
. A+ Y1 l3 C, v2 P+ A
For client applications, you may only need to copy the CA certificate and: f% S  w) _7 P+ x: S& k" _: T
configure the client to trust this certificate.! k3 f: q1 R5 g- _/ P

9 e1 z! G6 n- R, {# M  h. y* o' x: z" ]3 h
4 ?, \7 b6 G. J- B1 M  J! U
此操作中间需要输入刚才设置的密码就直接输入即可,需要输入路劲的地方可以不输入,直接回车就会生成一个文件在当前目录下:9 ~! z1 y: i0 g; g/ k5 f3 p5 W
elastic-certificates.p12 7 @; P4 d/ H# }8 k' p

# v0 g( C9 v% c# z, p: t2 e

( E! k6 T9 t7 b3、将凭证移至相应的目录即可:; r& l8 Q" G+ U4 d2 q) c. ~& P

' G* j' [- {1 Y2 ^( z- D" Q

0 S  L0 g% r  `$ _/ U, P##将凭证迁移到指定的目录:
7 O6 x4 s/ ?  b9 H  ]9 p创建目录:" m: Y: F2 D( h! v9 V8 O  R
mkdir -p ./config/certificates/. K8 b* M( c. D( H& d: g
移动凭证到指定目录下:8 r+ q& a  \4 t

( D  v2 G  h! r7 ^[es@it-elassearch elasticsearch-8.15.0]$ mv elastic-certificates.p12 elastic-stack-ca.p12 ./config/certificates/
- J0 t2 ?# y; m" a# s& L0 X: i/ x2 u2 ]& T2 w& T
. }3 j0 ?9 R, i7 G: r( e" {8 ?3 k  F
4、复制凭证到每个节点上:(使用scp或者rsync方式即可)
+ F; P' l. _; g( V[es@it-elassearch elasticsearch-8.15.0]$ rsync -azvP -e 'ssh -p 60028' config/certificates/ es@172.24.110.126:/data/elasticsearch/elastic-cluster2/elasticsearch-8.15.0/config/certificates/
% {0 ~+ Q) E& H" k1 z: Kes@172.24.110.126's password:
  B( q% I( s! }0 d& y% j2 wsending incremental file list
( L; h$ `6 w2 D! z./
2 N$ ~" ~# O) @) V! }! @elastic-certificates.p12( s  Q1 v, U# ~0 N9 h- m& T
          3,596 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=1/3)
* ?, ]; C+ W( l+ M8 l# Kelastic-stack-ca.p12
0 P+ M5 D4 h, W  I          2,672 100%    2.55MB/s    0:00:00 (xfr#2, to-chk=0/3)/ g; |; D2 ^$ Z  W) D$ H6 h
9 h. {, c- w2 @. S1 C; |
/ R, {, d4 k7 s7 R1 l) g: `
sent 6,314 bytes  received 57 bytes  1,415.78 bytes/sec
1 Q! M+ V% ^. B& M+ l0 ~- btotal size is 6,268  speedup is 0.98+ Q! f: h9 j  ^% D* B

/ q1 \( H) O7 n$ G. @/ k$ f' Q
; a% i' |: B# T  n- K4 h* w

) J5 K/ e% Z. e% C7 f. }/ a6 }) h0 O5、修改配置文件:! j+ Q) c( H- {1 L4 J
http.cors.enabled: true
, O+ A, z( [- b* l- n) whttp.cors.allow-origin: "*"5 D% G! o' D2 Q  |1 R
http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length! h. p( |: _& c* B; c
xpack.security.enabled: true
4 s" g  |: x0 m. t; {#xpack.security.authc.accept_default_password: true; [5 s# j9 g6 t% w, L: X7 P' m
xpack.security.transport.ssl.enabled: true
  A  n0 x- j8 X/ L  rxpack.security.transport.ssl.verification_mode: certificate
  A! s  h& N9 fxpack.security.transport.ssl.keystore.path: /data/elasticsearch/elastic-cluster/elasticsearch-8.15.0/config/certificates/elastic-certificates.p12
8 }: \6 }3 y4 Z& ^  |+ ]# q7 ]xpack.security.transport.ssl.truststore.path: /data/elasticsearch/elastic-cluster/elasticsearch-8.15.0/config/certificates/elastic-certificates.p12+ S- ?* Y; i5 z
$ _# Q' \  w1 ~; o

  t1 O0 Y$ g9 w1 D! ]加权一样需要切换到es账号:
4 L0 R5 T8 l9 a7 s( h. j& m
4 x4 _$ p8 n/ ^

$ z4 a/ Q7 w1 s+ W在各个节点上添加密码:+ [0 c4 Q$ L5 |% S. ?3 B& n  \

) c/ u" Y) E5 L" O3 q; `; a; N# O

+ ]9 T" ^, S& P- H. R; }; V. T/ Q8 r6 {& c
[es@it-elassearch elasticsearch-8.15.0]$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
" `7 Y( \$ ]6 n) o  z6 O9 j7 g' RThe elasticsearch keystore does not exist. Do you want to create it? [y/N]y( M, c8 \) [, [1 K" i! D+ B& M
Enter value for xpack.security.transport.ssl.keystore.secure_password:
! i$ r& w% A+ \0 w7 }" C
" P/ u( U1 o& |2 `
( ~% d7 S( T5 r- L8 h/ E
输入密码:第一次输入密码上面配置的7 t0 q( Q& s3 U, J% P! K

6 O" v! d7 ^; _4 Q

" L8 k9 `/ D5 _" ?9 ], L1 N[es@it-elassearch elasticsearch-8.15.0]$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
' ]6 y0 ?4 v! F# REnter value for xpack.security.transport.ssl.truststore.secure_password:
/ r* _0 M# J. A: M8 l. W: x5 K8 p7 f
4 a, M% n" J" w% s输入密码: 第二次输入上面的密码:1 O# E/ C7 F: L/ J2 U0 r
3 N  i) F' M9 ]  y
接下来和没有做鉴权的一样,逐个启动集群:6 g* v- K8 H" A
- T- L, w# j( L$ e; q1 H
; K- K: Q/ ~8 ~* C
切换到其它用户,root用户不能启动ES:su es
8 J" u1 X" ?4 `6 f# L2 d7 ?3 R1 ~7 A+ n' T% A2 ?* e7 Z9 F& H

' I' ~. e. I3 b4 Q% p' L[es@it-elassearch elasticsearch-8.15.0]$ bin/elasticsearch -d
- \$ c9 u% F) p3 x.......
4 m* L$ S9 `2 J% H6 WOct 24, 2024 5:33:34 PM sun.util.locale.provider.LocaleProviderAdapter <clinit>+ b; Q& C' C. W2 q
[2024-10-24T17:33:40,246][INFO ][o.e.n.NativeAccess       ] [it-elassearch] Using native vector library; to disable start with -Dorg.elasticsearch.nativeaccess.enableVectorLibrary=false
5 S2 X" W9 u8 x  ?- J. k[2024-10-24T17:33:40,727][INFO ][o.e.n.NativeAccess       ] [it-elassearch] Using [jdk] native provider and native methods for [Linux]
- c7 M  U: Q) r* b/ i[2024-10-24T17:33:41,119][INFO ][o.a.l.i.v.PanamaVectorizationProvider] [it-elassearch] Java vector incubator API enabled; uses preferredBitSize=128; floating-point vectors only; y! a5 X4 C. T) i. B
[2024-10-24T17:33:42,185][INFO ][o.e.n.Node               ] [it-elassearch] version[8.15.0], pid[8520], build[tar/1a77947f34deddb41af25e6f0ddb8e830159c179/2024-08-05T10:05:34.233336849Z], OS[Linux/3.10.0-1160.24.1.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/22.0.1/22.0.1+8-16]
5 |7 K- l8 y+ \8 E.......
) v, s" p: t* Q% [9 x$ {$ V[2024-10-24T17:34:27,594][WARN ][o.e.c.c.ClusterFormationFailureHelper] [it-elassearch] master not discovered yet, this node has not previously joined a bootstrapped cluster, and this node must discover master-eligible nodes [it-elassearch, it-elassearch-2] to bootstrap a cluster: have discovered [{it-elassearch}{1TZ7_AjMQBm4NUw73Dr9eQ}{wrEeokvZTM-NfqrlNd_FSQ}{it-elassearch}{172.24.110.125}{172.24.110.125:9300}{cdfhilmrstw}{8.15.0}{7000099-8512000}]; discovery will continue using [172.24.110.126:9300] from hosts providers and [{it-elassearch}{1TZ7_AjMQBm4NUw73Dr9eQ}{wrEeokvZTM-NfqrlNd_FSQ}{it-elassearch}{172.24.110.125}{172.24.110.125:9300}{cdfhilmrstw}{8.15.0}{7000099-8512000}] from last-known cluster state; node term 0, last-accepted version 0 in term 0; for troubleshooting guidance, see https://www.elastic.co/guide/en/ ... roubleshooting.html) g; V2 D" Z' r5 B1 @
[2024-10-24T17:34:27,609][INFO ][o.e.h.AbstractHttpServerTransport] [it-elassearch] publish_address {172.24.110.125:9200}, bound_addresses {[::]:9200}' z9 K" d9 ^% j+ G0 f
[2024-10-24T17:34:27,637][INFO ][o.e.n.Node               ] [it-elassearch] started {it-elassearch}{1TZ7_AjMQBm4NUw73Dr9eQ}{wrEeokvZTM-NfqrlNd_FSQ}{it-elassearch}{172.24.110.125}{172.24.110.125:9300}{cdfhilmrstw}{8.15.0}{7000099-8512000}{ml.max_jvm_size=4294967296, ml.config_version=12.0.0, xpack.installed=true, transform.config_version=10.0.0, ml.machine_memory=8200949760, ml.allocated_processors=4, ml.allocated_processors_double=4.0}
+ z9 u* k% ?- M  }/ z
6 k4 o8 a+ R  w0 y
3 i! g: d) m/ p+ D

' h4 p9 E* b. s0 y" y! j/ w4 P, u
1 ^1 m6 |: C$ k5 ]

5 @9 U8 e9 h/ p. K$ U% I3 G5 {  T

$ x3 i* H% K- M! C+ A9 @7 N[es@it-elassearch elasticsearch-8.15.0]$ netstat -ntlp5 d" `9 n! l. ]2 Z+ M$ R
(Not all processes could be identified, non-owned process info
( R4 i9 W5 D% t: e6 R( Fwill not be shown, you would have to be root to see it all.)0 K2 ^4 ^0 ]0 G( K+ y6 a' |
Active Internet connections (only servers)
& X* C& P3 {9 e; f3 R+ s6 {# oProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
3 ?5 r" Q+ H% C) T4 @* U: _8 itcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -                  3 j$ K: L" x2 V2 b
tcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      -                    {4 F2 k; F2 Y: n- @
tcp6       0      0 :::9300                 :::*                    LISTEN      8520/java           4 j, d* @$ k$ t! |6 o' d
tcp6       0      0 ::1:25                  :::*                    LISTEN      -                  
0 h" g7 ^/ T8 a! ptcp6       0      0 :::60028                :::*                    LISTEN      -                  
4 X2 [7 m  U, v6 h9 Rtcp6       0      0 :::9200                 :::*                    LISTEN      8520/java           

& x3 E. n# t% x
0 b6 }& s6 M' W' X; e9 |

, r. {+ G, Q9 I% |, Y! D! g0 X* K% g6 }' ~' X

) o4 H. Y) ~4 T5 T* M  k0 p! e) ^! r  @5 D# i
[es@it-elassearch-1 elastic-cluster1]$ ./elasticsearch-8.15.0/bin/elasticsearch-create-enrollment-token -s kibana
+ B: [. s" b4 H, P  e$ V1 }. c, z! @8 _5 X" U7 ?
ERROR: [xpack.security.enrollment.enabled] must be set to `true` to create an enrollment token, with exit code 78
$ r, \4 G7 A9 t2 ~: b0 b3 s; |% S
# L% c1 |/ h+ h) s( f& b/ [+ Y- @" p* Q( m3 O4 z
在elasticsearch-8.15.0/config/elasticsearch.yml 添加 配置:8 O9 {9 Q. {# m
* L( o! W4 f0 H  c9 a, R
[es@it-elassearch-1 elastic-cluster1]$ vim elasticsearch-8.15.0/config/elasticsearch.yml
  q/ o  R7 Q' w; Y
  p1 P0 ?4 s0 E8 ^# gxpack.security.enrollment.enabled: true

9 {/ _+ S7 d9 ^, l3 H3 s8 G9 i( T/ T5 L! w' \% Y/ w0 I* i, \
( f) S. z" m+ v3 ~- i6 Q
保存再次执行:  X4 U1 s3 \  Q- h' A
) r0 w" M' \: @" I/ {8 V* o7 o

. ~$ N0 C' s# C$ v) L; c( g
; L# @5 D. V/ v4 V

0 `  j$ \) ?; M# t0 {2 p# ~: u! h
- x+ V) D% \4 T7 @# M[es@it-elassearch-1 elastic-cluster1]$ ./elasticsearch-8.15.0/bin/elasticsearch-create-enrollment-token -s kibana: K: y2 E; Z1 |+ E
Unable to create enrollment token for scope [kibana]
& ^1 F3 _5 \6 a
8 W, Z- _4 T+ R+ _) QERROR: Unable to create an enrollment token. Elasticsearch node HTTP layer SSL configuration is not configured with a keystore, with exit code 73# R5 Z5 U! k! b7 p* X8 Q
! D* P* z+ @  l2 O: p
如果你的kibana不在同一台主机上就需要加上http或https的访问路径生成,用""扩起来- Q9 {$ o) v: X2 p7 f

6 J! f# k; ~# U! I; h9 ]  }" K% X$ [$ V2 d5 d+ x
6 t: p0 S5 \6 T7 z. k8 m; r: H$ K; T
- m) o6 q% C' F% r" l- x3 v
$ }) d' Z6 C% o' E) f. l
4 e. S# m/ T) |+ Z
 楼主| 发表于 2024-10-31 16:09:57 | 显示全部楼层
登录时提示要求身份验证与此站点的连接不安全:$ n2 ~# A" a) H9 [$ o# E% L) m
3 _  x3 ]9 R) Y9 |2 w4 q: L
设置密码:0 P" y  \5 {8 e9 D, a
[es@it-elassearch elasticsearch-8.15.0]$ ./bin/elasticsearch-setup-passwords interactive
' x' e8 y8 _, }$ r1 D4 ^******************************************************************************) Y) V/ t: B+ F8 d1 f
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This       command will be removed in a future release.$ n. z, J" [0 n
******************************************************************************# U: p6 {$ Y/ Y: @* b8 r! W

2 j! m1 P$ F( B$ ~+ YInitiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
$ k7 y! X. q3 ]. F  U% W7 V/ u2 XYou will be prompted to enter passwords as the process progresses.
' q4 r7 R4 e$ h  o/ X: M; [4 FPlease confirm that you would like to continue [y/N]y% m% s/ V/ B0 i. E' B& k
! g  Z2 f: Z$ K7 g* X% H

2 d" v0 B; ~: }# J1 C) P; LEnter password for [elastic]: , k' S$ m5 {% v; a
Reenter password for [elastic]:
: M# S& f$ }/ h8 t9 JEnter password for [apm_system]: % M% \" L5 e  Q* L# i
Reenter password for [apm_system]:
% q" R+ z+ B2 ^; O* i: m& BEnter password for [kibana_system]: 2 C  W% j7 o3 N, q; X8 D
Reenter password for [kibana_system]:
+ Y# p2 ?+ U+ Y" e5 S; R; t9 q* _Enter password for [logstash_system]:
- x! L" K/ z% \Reenter password for [logstash_system]:
( t* O2 r! j1 K/ q5 D) `. ^. EEnter password for [beats_system]: % @( |% |* @1 ?/ V' E. c
Reenter password for [beats_system]:
$ Q8 u7 B( D2 D$ p1 z8 ZEnter password for [remote_monitoring_user]:
7 s, h5 F1 b7 ?! @. hReenter password for [remote_monitoring_user]: 8 c, y# p6 y6 D" S5 |; o
Changed password for user [apm_system]
5 g, ?* m$ ^* f& M2 Z; N% fChanged password for user [kibana_system]
* k1 c; `/ C/ x$ J2 o- _& H: OChanged password for user [kibana]
" U0 d$ C* r+ D  U/ b7 \' R7 v3 OChanged password for user [logstash_system]
/ q  g! `  V9 k; n8 oChanged password for user [beats_system]( F  z; P3 m! r) j# l& |4 F
Changed password for user [remote_monitoring_user]% ~- q$ t# {% b" {: m; f8 q& a3 ]9 I
Changed password for user [elastic]. u# P( a2 a  h4 v

2 d( @+ o& A* _' P9 d3 q2 W! y密码要记住。9 j% |- i; Q3 ?. Z" `
 楼主| 发表于 2024-10-31 16:12:02 | 显示全部楼层
访问地址:http://172.24.110.125:9200/      输入账号密码即可:
; _" x2 ?8 j4 @6 c2 D5 [; {' L{* b# b% s/ M0 t- }6 H
    "name": "it-elassearch",
: d! C' o2 m, I) n    "cluster_name": "essearch",
, \/ V! f  h6 n% v$ a2 j    "cluster_uuid": "AB2CR6VfTCeR57LVvOGUuw",  e1 R& g% f7 [2 X! f  P. r
    "version": {6 t1 }& R, a$ t
        "number": "8.15.0",4 L4 ]. Y: L: o  J4 z, A; z
        "build_flavor": "default",) a& c+ a) P2 ^2 M1 S" v) S
        "build_type": "tar",  A& b' \$ D9 w3 |
        "build_hash": "1a77947f34deddb41af25e6f0ddb8e830159c179",
; D7 s0 B; `! Y7 d1 e5 R        "build_date": "2024-08-05T10:05:34.233336849Z",
" S4 S- n5 N; r5 n. z, f; a        "build_snapshot": false,' y0 T0 O7 _& f. P& O; O4 M! h$ U
        "lucene_version": "9.11.1",
6 p3 `& z5 s0 e5 f. \$ g  \) E: \        "minimum_wire_compatibility_version": "7.17.0",' v4 |+ N4 T7 e3 E0 T
        "minimum_index_compatibility_version": "7.0.0", V4 Y+ H& z. u* f" x% B7 _( c
    },
6 R+ S; f4 [2 I* A    "tagline": "You Know, for Search"
& p8 _1 z, B! X4 H. K}
 楼主| 发表于 2024-12-2 15:50:06 | 显示全部楼层
3)更改 elasticsearch 主配置文件
' h; f' `# u; r8 X6 P/ L[root@elk-node1 ~]# grep -v "^#" /etc/elasticsearch/elasticsearch.yml3 C1 e; W3 W5 K' Q' k/ |/ F
cluster.name: my-elk-cluster 集群名字
3 R+ A% J2 q/ a5 v+ }8 S" rnode.name: elk-node1 节点名字
* Q, O, B/ b& K% ^$ S- Z9 @& H1 ~& e8 kpath.data: /data/elk_data 数据存放路径
$ v$ z8 Q& y8 ^7 O+ Spath.logs: /var/log/elasticsearch/ 日志存放路径. E( W- U3 G+ W- y, _- A9 |
bootstrap.memory_lock: false 不在启动的时候锁定内存
  o4 k6 C3 v" v& hnetwork.host: 0.0.0.0 提供服务绑定的 IP 地址,0.0.0.0 代表所有地址/ V( [9 f# B% o7 N
http.port: 9200 侦听端口为 9200- A5 [: ~9 L5 R* f2 K. s. Z1 x
discovery.zen.ping.unicast.hosts: ["elk-node1", "elk-node2"] 集群发现通过单播实现! j* H& h  ]( D% Y
[root@elk-node2 elasticsearch]# grep -v "^#" /etc/elasticsearch/elasticsearch.yml
: J: G1 |$ J; ~: C/ H- ucluster.name: my-elk-cluster
3 I0 [; ]- N, onode.name: elk-node28 a- ]5 _: z+ Y! o. K/ G/ }2 `, {
path.data: /data/elk_data
9 U% `% [: f5 ?path.logs: /var/log/elasticsearch/
1 |$ m9 L6 M: ^' R4 Pbootstrap.memory_lock: false
5 g5 a9 u" Y. n  N8 B, W6 C2 bnetwork.host: 0.0.0.04 V  q7 g  W1 M1 f5 m
http.port: 9200: |" W, K3 C0 a4 {2 Y
discovery.zen.ping.unicast.hosts: ["elk-node1", "elk-node2"]; i, o: X0 c0 X1 M- j) l  V! i# v2 w
 楼主| 发表于 2024-12-3 09:30:45 | 显示全部楼层
http://172.24.110.125:9200/_cluster/health?pretty
6 X' E5 a3 ~& _{* V6 x# j3 K3 q
    "cluster_name": "elasticsearch",
) t! W5 |1 ~0 M) }+ m    "status": "green",
* y2 H' I0 h6 e8 w    "timed_out": false,- a! B% T% S% h7 s4 |* W
    "number_of_nodes": 2," ^( @: P; j1 {
    "number_of_data_nodes": 2,
1 q6 \3 b' O2 W( V, e    "active_primary_shards": 107,5 u6 p. s3 v* d
    "active_shards": 214,3 `5 a+ i1 d* O) W6 {8 \! ?7 L
    "relocating_shards": 0,
+ D/ c1 }) N( b    "initializing_shards": 0,  h' Q- `! c, _' f8 |( o! t
    "unassigned_shards": 0,
+ s; I: w3 m( U3 F5 I    "delayed_unassigned_shards": 0,
# p! K8 i( i$ x  f  ?% {) i( A    "number_of_pending_tasks": 0,0 s1 y( q. B7 u! ?* x
    "number_of_in_flight_fetch": 0,- F! f# O+ m. z# M; b0 \3 s& ^
    "task_max_waiting_in_queue_millis": 0,
* A8 P3 W2 l. c3 q3 r, h8 a    "active_shards_percent_as_number": 100' d$ g+ j$ c7 ?& Q" v% M" \- k
}  x5 [  P' i6 \
 楼主| 发表于 2024-12-3 09:36:37 | 显示全部楼层
编写 logstash 配置文件 apache_log.conf 搜集 apache 日志并执行
% y' X7 b: i1 A+ J. h- d
5 F1 s8 a1 c" {7 U+ ]  ]: ^[root@apache conf.d]# cat apache_log.conf0 a& Q* m7 N! c1 C. |8 B  c4 T
input {' E! S# U% |7 j5 W: \* r$ H. J4 J
file {+ ?% V# O) }+ J9 n' p
path => "/etc/httpd/logs/access_log"9 w+ L$ m  V  ~8 }- X
type => "access"9 M# n  N! R1 J8 n8 W& K3 r" o% R; a
start_position => "beginning"+ G% k- }$ W/ K- t
}9 _2 o7 r0 C3 S
file {2 h& ]" l, ]5 A, ^4 h- }* D
path => "/etc/httpd/logs/error_log"
2 H) p5 _  u; p6 M9 dtype => "error"
! R- ]- Z* v8 w8 E; [! Fstart_position => "beginning"
- B- y* B/ Z$ b1 e0 Y2 J}
& W  ]5 Q0 k/ k, K: t5 s}
3 C6 `  X, q1 k2 ]output {
7 L) @% z1 A, Bif [type] == "access" {
6 B+ R* k9 W6 G; h* Felasticsearch {) g& L; @; d; H# i2 ?% u
hosts => ["192.168.10.181:9200"]8 G& z7 T8 F, }$ `! V
index => "apache_access-%{+YYYY.MM.dd}"1 H& \9 r; L7 w1 `
}
& i, r9 n  n/ p3 R  a4 L}
; i0 D. @7 E( N) ]0 b, `7 a# gif [type] == "error" {
9 g" M3 @3 V. U7 s: x6 Q( E7 V! Selasticsearch {
$ F- Y3 t, c! @+ y) Z0 {1 nhosts => ["192.168.10.181:9200"]
: v7 e' N8 D4 A5 V1 cindex => "apache_error-%{+YYYY.MM.dd}"
3 }. @3 B8 i: R}
7 L) m5 M# {1 y# c0 T$ M4 y% k7 j: k}" q% [3 S' }8 \
}: p5 p' z2 L1 w5 |
4 @6 M9 p+ B: m! N, g+ a" X; O
[root@apache ]# /usr/share/logstash/bin/logstash -f apache_log.conf$ B4 Q3 N( C% [6 W

' G! z; v# o( p- V) F
 楼主| 发表于 2024-12-5 14:19:46 | 显示全部楼层
安装 logstash 并做一些日志搜集输出到 elasticsearch 中
" J1 P# V/ |; d1 V# I2 z9 ?1)在 elk-node1 上安装
4 R2 q5 b7 O: q[root@elk-node1 ~]# rpm -ivh logstash-5.5.1.rpm
0 w- m& y$ `/ \2 z3 c警告:logstash-5.5.1.rpm: 头 V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY
! d7 i9 U" ?0 \( u9 w3 O4 }准备中... ################################# [100%]
2 [' n  ~4 y& }: C4 Y正在升级/安装...
5 G" d6 T2 q/ l- ^: b1:logstash-1:5.5.1-1 ################################# [100%]/ q7 a  K) H; Z# i; H7 j
Using provided startup.options file: /etc/logstash/startup.options$ r& M8 g/ Q* b# S- o
Successfully created system startup script for Logstash' v; Y# p5 g# K
[root@elk-node1 ~]# systemctl start logstash.service( k8 D# K. Q# ]: W
[root@elk-node1 ~]# ln -s /usr/share/logstash/bin/logstash /usr/local/bin/
5 [$ ^1 O6 i; h" f1 @7 H; B! A2)logstash 基本使用
! P5 C0 R4 E( ]9 q5 xLogstash 使用管道方式进行日志的搜集处理和输出。有点类似 linux 系统的管道命令 xxx | ccc
% A! F0 s  O+ S1 b* r+ G| ddd,xxx 执行完了会执行 ccc,然后执行 ddd。# l2 p& b/ |  I, _
在 logstash 中,包括了三个阶段:. m# Q1 o" W& y9 R
输入 input --> 处理 filter(不是必须的) --> 输出 output
1 V# H# Y1 g* `1 \9 d0 h; N7 X  y. a( `. R9 [" k3 x+ z
每个阶段都由很多的插件配合工作,比如 file、elasticsearch、redis 等等。/ h2 F. M" ~1 c  R' G% j9 |
每个阶段也可以指定多种方式,比如输出既可以输出到 elasticsearch 中,也可以指定到 stdout4 o! i; W  N/ y) n* w* y) E
在控制台打印。
  R& O. a% x! a! A& W由于这种插件式的组织方式,使得 logstash 变得易于扩展和定制。, W9 q$ m: p' q1 [
logstash 命令行中常用的命令:0 E9 K+ X: Y5 l9 N4 u# d- K
-f:通过这个命令可以指定 Logstash 的配置文件,根据配置文件配置 logstash
- ]) b' H5 F0 a' y, ?9 Q-e:后面跟着字符串,该字符串可以被当做 logstash 的配置(如果是“” 则默认使用 stdin
& u, U/ L3 r% F作为输入,stdout 作为输出)
- p8 t. f- v- i-t:测试配置文件是否正确,然后退出) q. ]/ P  r1 N$ e
启动一个 logstash,-e:在命令行执行;input 输入,stdin 标准输入,是一个插件;output 输) E' w. `+ R/ k- Z; {! H2 m' U# |
出,stdout:标准输出
, Z: s# K% N9 _* A) Z  ]3 m[root@elk-node1 ~]# logstash -e 'input { stdin{} } output { stdout{} }'
3 L  y+ q4 E( }, l, g# O* x& a22:50:19.889 [Api Webserver] INFO logstash.agent - Successfully started Logstash API
0 \9 ~' W! `; i, y; h/ iendpoint {:port=>9600}
% w' L  ]8 G2 E4 \; E1 }www.baidu.com 输入
% m' C1 c! A9 L0 q& H" v4 f- \8 J* T2017-08-09T14:51:26.277Z elk-node1 www.baidu.com 输出1 M5 r: J2 B; L+ |
www.sina.com.cn 输入" B! f2 v- q8 b- G
2017-08-09T14:51:30.971Z elk-node1 www.sina.com.cn 输出
3 d' _" x! Q6 o5 V2 K使用 rubydebug 显示详细输出,codec 为一种编解码器% n" i2 e; m0 q! q( I
[root@elk-node1 ~]# logstash -e 'input { stdin{} } output { stdout{ codec
5 W  j0 p. b" d; f1 N=>rubydebug} }'
3 f: x5 i: l" K: O: D# C22:54:23.075 [Api Webserver] INFO logstash.agent - Successfully started Logstash API
  m) b1 K2 A. k; g& Mendpoint {:port=>9600}' F) b# F* v: L
www.baidu.com 输入
0 w6 o3 x: T) n{) r( R( J1 e, b7 @# o
"@timestamp" => 2017-08-09T14:54:31.236Z,2 h; E: s, U7 f6 H
"@version" => "1",$ n, S  L% L2 L: E! f, I
"host" => "elk-node1",
8 C  w' D1 i: ?; J"message" => "www.baidu.com"
5 Y) r! q' Z8 y8 G- C6 u4 b/ V}* [: B/ [8 S2 R2 \  k4 o3 ~' n
www.sina.com.cn 输入
( y6 @9 S+ n- O+ c" j{- Z- X* ]+ G* R& |& Y! A
"@timestamp" => 2017-08-09T14:54:39.412Z,% Z# K: J, T4 N' t6 s* Q" d
"@version" => "1",& g  }7 F$ R. Q. u6 c
"host" => "elk-node1",# S0 N2 C( D' c3 D% o7 @% ]
"message" => "www.sina.com.cn"
' b- n/ G0 [* h9 l4 o, ~}9 s: R& k2 ?# A/ p. F6 {
使用 logstash 将信息写入到 elasticsearch 中
7 Q; O6 K/ f& e. O[root@elk-node1 ~]# logstash -e 'input { stdin{} } output { elasticsearch { hosts=>, e- T1 n9 W5 V
["192.168.10.181:9200"]} }'( k: o% A$ t0 Y& }2 n, i
22:59:03.834 [Api Webserver] INFO logstash.agent - Successfully started Logstash API
3 v" S& U7 t' B; P( x- ]endpoint {:port=>9600}9 b4 h3 k" k0 l/ u
www.baidu.com3 P4 f$ J; ^& A1 d# n" I9 k! [6 g
www.sina.com.cn
) ^0 L$ g% n$ nwww.google.com# k. r* }* e& _& ?# O, U5 U: ^
在 elasticsearch 中查看 logstash 新加的索引" w2 p5 X( O9 t& r
4 N  M: D0 f& g. x1 u

! l& l' L& `$ M2 S8 [3)logstash 配置文件使用- Z  ?; _; R; x3 q4 W6 L7 c. S
logstash 配置文件基本上由三部分组成,input、output 以及用户需要才添加的 filter,  B% _4 v: e9 Q6 s3 W
因此标准的配置文件格式如下:& E1 L1 {2 p. y. ]% b8 z- u
input {...}( ^# v" R0 o: W9 R+ Y% A, y0 {
filter {...}+ M# O$ L9 P: K" Y4 U2 {  T9 i
output {...}4 Y* j0 g+ {0 P  b! w  r0 s
在每个部分中,也可以指定多个访问方式,例如我想要指定两个日志来源文件,则可以这样写:# G1 S0 T% r, j9 g1 |  L2 h# P7 [
input {
9 v4 d- z" b9 K' w2 W  i' K. {9 Kfile { path =>"/var/log/messages" type =>"syslog"}
/ f" }' [0 I/ H' Q+ u& Wfile { path =>"/var/log/apache/access.log" type =>"apache"}
7 B- y, a' b  e# Y8 e}
, ~# L: D" ^  c* K5 b下面是一个收集系统日志的配置文件例子,将其放到/etc/logstash/conf.d/目录中,; j, Z+ O7 P* h6 ]
logstash 启动的时候便会加载。注意要给 logstash 读取日志文件的权限。+ s- d2 D8 D: P' x
[root@elk-node1 logstash]# chmod o+r /var/log/messages
' _% r% Y4 O+ v! W4 Z0 D[root@elk-node1 logstash]# ll /var/log/messages
/ {* _! m) Q8 ~& G-rw----r--. 1 root root 2566754 8 月 9 23:25 /var/log/messages" Z2 c% `# }$ F% }. W+ k
[root@elk-node1 ~]# cd /etc/logstash/conf.d/
* u+ j) c  L* d% L. I1 @[root@elk-node1 conf.d]# cat system.conf
) g. \1 i1 n) Q+ [# dinput {) ^- u9 V/ q- k: Q' l% N  b# r
file { 从文件中读取2 O. `" w$ M8 k# b
path => "/var/log/messages" 文件路径7 f+ R' h, Q8 b
type => "system"5 E) Z/ S  l8 x8 \7 q
start_position => "beginning" 是否从头开始读取
8 U( v8 O4 n$ @+ N+ h4 ^$ e}% @9 J( @. m' P4 R) w
}
- P( n( H; m- j; L" uoutput {
# ~$ E0 V! A9 A& G& s) M. Y( d: Melasticsearch { 输出到 elasticsearch 中3 ^: Z3 e( J, g  ?
hosts => ["192.168.10.181:9200"] elasticsearch 主机地址和端口  }  P( \# a8 L
index => "system-%{+YYYY.MM.dd}" 索引名称5 ?0 a6 r3 O' R3 {- w8 O2 j4 T
}: N' u8 r; x! m
}
% l* p, s. K* S5 s4 F- W  P. P& ~重启 logstash 服务
/ R( f/ {: d2 a! F) O[root@elk-node1 logstash]# systemctl restart logstash- @/ E8 P9 v4 F
在浏览器中即可看到新加索引及其内容# w1 {7 Q9 Z3 f' F& Q
* y# g( E# _" F. _+ N
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 20:23 , Processed in 0.066975 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表