安装elasticsearch配合ElasticPress插件为WordPress提速

1,006次阅读
没有评论

1.首先,踩个坑是到2022年10月9日,ElasticPress最高只能使用7.10版本的elasticsearch,而官方已经到了8.6.3

2.然后elasticsearch不能用root安装,这里面权限很蛋疼。

接下来就是具体实战步骤了:

第一步:

cd 到/usr/local 这个目录下,然后mkdir es

第二步:

cd /user/local/es 然后按官方的教程执行

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-7.9.3-linux-x86_64.tar.gz.sha512
tar -xzf elasticsearch-7.9.3-linux-x86_64.tar.gz

第三步,创建用户组及用户
# 创建es分组
groupadd es
# 为es分组添加用户es,密码为es123456
useradd es -g es -p es123456

第四步,授权文件夹
chown -R es:es /usr/local/es/elasticsearch-7.9.3

第五步,配置elasticsearch.yml(在安装包config目录下)

vi /usr/local/es/elasticsearch-7.9.3/config/elasticsearch.yml

# 底部追加
network.host: 0.0.0.0
http.port: 9200

# 如果是centos6,需要继续追加
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

第六步,切换用户

su es

第七步,启用es

cd /usr/local/es/elasticsearch-7.9.3/bin
./elasticsearch

第八步,设置开机启动

切换root用户

su root

创建自启动脚本

vi /etc/init.d/elastisearch

# 添加如下内容

#jdk相关路径
export JAVA_HOME=/home/software/jdk1.8.0_301
export PATH=$PATH:$JAVA_HOME/bin

case "$1" in
start)
    #es的启动账号名
    su es<<!
    #es的安装路径
    cd /usr/local/es/elasticsearch-7.9.3/
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
stop)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    ;;
restart)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    su es<<!
    cd /usr/local/es/elasticsearch-7.9.3/bin
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
*)
    echo "start|stop|restart"
    ;;
esac

exit $?

给脚本权限,并配置开机自启动

chmod +x /etc/init.d/elastisearch
chkconfig --add /etc/init.d/elastisearch
重启机器验证:
reboot

第九步,检查运行情况

访问ip:9200出现如下页面显示成功

{
"name" : "Fy10rag",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "hE6CL8LUTV6XJBxeqU9y8w",
"version" : {
"number" : "6.4.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "fe40335",
"build_date" : "2018-10-30T23:17:19.084789Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}

注:

启动报错处理:

vi /etc/sysctl.conf

文件最后添加

vm.max_map_count=262144

添加完成后运行如下命令

sysctl -p

修改/etc/security/limits.conf

vi /etc/security/limits.conf

添加如下内容

* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096

修改/etc/security/limits.d/90-nproc.conf

vi /etc/security/limits.d/90-nproc.conf

修改如下内容:

  • soft nproc 1024

修改为

  • soft nproc 4096

没有https,所以要

修改elasticsearch.yml配置文件

xpack.security.enabled设置为false

小内存机器,需要修改配置文件

找到elasticsearch的安装目录,然后找到config文件夹,里面都是相关的配置文件。

其中,jvm.options可以修改es运行时候的内存分配。打开jvm.options文件,我们可以发现默认设置的内存是4g。

在最后加

-Xms1g

-Xmx1g

保存即可

 
吾爱互联
版权声明:本站原创文章,由 吾爱互联 2022-10-09发表,共计2590字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
载入中...