Web集群部署实战

2023-10-26

Web集群部署实战

Web集群架构图

系统规划

实验要求:购买一个 SFS 服务,以及 3 台云主机,部署 apache + php 的网站

 购买云主机3台

 

部署网页数据 

# 挂载 SFS 服务到跳板机
[root@ecs-proxy ~]# dnf install -y nfs-utils
[root@ecs-proxy ~]# mount -t nfs -o vers=3,nolock 192.168.1.197:/ /mnt/
[root@ecs-proxy ~]# df -h /mnt/
Filesystem       Size  Used   Avail  Use%   Mounted  on
192.168.1.197:/  500G     0    500G    0%   /mnt

# 部署网页到 NFS 服务 
[root@ecs-proxy ~]# cd 4
[root@ecs-proxy 4]# tar -zxf public/website.tar.gz -C /mnt/

部署web服务

[root@ecs-proxy ~]# mkdir website
[root@ecs-proxy ~]# cd website
[root@ecs-proxy website]# vim ansible.cfg
[defaults]
inventory = hostlist
host_key_checking = False
[root@ecs-proxy website]# vim hostlist
[web]
192.168.1.[11:13]


[root@ecs-proxy website]# ansible all -m ping
可能报错
Ansible conld noe initialize the preferred locale: unsupported local setting
这个报错是由于ansible  无法初始化首选语言环境所导致的。
解决方法:1.在~/.bashrc 文件末尾添加2行
export LC_ALL =en_US.UTF-8
c
从重新执行 source ~/.bashrc 解决问题
这两个命令的作用是设置系统的默认语言环境为英语(美国)和UTF-8编码。
export LC_ALL=en_US.UTF-8 命令会将系统的语言环境设置为英语(美国),并使用UTF-8编码格式。这意味着在系统中输入和输出的所有文本都将使用UTF-8编码格式,以确保它们可以正确地显示和处理非英语字符。
export LANG=en_US.UTF-8 命令与 export LC_ALL=en_US.UTF-8 命令类似,但它只设置了系统的默认语言环境,而不是整个系统的语言环境。这意味着只有当前终端窗口中的语言环境会被设置为英语(美国)和UTF-8编码格式,而其他终端窗口仍然保持原来的语言环境设置不变。
方法2: 
cat > /etc/profile.d/lang.sh<<EOF
export LANG="en_US.UTF-8"
EOF

[root@ecs-proxy website]# cat > web_install.yaml<< EOF
---
- name: web 集群安装
  hosts: web
  tasks:
  - name: 安装 apache 服务 
    dnf:
      name: httpd,php,nfs-utils
      state: latest
      update_cache: yes
  - name: 配置 httpd 服务 
    service:
      name: httpd
      state: started
      enabled: yes
  - name: 编辑 fstab 文件,添加 NFS 配置
    lineinfile:
      path: /etc/fstab
      regexp: '^192.168.1.197:/.*'
      line: '192.168.1.197:/ /var/www/html nfs defaults,_netdev,vers=3,nolock 1 1'
      create: yes
  - name: 挂载 NFS
    shell:
      cmd: mount /var/www/html
EOF
[root@ecs-proxy website]# ansible-playbook web_install.yaml

验证结果

[root@ecs-proxy ~]# curl http://192.168.1.11/info.php
<pre>
Array
(
    [REMOTE_ADDR] => 192.168.1.252
    [REQUEST_METHOD] => GET
    [HTTP_USER_AGENT] => curl/7.29.0
    [REQUEST_URI] => /info.php
)
php_host: web-0001
1229

配置负载均衡 

购买负载均衡

 

负载均衡(ELB)

配置华为云负责均衡对外发布服务

[root@ecs-proxy ~]# curl http://192.168.1.250/info.php
<pre>
Array
(
    [REMOTE_ADDR] => 100.125.99.180
    [REQUEST_METHOD] => GET
    [HTTP_USER_AGENT] => curl/7.29.0
    [REQUEST_URI] => /info.php
)
php_host: web-0001
1229

弹性公网ip绑定到负载均衡服务器上,可以在公网访问80网站 

 http://124.70.1.159/info.php

Elasticsearch 安装

项目架构图

添加软件包

# 添加 ELK 软件包到自定义 Yum 仓库
[root@ecs-proxy s4]# rsync -av elk/ /var/localrepo/elk/
[root@ecs-proxy s4]# createrepo --update /var/localrepo

购买云主机

集群安装

部署 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
192.168.1.24    es-0004
192.168.1.25    es-0005
[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://es-0001: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
192.168.1.24    es-0004
192.168.1.25    es-0005
[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://es-0001:9200/_cat/nodes?pretty
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 主机安装 Elasticsearch
  • [root@ecs-proxy ~]# mkdir es
    [root@ecs-proxy ~]# cd es
    [root@ecs-proxy es]# vim ansible.cfg 
    [defaults]
    inventory = hostlist
    host_key_checking = False
    [root@ecs-proxy es]# vim hostlist
    [es]
    192.168.1.[21:25]
    [root@ecs-proxy es]# rsync -av 192.168.1.21:/etc/elasticsearch/elasticsearch.yml elasticsearch.j2
    [root@ecs-proxy es]# vim elasticsearch.j2
    23:  node.name: {{ ansible_hostname }}
    [root@ecs-proxy es]# vim es_install.yaml 
    ---
    - name: Elasticsearch 集群安装
      hosts: es
      tasks:
      - name: 设置 /etc/hosts
        copy:
          dest: /etc/hosts
          owner: root
          group: root
          mode: '0644'
          content: |
            ::1     localhost localhost.localdomain localhost6 localhost6.localdomain6
            127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
            {% for i in groups.es %}
            {{ hostvars[i].ansible_eth0.ipv4.address }} {{ hostvars[i].ansible_hostname }}
            {% endfor %}
      - name: 安装 ES 服务
        dnf:
          name: elasticsearch
          state: latest
          update_cache: yes
      - name: 拷贝配置文件
        template:
          src: elasticsearch.j2
          dest: /etc/elasticsearch/elasticsearch.yml
          owner: root
          group: elasticsearch
          mode: '0660'
      - name: 配置 ES 服务 
        service:
          name: elasticsearch
          state: started
          enabled: yes
    
    [root@ecs-proxy es]# ansible-playbook es_install.yaml
    [root@ecs-proxy es]# curl http://192.168.1.21:9200/_cat/nodes?pretty
    192.168.1.21 32 88 0 0.04 0.01 0.00 cdfhilmrstw * es-0001
    192.168.1.22 16 87 0 0.13 0.04 0.01 cdfhilmrstw - es-0002
    192.168.1.23  6 86 1 0.64 0.21 0.07 cdfhilmrstw - es-0003
    192.168.1.24 18 86 0 0.44 0.13 0.05 cdfhilmrstw - es-0004
    192.168.1.25  6 86 1 0.67 0.21 0.07 cdfhilmrstw - es-0005

    插件管理

    Head插件原理图

 部署插件页面

# 拷贝插件 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 ~]# dnf install -y nginx httpd-tools
    [root@es-0001 ~]# systemctl enable --now nginx
    [root@es-0001 ~]# vim /etc/nginx/default.d/esproxy.conf 
    location ~* ^/es/(.*)$ {
        auth_basic "Elasticsearch admin";
        auth_basic_user_file /etc/nginx/auth-user; 
        proxy_pass http://127.0.0.1:9200/$1;
    }
    [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

创建索引

  • 指定索引的名称,指定分片数量,指定副本数量
# 设置默认分片副本数量
[root@es-0001 ~]# curl -XPUT -H 'Content-Type: application/json' \
    http://127.0.0.1:9200/_template/index_defaults -d '{
      "template": "*",
      "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
      }
    }'

{"acknowledged":true}

# 创建 tedu 索引
[root@es-0001 ~]# curl -XPUT http://127.0.0.1:9200/tedu?pretty
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "tedu"
}

增加数据

[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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Web集群部署实战 的相关文章

随机推荐

  • VS的多线程调试问题

    今天进度太慢了 本来就不是非常有时间的 结果都花在了整系统结构的上面 虽说是用了新的开源图像引擎 使用了新的构架 但是 我还是想走以前的老路 因为我觉得把视图渲染放到后台的某一个线程当中可能是一种比较合理的做法 整了一天 终于通过thunk
  • C++互斥锁std::mutex

    目录 std mutex 成员函数 std lock guard std unique lock std mutex实测代码 std mutex 是C 11 中最基本的互斥量 std mutex 对象提供了独占所有权的特性 即不支持递归地对
  • 统计学习方法(第三章)--KNN分类器python实现及kd树实现及sklearn调用

    KNN算法的的原理 KNN不存在显式的学习过程 对于一个测试样本 根据给定的距离计算公式 和k值 找到距离测试样本最近的k个训练样本 k个训练样本得票最高的类别作为测试样本的类别 三要素 距离的度量 np linalg norm x y p
  • springboot集成kafka

    1 pom xml中增加依赖包
  • 阿里云 一键web 部署

    阿里云 一键web 部署 软件下载地址 包含下文中所需要用到的文件 下面文中提到的文件下载地址 提取码 688c xftp 和 xshell下载地址 提取码 ertk 参考下面这篇文章 经测试 成功部署 https www cnblogs
  • shell输入内容时不显示内容

    简介 大家都知道当我们ssh登录linux服务器的时候输入密码密码是不显示在屏幕上的 同样在我们写shell脚本的时候在获取用户密码的时候 有时候也希望不显示密码 这个是怎么做的呢 实例脚本 bin bash echo 请输入密码 stty
  • pytorch输出tensor维度时报错:built-in method size of Tensor object at 0x7f2051c31ea0

    使用python输出某tensor的维度 print tensor size 出现报错 built in method size of Tensor object at 0x7f2051c31ea0 原因是size后面少了括号 加上即可 p
  • Linux 安装jenkins和jdk11

    Linux 安装jenkins和jdk11 1 Install Jdk11 2 Jenkins Install 2 1 Install Jenkins 2 2 Start 2 3 Error 3 Awakening 1 1 Big Data
  • opencv_contrib_python-3.4.0.12-cp36-cp36m(32位 64位)百度云资源

    官方下载地址下载太慢 贴一个百度云的地址 https pan baidu com s 1gguVL55 32位 https pan baidu com s 1bqP8c0Z 64位
  • STL标准模板库

    目录 一 容器 1 所有容器 2 常用容器 3 容器主要用法 4 resize和reserve 二 关系模型 1 谁需要关系 2 运算符最小集 3 弱序关系和严格弱序关系 4 相等关系 5 序关系和相等关系的关系 三 算法 1 sort函数
  • 华为机试HJ2-计算字符串中给定字符出现次数

    输入字符串以及特定字符 计算字符串中特定字符出现次数 include
  • spring cloud mybatis+mysql实现对数据库数据的访问

    MyBatis 是一款优秀的持久层框架 它支持定制化 SQL 存储过程以及高级映射 MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集 MyBatis 可以使用简单的 XML 或注解来配置和映射原生类型 接口和 J
  • Linux指令

    1 pwd 显示当前用户所处的工作路径 2 ls 列出当前目录下所有文件和文件夹 ls 选项 常见的命令 ls l 显示文件的具体信息 文件的属性 大小 一行显示一个文件 ls a 显示所有的文件和文件夹 包含了以 开头的隐藏文件和文件夹
  • $(function(){})和$(document).ready(function(){})

    document ready和onload的区别 JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready 表示文档结构已经加载完成 不包含图片等非文字媒体文件 二是onload 指示页面包含图片等文件在内的所有元素都加
  • R语言-多元统计学分析课程报告

    本文我们应用的软件为R语言 进行多元统计分析 所用的数据集为鸢尾花数据集 我们进行了Bayes判别 Fisher判别 系统聚类法 k 均值聚类和主成分分析 导入鸢尾花数据集 data lt read csv E 数学专业 多元统计学上机作业
  • 【Windows】win10任务栏图标空白的解决方案

    win10任务栏图标空白的解决方案 一 错误原因 在 Windows 10 系统中 为了加速图标的显示 当第一次对图标进行显示时 系统会对文件或程序的图标进行缓存 之后 当我们再次显示该图标时 系统会直接从缓存中读取数据 从而大大加快显示速
  • h5跳转小程序

    h5跳转小程序 我的所写的项目是react框架 在h5跳转小程序时 需要引入wx jssdk 具体操作看我上篇文章 https blog csdn net weixin 45315794 article details 122448088
  • Spring中@Autowired注解、J2EE @Resource注解的区别

    Spring不但支持自己定义的 Autowired注解 还支持几个由JSR 250规范定义的注解 它们分别是 Resource PostConstruct以及 PreDestroy Resource的作用相当于 Autowired 只不过
  • Android逆向工程:MIUI系统大揭秘:去不掉的小米账号!

    哈喽小伙伴们大家好 欢迎继续学习探讨MIUI系统的安全防范知识 在上篇博客中 Android逆向工程 带你领略MIUI系统的账号安全防范机制 账号是从哪里获取的 我们了解到了MIUI系统通过对关键代码进行封装进系统内 对外采用统一调用接口的
  • Web集群部署实战

    Web集群部署实战 Web集群架构图 系统规划 实验要求 购买一个 SFS 服务 以及 3 台云主机 部署 apache php 的网站 购买云主机3台 部署网页数据 挂载 SFS 服务到跳板机 root ecs proxy dnf ins