一,安装java11
安装就不说了,就直接说配置环境变量吧
java版本 OpenJDK11U-jdk_x64_linux_hotspot_11.0.8_10.tar.gz,自己网上搜索,然后解压
vi /etc/profile
export JAVA_HOME=/www/server/java
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
/www/server/java是你的解压安装目录
source /etc/profile java配置完成! java -version查看版本
下载地址:https://www.elastic.co/cn/downloads/elasticsearch
熟悉下es目录结构
bin 启动文件
config 配置文件
log4j2 日志配置文件
jvm.options java 虚拟机相关的配置
elasticsearch.yml elasticsearch 的配置文件! 默认 9200 端口! 跨域!
lib 相关jar包
logs 日志!
modules 功能模块
plugins 插件!
接下来就是配置啦。。。。
linux下安装
- 解压elasticsearch-7.6.1-linux-x86_64.tar.gz到/www/server/目录:
tar -xvf elasticsearch-7.6.1-linux-x86_64.tar.gz
- 进入解压后的elasticsearch目录:
(2)新建data
mkdir data
(2)修改config/elasticsearch.yml:
vi config/elasticsearch.yml
取消或者修改下列项注释并修改:
cluster.name: my-application #集群名称
node.name: node-1 #节点名称
#数据和日志的存储目录
path.data: /www/server/es/data
path.logs: /www/server/es/logs
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
network.host: 0.0.0.0
http.port: 9200 #端口
#设置在集群中的所有节点名称,这个节点名称就是之前所修改的,当然你也可以采用默认的也行,目前是单机,放入一个节点即可
cluster.initial_master_nodes: ["node-1"]
修改完毕后,:wq 保存退出vi
- 准备启动es
进入/bin目录执行命令:
./elasticsearch
这里出现如下错误:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid22863.log
[root@localhost es]#
elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到256m cd 到es目录修改 ./config/jvm.options:
vi ./config/jvm.options
修改该内容:根据自己的机器情况而定
-Xms256m
-Xmx256m
:wq 保存并退出vi,再次启动es
再次启动出现如下错误:
[2019-06-21T16:20:03,039][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.1.jar:7.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.6.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.6.1.jar:7.1.1]
... 6 more
[root@localhost es]#
这是不能使用root用户操作,添加一个其他的用户再试试:
[root@localhost es]# useradd es
[root@localhost es]# passwd es
更改用户 es 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost es]# chown -R es /www/server/es
vi 编辑 /etc/security/limits.conf,在末尾加上:
es soft nofile 65536
es hard nofile 65536
es soft nproc 4096
es hard nproc 4096
vi 编辑 vi /etc/security/limits.d/20-nproc.conf,将* 改为用户名(elasticsearch):
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
es soft nproc 4096
root soft nproc unlimited
vi 编辑 /etc/sysctl.conf,在末尾加上:
vm.max_map_count = 655360
在root用户下执行:
[root@localhost ~]# sysctl -p
vm.max_map_count = 655360
[root@localhost ~]#
登录刚才新建的elasticsearch用户,并启动elasticsearch,OK
[root@localhost es]# su es
[es@localhost es]$ ./bin/elasticsearch
es启动成功!!!!!!!!!!!!!!!!!
接下来就是安装es-head插件
切换到cd /www/server
安装elasticsearch-head
- 安装node.js
wget https://nodejs.org/dist/v12.18.1/node-v12.18.1-linux-x64.tar.xz // 下载
tar xf node-v12.18.1-linux-x64.tar.xz // 解压
cd node-v12.18.1-linux-x64 // 进入解压目录
解压文件的 bin 目录底下包含了 node、npm 等命令,我们可以修改linux系统的环境变量(profile)来设置直接运行命令:
export PATH=$PATH:/www/server/node-v12.18.1-linux-x64/bin
source /etc/profile
- elasticsearch-head
1. 在/usr/local目录解压elasticsearch-head-master.zip
unzip elasticsearch-head-master.zip
2. 修改elasticsearch-head-master目录
mv elasticsearch-head-master elasticsearch-head
3. 在elasticsearch-head目录下安装npm
npm install //安装后面可能会出现异常,但是不会影响操作
4. 启动elasticsearch-head
npm run start
成功后会出现跨域问题,在elasticsearch.yml配置文件中配置跨域:
http.cors.enabled: true # elasticsearch中启用CORS
http.cors.allow-origin: "*" # 允许访问的IP地址段,* 为所有IP都可以访问
kibana安装
1. 在/www/server/解压kibana-7.6.1-linux-x86_64.tar.gz
tar -xvf kibana-7.6.1-linux-x86_64.tar.gz
2. 进入./kibana/bin目录启动
./kibana
Kibana should not be run as root. Use --allow-root to continue.
不能在root用户下启动
3. 创建kibana用户
useradd kibana
passwd kibana
chown -R kibana /www/server/kibana
进入kibana用户启动kibana访问,OK:
碰到故障不要慌,百度一下就行了
kibana-Request Timeout after 30000ms故障解决
接下来的文章就是来用php+es解决搜索数据。。。。静待等候。..