Elasticsearch单机安装

一、需求

本地测试服务器,安装elasticsearch,用于开发使用。

二、准备

elasticsearch不允许root帐号运行。

  1. 创建用户和组
    1
    2
    groupadd cloud(创建组)
    useradd elastic -g cloud(新建用户,并指定组)
  2. 确定版本,并下载,解压
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <!-- 依赖的elasticsearch-client是5.6.10版本,所以我们选择5.6.10版本下载。-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    <version>2.0.3.RELEASE</version>
    </dependency>
    <!-- 切换帐号,下载对应版本软件,并解压 -->
    su - elastic
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.10.tar.gz
    <!-- 华为镜像包括所有版本,下载提速 -->
    https://mirrors.huaweicloud.com/elasticsearch/
    tar zxvf elasticsearch-5.6.10.tar.gz

三、配置

  1. 备份并修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
cd ${ELASTIC_HOME}/config
cp elasticsearch.yml elasticsearch.yml.backup
path.data: /home/elastic/data
path.logs: /home/elastic/logs

<!-- 编辑elasticsearch.yml,增加如下配置 -->
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
<!-- 设置允许跨域后,elasticsearch-head可视化插件方可访问该服务9200端口 -->
http.cors.enabled: true
http.cors.allow-origin: "*"
  1. 修改系统配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!-- 切换到root帐号 -->
su -root

<!-- 编辑/etc/sysctl.conf -->
fs.file-max = 1048576
vm.max_map_count=262144

<!-- 配置即刻生效 -->
sysctl -p

<!-- 编辑/etc/security/limits.conf -->
* soft nofile 655360
* hard nofile 655360

<!-- 退出后重新登录,配置生效 -->

四、启动并验证服务

  1. 启动应用
1
2
3
4
5
<!-- 切换到elastic帐号 -->
su - elastic

<!-- 以deamon模式启动elasticsearch服务 -->
${ELASTIC_HOME}/bin/elasticsearch -d
  1. 验证服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!-- 命令行 -->
$ curl localhost:9200
{
"name" : "TRsj0Ay",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "fJMBgczlRXKY-szPWYRlGg",
"version" : {
"number" : "5.6.10",
"build_hash" : "b727a60",
"build_date" : "2018-06-06T15:48:34.860Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}

五、可视化插件

1
2
3
4
5
6
7
8
9
10
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install
cnpm run start
open http://localhost:9100/

或者

安装Chrome插件elasticsearch-head

发布jar包到Maven中央仓库

动手之前,先通读全文,因为前后有些信息会相互关联。有不清楚的,欢迎咨询博主。

一、注册并登录sonatype

https://issues.sonatype.org/secure/Dashboard.jspa

记住帐号和密码

二、项目配置

2.1 配置pom.xml

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<project...>
<scm>
<connection>scm:git:https://gitee.com/bxl/simple-tiny-program.git</connection>
<url>http://www.adouteam.com/simple-tiny-program.html</url>
</scm>
<developers>
<developer>
<name>buxianglong</name>
<email>buxianglongoschina@gmail.com</email>
</developer>
</developers>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>

三、 首次发布

3.1 提交申请issue

还是在Sonatype:https://issues.sonatype.org/secure/Dashboard.jspa

可以参考我的提交:https://issues.sonatype.org/browse/OSSRH-42535

由于时差问题,需要耐心等待。

3.2 认证

groupId为 com.github 的,比较容易认证,只要scm信息和groupId一致即可,不需要额外操作。

如果是使用自己的域名,最简单的认证方式是通过域名邮箱发送邮件给central@sonatype.com。更多说明:https://central.sonatype.org/pages/choosing-your-coordinates.html

四、发布升级版本

4.1 ~/.m2/setting.xml 增加server配置:

1
2
3
4
5
6
7
8
9
<settings>
<servers>
<server>
<id>oss</id>
<username>{{sonatype_email}}</username>
<password>{{sonatype_password}}</password>
</server>
</servers>
</settings>

4.2 安装gpg签名工具

mac系统

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装gpg
brew install gpg
# 查看工具版本
gpg2 --version
# 生成签名,设置用户名{{gpg_name}}、邮箱{{gpg_email}}、记住这里的密码{{gpg_password}}
gpg2 --gen-key
# 列出所有签名
gpg2 --list-keys
-------------------------------------
pub rsa2048 2019-01-11 [SC] [expires: 2021-01-10]
F72902B6CB632C4721EBB38FBDE0876BCF3C0D45
uid [ultimate] buxianglong <buxianglongoschina@gmail.com>
sub rsa2048 2019-01-11 [E] [expires: 2021-01-10]

或者 https://sourceforge.net/p/gpgosx/docu/Download/ 下载安装GnuPG for OSX

4.3 将签名公钥发布到PGP密钥服务器

服务器可以这里找:https://sks-keyservers.net/status/

可以命令提交,也可以进入对应网站服务页面提交

1
2
3
4
5
6
7
8
# 发布到PGP密钥服务器
gpg2 --keyserver pgp.net.nz --send-keys F72902B6CB632C4721EBB38FBDE0876BCF3C0D45
# 验证是否发布成功
gpg2 --keyserver pgp.net.nz --recv-keys F72902B6CB632C4721EBB38FBDE0876BCF3C0D45

gpg: key BDE0876BCF3C0D45: "buxianglong <buxianglongoschina@gmail.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1

五、发布到中央仓库

1
mvn clean deploy -P release

登录:https://oss.sonatype.org/#stagingRepositories

进入左侧菜单“Staging Repositories”,找到对应的“Repository”,先Close,然后 Release.

等 Description 变成 ok 后,10分钟左右,即可在中央仓库https://oss.sonatype.org/#welcome 搜索到jar包。

https://search.maven.org 可能需要2小时后,才能够搜索到。

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×