前言:正常的国外论坛程序都需要安装Elasticsearch才能支持中文搜索,直接在Linux中安装比较快些,以下方IPS为例,XenForo也可以按照这样安装,讲解了非常详细的步骤,有什么不懂的可以在下方评论。
当你安装 LNMP一键安装包 或 宝塔面板,配置Nginx、MySQL/MariaDB、PHP之后
就来安装Elasticsearch
------------------------------------------------------------
安装 Java Runtime 1.8
------------------------------------------------------------
命令
yum -y install java-1.8.0
命令
yum -y install java-1.8.0-openjdk-devel
------------------------------------------------------------
安装 Elasticsearch
------------------------------------------------------------
下载 rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-x86_64.rpm
安装 rpm
sudo rpm --install elasticsearch-7.6.2-x86_64.rpm
命令
sudo systemctl daemon-reload
命令
sudo systemctl enable elasticsearch.service
修改文件
vi /etc/elasticsearch/elasticsearch.yml
#network.host: 192.168.0.1
修改为
network.host: 127.0.0.1
# http.port: 9200
修改为
http.port: 9200
保存并离开
:wq
修改文件
vi /etc/elasticsearch/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
会看到这两个,默认内存 1GB
-Xms1g
-Xmx1g
修改为 (可调低)
-Xms256m
-Xmx256m
保存并离开
:wq
启动命令
sudo systemctl start elasticsearch.service
状态命令
service elasticsearch status
需要运行
Active: active (running)
测试Elasticsearch是否成功运行
curl http://127.0.0.1:9200
成功的话,会有讯息,例如 You Know, for Search
Elasticsearch的中文搜索,此处只是本地 localhost 使用
所以Elasticsearch使用的 9200 Port 不要外连
你最好再确保
大厂的WAF防火墙,若你开启 9200 Port,那就关闭
你云主机Linux的防火墙,若你开启 9200 Port,那就关闭
若你安装的elasticsearch版本太旧或太新,就要卸载,重新安装IPS论坛支持的elasticsearch版本
-------------------------------------------------------------
卸载Elasticsearch命令
-------------------------------------------------------------
这个卸载方法,限rpm安装的elasticsearch
查询命令
rpm -qa | grep elasticsearch
得知你安装 elasticsearch-7.10.2-1.x86_64
因为用rpm安装的elasticsearch,所以卸载也用rpm命令
rpm --erase elasticsearch-7.10.2-1.x86_64
删除目录,有文件要删掉
rm -f -r /etc/elasticsearch
删除目录,有文件要删掉
rm -f -r /var/lib/elasticsearch
重启
sudo reboot
回到上面的教程 安装Elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch/某版本.rpm
重新安装IPS论坛支持的elasticsearch版本
Elasticsearch设置完成,才能搜索中文
你的Linux服务器先安装Elasticsearch
Elasticsearch必须至少运行6.0.0版本,但小于7.7.0版本
IPS论坛后台 -> 系统 -> 搜索
照着以下设置,默认值就好,不用改太多
搜索引擎 -> Elasticsearch (高级)
Elasticsearch 伺服器 -> http://localhost:9200
Elasticsearch 索引名称 -> content
分析器 -> 中文/日文/韩文
其余默认值就好,不用改太多
-> 保存
重建搜索索引
首次安装Elasticsearch,并在论坛后台配置完成后,你需要重建搜索索引
之后,若你有一些大动作,例如:大量删除帖子、大量删除会员帐户,也需要重建Elasticsearch索引
论坛后台 -> 系统 -> 搜索 -> 右上方的 [重建搜索索引]
按下 [确定] -> 等待 [正在重建搜索索引] 消息不显示后
就到 [仪表板] -> 按下 [手动运行]
按下 [现在运行] -> 然后等待,直到它运行完毕
来源:PHP论坛人,可以百度搜索一下,也是IPS专业交流的论坛。