公有云
云服务管理
弹性计算服务
云主机配置
名称 | IP地址 | 配置 |
web-0001 | 192.168.1.11 | 2CPU,4G内存 |
web-0002 | 192.168.1.12 | 2CPU,4G内存 |
- 部署网站页面
# 安装 nfs 协议客户端
[root@ecs-proxy ~]# dnf install -y nfs-utils
[root@ecs-proxy ~]# mount -t nfs -o nolock <SFS服务地址> /mnt/
[root@ecs-proxy ~]# mkdir /mnt/html
# 部署网站页面到文件共享服务
[root@ecs-proxy ~]# tar -zxf s4/public/website.tar.gz -C /mnt/html/
- 部署 web 服务
# 安装 Web 服务
[root@web ~]# dnf install -y httpd php nfs-utils
[root@web ~]# systemctl enable --now httpd
# 配置开机自动挂载
[root@web ~]# vim /etc/fstab
<SFS服务地址>:/html /var/www/html nfs defaults,_netdev 1 1
[root@web ~]# systemctl daemon-reload
[root@web ~]# mount -a
# 查看验证
[root@web ~]# df -h
Filesystem Size Used Avail Use% Mounted on
<SFS服务地址> 1.2T 0 1.2T 0% /var/www/html
负载均衡服务
# 访问验证
[root@ecs-proxy s4]# curl -m3 http://192.168.0.250/info.php
<pre>
Array
(
[REMOTE_ADDR] => 192.168.1.252
[REQUEST_METHOD] => GET
[HTTP_USER_AGENT] => curl/7.61.1
[REQUEST_URI] => /info.php
)
php_host: web
1229
项目架构图
Elasticsearch 安装
添加软件包
# 添加 ELK 软件包到自定义 Yum 仓库
[root@ecs-proxy s4]# rsync -av elk/ /var/localrepo/elk/
[root@ecs-proxy s4]# createrepo --update /var/localrepo
购买云主机
主机 | IP地址 | 配置 |
es-0001 | 192.168.1.21 | 最低配置2核4G |
es-0002 | 192.168.1.22 | 最低配置2核4G |
es-0003 | 192.168.1.23 | 最低配置2核4G |
集群安装
部署 es-0001
[root@es-0001 ~]# vim /etc/hosts
192.168.1.21 es-0001
192.168.1.22 es-0002
192.168.1.23 es-0003
[root@es-0001 ~]# dnf install -y elasticsearch
[root@es-0001 ~]# vim /etc/elasticsearch/elasticsearch.yml
17: cluster.name: my-es
23: node.name: es-0001
56: network.host: 0.0.0.0
70: discovery.seed_hosts: ["es-0001", "es-0002", "es-0003"]
74: cluster.initial_master_nodes: ["es-0001", "es-0002", "es-0003"]
[root@es-0001 ~]# systemctl enable --now elasticsearch
# 服务启动成功
[root@es-0001 ~]# curl http://127.0.0.1:9200
{
"name" : "es-0001",
"cluster_name" : "my-es",
"cluster_uuid" : "_na_",
"version" : {
"number" : "7.17.8",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "120eabe1c8a0cb2ae87cffc109a5b65d213e9df1",
"build_date" : "2022-12-02T17:33:09.727072865Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
部署 es-0002
# 验证集群状态失败
[root@es-0002 ~]# curl http://192.168.1.21:9200/_cat/nodes?pretty
{
"error" : {
"root_cause" : [
{
"type" : "master_not_discovered_exception",
"reason" : null
}
],
"type" : "master_not_discovered_exception",
"reason" : null
},
"status" : 503
}
# 部署服务
[root@es-0002 ~]# vim /etc/hosts
192.168.1.21 es-0001
192.168.1.22 es-0002
192.168.1.23 es-0003
[root@es-0002 ~]# dnf install -y elasticsearch
[root@es-0002 ~]# vim /etc/elasticsearch/elasticsearch.yml
17: cluster.name: my-es
23: node.name: es-0002
56: network.host: 0.0.0.0
70: discovery.seed_hosts: ["es-0001", "es-0002", "es-0003"]
74: cluster.initial_master_nodes: ["es-0001", "es-0002", "es-0003"]
[root@es-0002 ~]# systemctl enable --now elasticsearch
# 验证集群状态
[root@es-0002 ~]# curl http://127.0.0.1:9200/_cat/nodes
192.168.1.21 16 89 2 0.15 0.06 0.04 cdfhilmrstw * es-0001
192.168.1.22 6 88 61 1.00 0.23 0.08 cdfhilmrstw - es-0002
部署 es-0003
[root@es-0003 ~]# vim /etc/hosts
192.168.1.21 es-0001
192.168.1.22 es-0002
192.168.1.23 es-0003
[root@es-0003 ~]# dnf install -y elasticsearch
[root@es-0003 ~]# vim /etc/elasticsearch/elasticsearch.yml
17: cluster.name: my-es
23: node.name: es-0003
56: network.host: 0.0.0.0
70: discovery.seed_hosts: ["es-0001", "es-0002", "es-0003"]
74: cluster.initial_master_nodes: ["es-0001", "es-0002", "es-0003"]
[root@es-0003 ~]# systemctl enable --now elasticsearch
[root@es-0003 ~]# curl http://127.0.0.1:9200/_cat/nodes
192.168.1.21 16 89 2 0.15 0.06 0.04 cdfhilmrstw * es-0001
192.168.1.22 6 88 61 1.00 0.23 0.08 cdfhilmrstw - es-0002
192.168.1.23 6 86 1 0.64 0.21 0.07 cdfhilmrstw - es-0003
插件管理
部署插件页面
# 拷贝插件 public/head.tar.gz 到 es-0001 主机
[root@ecs-proxy s4]# rsync -av public/head.tar.gz 192.168.1.21:./
#-------------------------------------------------
# 在 es-0001 上安装 web 服务,并部署插件
[root@es-0001 ~]# dnf install -y nginx
[root@es-0001 ~]# systemctl enable --now nginx
[root@es-0001 ~]# tar zxf head.tar.gz -C /usr/share/nginx/html/
- 通过 ELB 的 8080 端口,发布服务到互联网
认证和代理
[root@es-0001 ~]# vim /etc/nginx/default.d/esproxy.conf
location ~* ^/es/(.*)$ {
proxy_pass http://127.0.0.1:9200/$1;
auth_basic "Elasticsearch admin";
auth_basic_user_file /etc/nginx/auth-user;
}
[root@es-0001 ~]# dnf install -y httpd-tools
[root@es-0001 ~]# htpasswd -cm /etc/nginx/auth-user admin
New password:
Re-type new password:
Adding password for user admin
[root@es-0001 ~]# systemctl reload nginx
- 通过 head 插件管理 elasticsearch 集群
API原语管理
集群状态查询
# 查询支持的关键字
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/_cat/
# 查具体的信息
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/_cat/master
# 显示详细信息 ?v
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/_cat/master?v
# 显示帮助信息 ?help
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/_cat/master?help
# 显示易读格式 ?pretty
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/_cat/master?pretty
创建索引
- 指定索引的名称,指定分片数量,指定副本数量
# 创建 tedu 索引
[root@es-0001 ~]# curl 'http://127.0.0.1:9200/tedu?pretty' \
-X PUT -H 'Content-Type: application/json' -d '{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}'
增加数据
[root@es-0001 ~]# curl -XPUT -H "Content-Type: application/json" \
http://127.0.0.1:9200/tedu/teacher/1?pretty -d '{
"职业": "诗人","名字": "李白","称号": "诗仙","年代": "唐"
}'
查询数据
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/tedu/teacher/_search?pretty
[root@es-0001 ~]# curl -XGET http://127.0.0.1:9200/tedu/teacher/1?pretty
修改数据
[root@es-0001 ~]# curl -XPOST -H "Content-Type: application/json" \
http://127.0.0.1:9200/tedu/teacher/1/_update -d '{
"doc": {"年代":"公元701"}
}'
删除数据
# 删除一条
[root@es-0001 ~]# curl -XDELETE http://127.0.0.1:9200/tedu/teacher/1
# 删除索引
[root@es-0001 ~]# curl -XDELETE http://127.0.0.1:9200/tedu