BurningBright

  • Home

  • Tags

  • Categories

  • Archives

  • Search

Elasticsearch cluster status

Posted on 2017-03-21 | Edited on 2020-09-17 | In search

Terminology

An Elasticsearch cluster is made up of one or more nodes.
Each of these nodes contains indexes which are split into multiple shards.
Elasticsearch makes copies of these shards called replicas.
These (primary) shards and replicas are then placed on various nodes throughout the cluster.

Status

Cluster Health API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
curl -XGET http://192.168.3.11:9200/_cluster/health

{
"cluster_name" : "testcluster",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 5,
"active_shards" : 5,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 5,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 50.0
}
  • RED:
    Damnit. Some or all of (primary) shards are not ready.

  • YELLOW:
    Elasticsearch has allocated all of the primary shards, but some/all of the replicas have not been allocated.

  • GREEN:
    Great. Your cluster is fully operational. Elasticsearch is able to allocate all shards and replicas to machines within the cluster.

Request Parameters

  • level
    Can be one of cluster, indices or shards. Controls the details level of the health information returned. Defaults to cluster.
  • wait_for_status
    One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided or better, i.e. green > yellow > red. By default, will not wait for any status.
  • wait_for_no_relocating_shards
    A boolean value which controls whether to wait (until the timeout provided) for the cluster to have no shard relocations. Defaults to false, which means it will not wait for relocating shards.
  • wait_for_active_shards
    A number controlling to how many active shards to wait for, all to wait for all shards in the cluster to be active, or 0 to not wait. Defaults to 0.
  • wait_for_nodes
    The request waits until the specified number N of nodes is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible to use ge(N), le(N), gt(N) and lt(N) notation.
  • timeout
    A time based parameter controlling how long to wait if one of the wait_for_XXX are provided. Defaults to 30s.
  • local
    If true returns the local node information and does not provide the state from master node. Default: false.
1
curl -XGET http://192.168.3.11:9200/_cluster/health?wait_for_status=yellow&timeout=50s

Elasticsearch demo

Posted on 2017-03-20 | Edited on 2020-09-17 | In search

Create a new index

1
2
3
curl -XDELETE http://192.168.3.11:9200/policy

curl -XPUT http://192.168.3.11:9200/policy

A new field mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
curl -XPOST http://192.168.3.11:9200/policy/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'

Add data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
curl -XPOST http://192.168.3.11:9200/policy/fulltext/1 -d'
{"content":"2017年1月1日起全国实行国Ⅴ排放标准"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/2 -d'
{"content":"2017年1月1日起实施:车内空气质量强制达标"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/3 -d'
{"content":"2017年试行新能源汽车碳配额管理"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/4 -d'
{"content":"新能源车生产企业准入规则 有望于2017年正式实施"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/5 -d'
{"content":"电池行业新规范 有望于2017年全面执行"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/6 -d'
{"content":"新能源补贴新政即将出炉 2017年将实施"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/7 -d'
{"content":"《外商投资产业指导目录》修订版将执行 合资车企股比不会放开"}
'

Have a search

1
2
3
4
5
6
7
8
9
10
11
12
curl -XPOST http://192.168.3.11:9200/policy/fulltext/_search  -d'
{
"query" : { "match" : { "content" : "能源" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'

Check engine status

1
2
3
curl -XGET http://192.168.3.11:9200/policy/_analyze?text=2017&tokenizer=ik_max_word

curl -XGET http://192.168.3.11:9200/_cluster/health?pretty=true

Hello elasticsearch

Posted on 2017-03-19 | Edited on 2018-12-16 | In search

Install

1
2
3
4
5
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz

sudo tar -xzvf elasticsearch-5.2.2.tar.gz

sudo chown -R pi:pi elasticsearch-5.2.2

If not change directory’s owner, user command sudo -E ./bin/elasticsearch execute the script, or the java path can’t be find.

Config

./bin/elasticsearch
dispatch memory

1
ES_JAVA_OPTS="-Xms70m -Xmx70m"

./config/elasticsearch.yml
set bootstrap to single machine mode

1
2
3
4
5
6
7
8
9
10
cluster.name: elastic-pi

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

network.host: 0.0.0.0
http.port: 9200

#http.cors.enabled: true
#http.cors.allow-origin: "*"

If exception happen like this
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
In single machine mode looks like no this problem

1
2
sudo echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sudo sysctl -p

Plugin

elasticsearch-analysis-ik

Pharse process plugin
release to plugin directory

1
2
3
curl -O https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.2.2/elasticsearch-analysis-ik-5.2.2.zip

unzip elasticsearch-analysis-ik-5.2.2.zip

head

install npm/ nodejs/ elasticsearch-head

Exception

org.elasticsearch.indices.IndexClosedException: closed

delete the origin index and rebuild index, it works.

Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

make sure java be right configed, and current user has privilege to use elasticsearch/ environment variable

Operate

  1. start
    nohup ./bin/elasticsearch&
    ./bin/elasticsearch -d

  2. stop
    ps -ef|grep elastic
    kill -9 51271

Hello hbase

Posted on 2017-03-15 | Edited on 2018-12-16 | In db

Download Configure

1
2
3
4
5
6
7
8
9
10
11
sudo curl -O http://mirrors.hust.edu.cn/apache/hbase/1.3.0/hbase-1.3.0-bin.tar.gz

sudo tar -xzvf hbase-1.3.0-bin.tar.gz

sudo vim conf/hbase-env.sh
> export JAVA_HOME=/usr/lib/jdk1.8.0_121
> export HBASE_CLASSPATH=/usr/lib/hbase-1.3.0/lib

sudo bash bin/start-hbase.sh

more logs/hbase-root-master-raspberrypi.log

Have a try

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bin/hbase shell

create 'PageViews', 'info'

list

descibe 'PageViews'

put 'PageViews', 'rowkey1', 'info:page', '/mypage'

put 'PageViews', 'rowkey1', 'info:count', '7'

get 'PageViews', 'rowkey1'

put 'PageViews', 'rowkey2', 'info:page', '/myotherpage'

put 'PageViews', 'srowkey2', 'info:page', '/myotherpage'

scan 'PageViews', {STARTROW=>'r', ENDROW=>'s'}

scan 'PageViews', {STARTROW=>'r'}

Inverse function

Posted on 2017-03-14 | Edited on 2020-06-16 | In python
ϕ−1(y)=19y3ϕ−1(y)=19y3↓↓ϕ(x)=9x13ϕ(x)=9x13
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plot
N = 10000
X0 = np.random.rand(N)
X1 = 3*X0
Y = np.power(9*X1, 1.0/3)
t = np.arange(0.0, 3.0, 0.01)
y = t*t/9
plot.plot(t, y, 'r-', linewidth=1)
plot.hist(Y, bins=50, normed=1, facecolor='green', alpha=0.75)
plot.show()

Random event

Posted on 2017-03-11 | Edited on 2020-06-16 | In math

All sample’s collection be called sample zone.

Ω1={1,2,3,4,5,6}Ω1={1,2,3,4,5,6}Ω2={t|t≥0}Ω2={t|t≥0}

Contain relation

∅⊂A⊂B∅⊂A⊂BA⊂BB⊂C⇒A⊂CA⊂BB⊂C⇒A⊂C

Equal realtion

A⊂B&&B⊂AA⊂B&&B⊂A

Events sum

A1⋃A2...⋃AnA1⋃A2...⋃An

or

n⋃i=1Ai⋃i=1nAi

Events product

A1⋂A2...⋂AnA1⋂A2...⋂An

or

n⋂i=1Ai⋂i=1nAi

Mutex events

AB=∅AB=∅

Oppose events

AB=∅&&A⋃B=ΩAB=∅&&A⋃B=ΩA=¯¯¯¯BB=¯¯¯¯AA=B¯B=A¯

Events difference

A−B=A¯¯¯¯B=A−(AB)A−B=AB¯=A−(AB)

Complete event group

n⋃i=1Ai=Ω&&Ai⋂Aj=∅(i≠j)⋃i=1nAi=Ω&&Ai⋂Aj=∅(i≠j)

Quicksort compare analysis

Posted on 2017-03-10 | Edited on 2020-06-16 | In algorithm

Quicksort user  2NlnN 2NlnN compares to sort
an array of N distinct keys on average
(one-sixth that many exchanges)

Proof

Let CNCN be the average number of compares need to sort N items
with distinct values.
We have C0=C1=0C0=C1=0 for N>1N>1

Express the average compare

CN=N+1+(C0+C1+...+CN−2+CN−1)/N+(CN−1+CN−2+...+C0)/NCN=N+1+(C0+C1+...+CN−2+CN−1)/N+(CN−1+CN−2+...+C0)/N
  1. cost of partitioning
    N-1 compares two partition with flag
    1 more compare in each part breakpoint compare
  1. left subarray sort

    (C0+C1+...+CN−2+CN−1)/N(C0+C1+...+CN−2+CN−1)/N
  2. right subarray sort

    (CN−1+CN−2+...+C1+C0)/N(CN−1+CN−2+...+C1+C0)/N

Rearrange terms

  1. Multiplying by N
NCN=N(N+1)+2(C0+C1+...+CN−2+CN−1)NCN=N(N+1)+2(C0+C1+...+CN−2+CN−1)
  1. Subtracting with same equation of N-1
NCN−(N−1)CN−1=N(N+1)−(N−1)N+NCN−(N−1)CN−1=N(N+1)−(N−1)N+2(C0+C1+...+CN−2+CN−1)−2(C0+C1+...+CN−2)2(C0+C1+...+CN−2+CN−1)−2(C0+C1+...+CN−2)⇒⇒NCN−(N−1)CN−1=2N+2CN−1NCN−(N−1)CN−1=2N+2CN−1
  1. Each item dividing by N(N+1) leaves
CN/(N+1)=CN−1/N+2/(N+1)CN/(N+1)=CN−1/N+2/(N+1)
  1. Add same equation from 1
CN/(N+1)=CN−1/N+2/(N+1)CN/(N+1)=CN−1/N+2/(N+1)++CN−1/(N)=CN−2/(N−1)+2/(N)CN−1/(N)=CN−2/(N−1)+2/(N)⋯⋯C3/(4)=C2/3+2/4C3/(4)=C2/3+2/4++C2/(3)=C1/2+2/3C2/(3)=C1/2+2/3⇒⇒C23+C34+...+CN−1N+CNN+1=C23+C34+...+CN−1N+CNN+1=C12+C23+...+CN−2N−1+CN−1N+23+34+...+2N+2N+1C12+C23+...+CN−2N−1+CN−1N+23+34+...+2N+2N+1⇒⇒CN(N+1)=C12+23+34+...+2N+1CN(N+1)=C12+23+34+...+2N+1⇒⇒CN∼2(N+1)(13+14+...+1N+1)CN∼2(N+1)(13+14+...+1N+1)
  1. Further integration
13+14+...+1N+1∼ln(N)13+14+...+1N+1∼ln(N)⇒⇒CN∼2NlnN≈1.39lgNCN∼2NlnN≈1.39lgN

PS.

1+12+13+...+1N>ln(1+1)+ln(1+12)+1+12+13+...+1N>ln(1+1)+ln(1+12)+...+ln(1+1N−1)+ln(1+1N)...+ln(1+1N−1)+ln(1+1N)⇒⇒1+12+13+...+1N>ln[2×32×43×...NN−1×N+1N]≈ln(N)1+12+13+...+1N>ln[2×32×43×...NN−1×N+1N]≈ln(N)

Euclidean algorithm

Posted on 2017-03-09 | Edited on 2020-09-17 | In math
1
2
3
4
5
int gcd(int a,int b) {
if(b==0)
return a;
return gcd(b,a%b);
}

1. Make

c=gcd(a,b)c=gcd(a,b)

-

a=mca=mc

-

b=ncb=nc

c is the biggest divisor

2. Got

r=a−kb=mc−knc=(m−kn)cr=a−kb=mc−knc=(m−kn)c

3. c is a divisor of r as well.

4. m-kn and n definitely has coprime relation

proof by contradiction

  1. setting they are no coprime relation

    m−kn=xdm−kn=xd

    -
    n=ydn=yd (d>1)

  2. then

    m=kn+xd=kyd+xd=(ky+x)dm=kn+xd=kyd+xd=(ky+x)d

    -

    a=mc=(ky+x)dca=mc=(ky+x)dc

    -

    b=nc=ydcb=nc=ydc
  3. a and b ‘s biggest divisor is not c. so step 4 proved.

5. c is biggest divisor in b and r as well.

gcd(b,r)=cgcd(b,r)=c

-

gcd(a,b)=gcd(b,r)gcd(a,b)=gcd(b,r)

RSA Principle 5

Posted on 2017-03-05 | Edited on 2020-06-16 | In math

Proving

Why?

cd≡m(modn)cd≡m(modn)

Base on encrypt rule:

me≡c(modn)me≡c(modn)

->

c=me−knc=me−kn

Put it into the target

(me−kn)d≡m(modn)(me−kn)d≡m(modn)

The n in left part of equal could all be divided by n. So it’s same as this:

med≡m(modn)med≡m(modn)

Bacause

ed≡1(modϕ(n))ed≡1(modϕ(n))

->

ed=hϕ(n)+1ed=hϕ(n)+1

Put it into above, prove this work

mhϕ(n)+1≡m(modn)mhϕ(n)+1≡m(modn)

Then divide into two condition

m and n has coprime relation

In this condition base on euler theorem

mϕ(n)≡1(modn)mϕ(n)≡1(modn)

Put it into above:

(mϕ(n))h×m≡m(modn)(mϕ(n))h×m≡m(modn)

Proved

m and n has no coprime relation

In this condition, bacause m and n has no coprime relation, so m and n must have common factor that is not 1.
n come from two coprime factor p and q, so m must multiply with p or q.
m = kp or m = kq

Choose m = kp for example
Because q is a coprime number, and k has no possible multiply q[or will cross m], so k and q has coprime relation.
Base on euler theorem:

φ(q)=q−1φ(q)=q−1(kp)q−1≡1(modq)(kp)q−1≡1(modq)

Further

[(kp)q−1]h(q−1)×kp≡kp(modq)[(kp)q−1]h(q−1)×kp≡kp(modq)

Bascause

ed=hϕ(n)+1ed=hϕ(n)+1

so:

(kp)ed≡kp(modq)(kp)ed≡kp(modq)(kp)ed=kp+tq(kp)ed=kp+tq

This time t definitely could be divided be p. Why?

p((kp)ed−1−k)=tqp((kp)ed−1−k)=tq

((kp)ed−1−k)((kp)ed−1−k) is an integer and p q has coprime relation
So definitely has integer t′=t/pt′=t/p

(kp)ed=kp+t′pq(kp)ed=kp+t′pq

m=kp, n=pq then:

med=m(modn)med=m(modn)

Proved

RSA Principle 4

Posted on 2017-03-05 | Edited on 2020-06-16 | In math

Encryption and decryption

Pub Key: (14363, 97)
Prv Key: (14363, 9553)

If A want send message m to B.
A need use B’s public key to encrypt M[Integer and M < n].

me≡c(modn)me≡c(modn)

Suppose A want send “Hello B” to B, the first alphabet ‘H’ should be encrypt like this.

c=7297mod14363c=7297mod14363

The ciphertext c is 5769

B received A’s message 5769, B use private key to decrypt it.

cd≡m(modn)cd≡m(modn)

->

M=57699553mod14363M=57699553mod14363

The text is 72[ ‘H’ in ASCII ]

Signatures and signed inspection certificate

It’s a opposite progress of above one.

Sender in order to show it’s identity, it need to use it’s private key to encrypt[autograph] abstract message like hash code or mac code.

Receiver got message, use public key to decrypt[certificate] the signature, than contract the clear text with message’s abstract.

1…222324…29

Leon

282 posts
20 categories
58 tags
GitHub
Links
  • clock
  • typing-cn
  • mathjax
  • katex
  • cron
  • dos
  • keyboard
  • regex
  • sql
  • toy
© 2017 – 2024 Leon
Powered by Hexo v3.9.0
|
Theme – NexT.Muse v7.1.2