深入理解Zookeeper系列-2.Zookeeper基本使用和分布式锁原理

news2024/9/22 15:47:09
  • 👏作者简介:大家好,我是爱吃芝士的土豆倪,24届校招生Java选手,很高兴认识大家
  • 📕系列专栏:Spring源码、JUC源码、Kafka原理、分布式技术原理
  • 🔥如果感觉博主的文章还不错的话,请👍三连支持👍一下博主哦
  • 🍂博主正在努力完成2023计划中:源码溯源,一探究竟
  • 📝联系方式:nhs19990716,加我进群,大家一起学习,一起进步,一起对抗互联网寒冬👀

文章目录

  • 集群环境安装
  • Zookeeper java客户端的使用
    • Curator
    • 代码
    • 权限操作
      • 权限模式
  • 节点监听
  • 分布锁的实现

集群环境安装

在zookeeper集群中,各个节点总共有三种角色,分别是:leader,follower,observer

集群模式我们采用模拟3台机器来搭建zookeeper集群。分别复制安装包到三台机器上并解压,同时copy一份zoo.cfg。

  • 修改配置文件
  1. 修改端口
  2. server.1=IP1:2888:3888 【2888:访问zookeeper的端口;3888:重新选举leader的端口】
  3. server.2=IP2.2888:3888
  4. server.3=IP3.2888:2888
  • server.A=B:C:D:其 中
  1. A 是一个数字,表示这个是第几号服务器;
  2. B 是这个服务器的 ip地址;
  3. C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;
  4. D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新
    的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方
    式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配
    不同的端口号。
  5. 在集群模式下,集群中每台机器都需要感知到整个集群是由哪几台机器组成的,在配置文件
    中,按照格式server.id=host:port:port,每一行代表一个机器配置。id: 指的是server ID,用
    来标识该机器在集群中的机器序号
  • 新建datadir目录,设置myid

在每台zookeeper机器上,我们都需要在数据目录(dataDir)下创建一个myid文件,该文件只有一行内容,对应每台机器的Server ID数字;比如server.1的myid文件内容就是1。【必须确保每个服务器的myid文件中的数字不同,并且和自己所在机器的zoo.cfg中server.id的id值一致,id的范围是1~255】

  • 启动zookeeper

需要注意的是,如果使用云服务器搭建的话,需要开放端口。

Zookeeper java客户端的使用

针对zookeeper,比较常用的Java客户端有zkclient、curator。由于Curator对于zookeeper的抽象层次
比较高,简化了zookeeper客户端的开发量。使得curator逐步被广泛应用。

  1. 封装zookeeper client与zookeeper server之间的连接处理
  2. 提供了一套fluent风格的操作api
  3. 提供zookeeper各种应用场景(共享锁、leader选举)的抽象封装

Curator

<dependency>
	<groupId>org.apache.curator</groupId>
	<artifactId>curator-framework</artifactId>
	<version>4.2.0</version>
</dependency>
<dependency>
	<groupId>org.apache.curator</groupId>
	<artifactId>curator-recipes</artifactId>
	<version>4.2.0</version>
</dependency>

代码

public static void main(String[] args) throws Exception {
        
        CuratorFramework curatorFramework=
                CuratorFrameworkFactory.builder().
                        connectString("192.168.216.128:2181,192.168.216.129:2181,192.168.216.130:2181").
                        sessionTimeoutMs(5000). // 会话超时,定时心跳机制
                        retryPolicy(new ExponentialBackoffRetry
                                (1000,3)).//重试
                        connectionTimeoutMs(4000).build();
        curatorFramework.start(); //表示启动.
//创建
//        create(curatorFramework);
//修改
//        update(curatorFramework);
//查看
//        get(curatorFramework);
    
    	operatorWithAsync(curatorFramework);


        create(curatorFramework);
    }

    private static String get(CuratorFramework curatorFramework) throws Exception {
        String rs=new String(curatorFramework.getData().forPath("/first_auth"));
        System.out.println(rs);
        return rs;
    }

    private static String create(CuratorFramework curatorFramework) throws Exception {

       String path=curatorFramework.create().
                creatingParentsIfNeeded().
                withMode(CreateMode.PERSISTENT).forPath("/first","Hello Gupaao".getBytes());
        System.out.println("创建成功的节点: "+path);
        return path;
    }

    private static String update(CuratorFramework curatorFramework) throws Exception {
        curatorFramework.setData().forPath("/first","Hello GuPaoEdu.cn".getBytes());
        return null;
    }

    //异步访问 | 同步(future.get())
    //redisson
    private static String operatorWithAsync(CuratorFramework curatorFramework) throws Exception {
        // 之前说过,数据同步的时候需要投票,如果我们可以使用异步的请求
        CountDownLatch countDownLatch = new CountDownLatch(1);
        curatorFramework.create().creatingParentsIfNeeded().
                withMode(CreateMode.PERSISTENT).inBackground(new BackgroundCallback() {
            @Override
            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
                System.out.println(Thread.currentThread().getName()+":"+event.getResultCode());
                countDownLatch.countDown();
            }
        }).forPath("/second","second".getBytes());
        //TODO ...
        System.out.println("before");
        countDownLatch.await(); //阻塞
        System.out.println("after");
        return "";
    }


测试 进入zookeeper
ls /
get first   就可以看到这个数据了

权限操作

我们可以设置当前节点增删改查的权限。

read
write(修改)
delete
create(创建)
admin
简写: rwdca

private static String authOperation(CuratorFramework curatorFramework) throws Exception {
        List<ACL> acls=new ArrayList<>();
        ACL acl=new ACL(ZooDefs.Perms.CREATE| ZooDefs.Perms.DELETE,new Id("digest", DigestAuthenticationProvider.generateDigest("u1:u1")));
        ACL acl1=new ACL(ZooDefs.Perms.ALL,new Id("digest", DigestAuthenticationProvider.generateDigest("u2:u2")));
        acls.add(acl);
        acls.add(acl1);
        curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).
                withACL(acls).forPath("/first_auth","123".getBytes());
        return null;
    }


List<AuthInfo> list=new ArrayList<>();
        AuthInfo authInfo=new AuthInfo("digest","u2:u2".getBytes());
        list.add(authInfo);
        CuratorFramework curatorFramework=
                CuratorFrameworkFactory.builder().
                        connectString("192.168.216.128:2181,192.168.216.129:2181,192.168.216.130:2181").
                        sessionTimeoutMs(5000).
                        retryPolicy(new ExponentialBackoffRetry
                                (1000,3)).
                        connectionTimeoutMs(4000).authorization(list).build();
        curatorFramework.start(); //表示启动.

权限模式

  • Ip 通过ip地址粒度来进行权限控制,例如配置 [ip:192.168.0.1], 或者按照网段 ip:192.168.0.1/24 ;
  • Digest:最常用的控制模式,类似于 username:password ;设置的时候需要
  • DigestAuthenticationProvider.generateDigest() SHA-加密和base64编码
  • World: 最开放的控制模式,这种权限控制几乎没有任何作用,数据的访问权限对所有用户开放。 world:anyone
  • Super: 超级用户,可以对节点做任何操作
  • auth 不需要id。不过这里应该用 expression 来表示。即(scheme:expression:perm)

节点监听

  • 当前节点的创建(NodeCreated)
  • 子节点的变更事件(NodeChildrenChanged) ->Dubbo
  • 当前被监听的节点的数据变更事件:NodeDataChanged
  • 当前节点被删除的时候会触发 NodeDeleted

ZooKeeper zooKeeper;
    public void originApiTest() throws IOException, KeeperException, InterruptedException {
        ZooKeeper zooKeeper=new ZooKeeper("192.168.216.128:2181", 5000, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                //表示连接成功之后,会产生的回调时间
            }
        });
        Stat stat=new Stat();
        zooKeeper.getData("/first", new DataWatchListener(),stat); //针对当前节点

      /*  zooKeeper.exists();  //针对当前节点
        zooKeeper.getChildren();  //针对子节点的监听*/
    }


class DataWatchListener implements Watcher{
        @Override
        public void process(WatchedEvent watchedEvent) {
            // 事件回调
            String path=watchedEvent.getPath();
            // 再次注册监听
            try {
                zooKeeper.getData(path,this,new Stat());
            } catch (KeeperException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
private static void addNodeCacheListener(CuratorFramework curatorFramework,String path) throws Exception {
    	
        NodeCache nodeCache=new NodeCache(curatorFramework,path,false);
        NodeCacheListener nodeCacheListener=new NodeCacheListener() {
            @Override
            public void nodeChanged() throws Exception {
                System.out.println("Receive Node Changed");
                System.out.println(""+nodeCache.getCurrentData().getPath()+"->"+new String(nodeCache.getCurrentData().getData()));
            }
        };
        nodeCache.getListenable().addListener(nodeCacheListener);
        nodeCache.start();
    }



    private static void addPathChildCacheListener(CuratorFramework curatorFramework,String path) throws Exception {
        PathChildrenCache childrenCache=new PathChildrenCache(curatorFramework,path,true);
        PathChildrenCacheListener childrenCacheListener=new PathChildrenCacheListener() {
            @Override
            public void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent pathChildrenCacheEvent) throws Exception {
                System.out.println("子节点事件变更的回调");
                ChildData childData=pathChildrenCacheEvent.getData();
                System.out.println(childData.getPath()+"-"+new String(childData.getData()));
            }
        };
        childrenCache.getListenable().addListener(childrenCacheListener);
        childrenCache.start(PathChildrenCache.StartMode.NORMAL);
    }


addNodeCacheListener(curatorFramework,"/first");

addPathChildCacheListener(curatorFramework,"/first");

需要在main方法中 不让其结束
System.in.read();

分布锁的实现

在这里插入图片描述

两个线程访问一个共享资源,就会造成数据的不确定性。所以需要加锁。

在这里插入图片描述

但是在分布式的场景下,线程变成进程

在这里插入图片描述

那么应该怎么做呢?如果使用Zookeeper来实现呢?

按照zookeeper的特性,只会有一个节点成功,其他的都是失败特性。如果处理完了,其他节点监听这个,当成功的那个节点删除了之后,回调通知再次获得锁即可。

在这里插入图片描述

但是会存在一个问题,比如说有100个节点,那么他就会触发99次来通知剩下的节点,为了解决这样的一个问题,一次性唤醒所有的话,我们可以使用顺序节点

在这里插入图片描述

先写入后,先排队

这样的话,我们每个节点只需要监听上一个顺序的变化即可,如果我们发现了一个节点删除了,然后去判断自己是不是序号最好的就ok,如果是最小的,那就发起获取锁的动作,如果不是就等着。

在这里插入图片描述

CuratorFramework curatorFramework=
                CuratorFrameworkFactory.builder().
                        connectString("192.168.216.128:2181,192.168.216.129:2181,192.168.216.130:2181").
                        sessionTimeoutMs(5000).
                        retryPolicy(new ExponentialBackoffRetry
                                (1000,3)).
                        connectionTimeoutMs(4000).build();
        curatorFramework.start(); //表示启动.

        /**
         * locks 表示命名空间
         * 锁的获取逻辑是放在zookeeper
         * 当前锁是跨进程可见
         */
        InterProcessMutex lock=new InterProcessMutex(curatorFramework,"/locks");
        for(int i=0;i<10;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"->尝试抢占锁");
                try {
                    lock.acquire();//抢占锁,没有抢到,则阻塞
                    System.out.println(Thread.currentThread().getName()+"->获取锁成功");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    Thread.sleep(4000);
                    lock.release(); //释放锁
                    System.out.println(Thread.currentThread().getName()+"->释放锁成功");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            },"t-"+i).start();
        }

    }

InterProcessMutex

private final ConcurrentMap<Thread, InterProcessMutex.LockData> threadData;

// 首先看 acquire 方法
public void acquire() throws Exception {
        if (!this.internalLock(-1L, (TimeUnit)null)) {
            throw new IOException("Lost connection while trying to acquire lock: " + this.basePath);
        }
    }
    
    
private boolean internalLock(long time, TimeUnit unit) throws Exception {
    // 获得当前线程
        Thread currentThread = Thread.currentThread();
        InterProcessMutex.LockData lockData = (InterProcessMutex.LockData)this.threadData.get(currentThread);
        if (lockData != null) {
            // 首先判断在同一个线程是否有重入的情况
            // 如果有重入,则 +1
            lockData.lockCount.incrementAndGet();
            return true;
        } else {
            // 如果没有重入
            String lockPath = this.internals.attemptLock(time, unit, this.getLockNodeBytes());
            if (lockPath != null) {
                // 说明注册成功
                InterProcessMutex.LockData newLockData = new InterProcessMutex.LockData(currentThread, lockPath);
                // 存进map中
                this.threadData.put(currentThread, newLockData);
                return true;
            } else {
                return false;
            }
        }
    }

进入 attemptLock

String attemptLock(long time, TimeUnit unit, byte[] lockNodeBytes) throws Exception {
        long startMillis = System.currentTimeMillis();
        Long millisToWait = unit != null ? unit.toMillis(time) : null;
        byte[] localLockNodeBytes = this.revocable.get() != null ? new byte[0] : lockNodeBytes;
        int retryCount = 0;
        String ourPath = null;
        boolean hasTheLock = false;
        boolean isDone = false;

		// 这里面是一个死循环
        while(!isDone) {
            isDone = true;

            try {
            // try里面的逻辑,会在循环中会去创建一个锁
                ourPath = this.driver.createsTheLock(this.client, this.path, localLockNodeBytes);
                hasTheLock = this.internalLockLoop(startMillis, millisToWait, ourPath);
            } catch (NoNodeException var14) {
            // catch里面的逻辑实际上是重试逻辑
                if (!this.client.getZookeeperClient().getRetryPolicy().allowRetry(retryCount++, System.currentTimeMillis() - startMillis, RetryLoop.getDefaultRetrySleeper())) {
                    throw var14;
                }

                isDone = false;
            }
        }

        return hasTheLock ? ourPath : null;
    }
    
进入createsTheLock

public String createsTheLock(CuratorFramework client, String path, byte[] lockNodeBytes) throws Exception {
		// 本质上就是创建一个临时有序节点
        String ourPath;
        if (lockNodeBytes != null) {
            ourPath = (String)((ACLBackgroundPathAndBytesable)client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)).forPath(path, lockNodeBytes);
        } else {
            ourPath = (String)((ACLBackgroundPathAndBytesable)client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)).forPath(path);
        }

        return ourPath;
    }
    

// try里面的逻辑,会在循环中会去创建一个锁
                ourPath = this.driver.createsTheLock(this.client, this.path, localLockNodeBytes);
// 此时去判断拿没拿到锁,拿到了以后去判断是不是最小的
                hasTheLock = this.internalLockLoop(startMillis, millisToWait, ourPath);

internalLockLoop

private boolean internalLockLoop(long startMillis, Long millisToWait, String ourPath) throws Exception {
        boolean haveTheLock = false;
        boolean doDelete = false;

        try {
            if (this.revocable.get() != null) {
                ((BackgroundPathable)this.client.getData().usingWatcher(this.revocableWatcher)).forPath(ourPath);
            }

            while(this.client.getState() == CuratorFrameworkState.STARTED && !haveTheLock) { // while循环判断客户端的连接没有断开,并且没有获得锁的情况下
            
            // 拿到排序之后的节点
                List<String> children = this.getSortedChildren();
                String sequenceNodeName = ourPath.substring(this.basePath.length() + 1);
                
                // 去执行一个判断锁的逻辑
                PredicateResults predicateResults = this.driver.getsTheLock(this.client, children, sequenceNodeName, this.maxLeases);
                
                // 是否获得锁
                if (predicateResults.getsTheLock()) {
                    haveTheLock = true;
                } else {
                // 否则进入监听的逻辑
                    String previousSequencePath = this.basePath + "/" + predicateResults.getPathToWatch();
                    synchronized(this) {
                        try {
                            ((BackgroundPathable)this.client.getData().usingWatcher(this.watcher)).forPath(previousSequencePath);
                            if (millisToWait == null) {
                            // 在监听中告诉其等待
                                this.wait(); 
                            } else {
                                millisToWait = millisToWait - (System.currentTimeMillis() - startMillis);
                                startMillis = System.currentTimeMillis();
                                if (millisToWait > 0L) {
                                    this.wait(millisToWait);
                                } else {
                                    doDelete = true;
                                    break;
                                }
                            }
                        } catch (NoNodeException var19) {
                        }
                    }
                }
            }
        } catch (Exception var21) {
            ThreadUtils.checkInterrupted(var21);
            doDelete = true;
            throw var21;
        } finally {
            if (doDelete) {
                this.deleteOurPath(ourPath);
            }

        }

        return haveTheLock;
    }
    

进入getsTheLock


public PredicateResults getsTheLock(CuratorFramework client, List<String> children, String sequenceNodeName, int maxLeases) throws Exception {
		// 得到索引,验证合法性
        int ourIndex = children.indexOf(sequenceNodeName);
        validateOurIndex(sequenceNodeName, ourIndex);
        
        // 判断是不是最小的,如果不是就取 -1之后的数
        boolean getsTheLock = ourIndex < maxLeases;
        String pathToWatch = getsTheLock ? null : (String)children.get(ourIndex - maxLeases);
        return new PredicateResults(pathToWatch, getsTheLock);
        
        
        // 首先,通过children.indexOf(sequenceNodeName)方法获取当前客户端创建的节点在子节点列表中的索引位置,并验证其合法性。然后,判断当前节点是否是最小的(即序号最小)。如果是最小的,则直接获取锁;否则,通过计算得到当前节点前面的一个节点名称,并将其设置为需要监听的节点路径,等待该节点释放锁后再尝试获取锁。
    }
    

-----------------------------------------------释放
// 当收到这个节点发生变化以后
private final Watcher watcher = new Watcher() {
        public void process(WatchedEvent event) {
            LockInternals.this.client.postSafeNotify(LockInternals.this);
        }
    };
// 去唤醒当前的进程下处于阻塞的线程
default CompletableFuture<Void> postSafeNotify(Object monitorHolder) {
        return this.runSafe(() -> {
            synchronized(monitorHolder) {
                monitorHolder.notifyAll();
            }
        });
    }

比如说用户服务有个线程去监控,不可能是不断的轮询,没什么意义,那么发现没办法抢占就先阻塞,也就是抢占失败,当前一个节点被删除了之后,会有一个watcher通知,那么就会去唤醒,那么会再次调用这个逻辑,判断是不是最小的,如果是就抢占到了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1272964.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

zookeeper集群和kafka集群

&#xff08;一&#xff09;kafka 1、kafka3.0之前依赖于zookeeper 2、kafka3.0之后不依赖zookeeper&#xff0c;元数据由kafka节点自己管理 &#xff08;二&#xff09;zookeeper 1、zookeeper是一个开源的、分布式的架构&#xff0c;提供协调服务&#xff08;Apache项目&…

CityEngine2023 根据shp数据构建三维模型并导入UE5

目录 0 引言1 基本操作2 实践2.1 导入数据&#xff08;.shp&#xff09;2.2 构建三维模型2.3 将模型导入UE5 &#x1f64b;‍♂️ 作者&#xff1a;海码007&#x1f4dc; 专栏&#xff1a;CityEngine专栏&#x1f4a5; 标题&#xff1a;CityEngine2023 根据shp数据构建三维模型…

零基础学编程系列,看一下具体中文编程代码是什么样子的

零基础学编程系列&#xff0c;看一下具体中文编程代码是什么样子的 上图 编写一个单选的程序 上图 是单选 按钮的中文编程代码 附&#xff1a;中文编程工具构件工具箱总共22组305个构件&#xff0c;构件明细如下&#xff1a; 文本件16个&#xff1a; &#xff08;普通标签&am…

JDK版本降级,如何重新编译打包项目

目前大部分人使用jdk1.8以及更高版本的jdk&#xff0c;在开发过程中也使用了很多jdk1.8的新特性&#xff0c;但或许还存在一些使用jdk低版本的客户&#xff0c;这时如果我们提供的代码涉及必须高版本jdk才能运行的话&#xff0c;那代码就必须降级&#xff0c;客户才能使用&…

Intellij IDEA 的安装和使用以及配置

IDE有很多种&#xff0c;常见的Eclipse、MyEclipse、Intellij IDEA、JBuilder、NetBeans等。但是这些IDE中目前比较火的是Intellij IDEA&#xff08;以下简称IDEA&#xff09;&#xff0c;被众多Java程序员视为最好用的Java集成开发环境&#xff0c;今天的主题就是IDEA为开发工…

.NET开源的处理分布式事务的解决方案

前言 在分布式系统中&#xff0c;由于各个系统服务之间的独立性和网络通信的不确定性&#xff0c;要确保跨系统的事务操作的最终一致性是一项重大的挑战。今天给大家推荐一个.NET开源的处理分布式事务的解决方案基于 .NET Standard 的 C# 库&#xff1a;CAP。 CAP项目介绍 CA…

由于找不到msvcp120.dll的解决方法,msvcp120.dll修复指南

当你尝试运行某些程序或游戏时&#xff0c;可能会遇到系统弹出的错误消息&#xff0c;提示"找不到msvcp120.dll"或"msvcp120.dll丢失"。这种情况通常会妨碍程序的正常启动。为了帮助解决这一问题&#xff0c;本文将深入讨论msvcp120.dll是什么&#xff0c;…

【C++】了解模板

这里是目录 前言函数模板函数模板的实例化类模板 前言 如果我们要交换两个数字&#xff0c;那么我们就需要写一个Swap函数来进行交换&#xff0c;那如果我们要交换char类型的数据呢&#xff1f;那又要写一份Swap的函数重载&#xff0c;参数的两个类型是char&#xff0c;那我们…

【排序,直接插入排序 折半插入排序 希尔插入排序】

文章目录 排序排序方法的分类插入排序直接插入排序折半插入排序希尔插入排序 排序 将一组杂乱无章的数据按照一定规律排列起来。将无序序列排成一个有序序列。 排序方法的分类 储存介质&#xff1a; 内部排序&#xff1a;数据量不大&#xff0c;数据在内存&#xff0c;无需…

【FPGA图像处理】——DDR仲裁、多输入源拼接、旋转任意角度、突发长度修改、任意地址读取。

前言&#xff1a;做FPGA大赛期间遇到的问题&#xff0c;自己coding过程。 包含&#xff1a;hdmi、摄像头等多输入源的拼接&#xff1b;了解DDR以及多种DMA传输方式&#xff0c;修改底层突发长度以及存储位宽&#xff1b;单输入源任意角度旋转&#xff08;无需降低帧率&#xff…

tex2D使用学习

1. 背景&#xff1a; 项目中使用到了纹理进行插值的加速&#xff0c;因此记录一些自己在学习tex2D的一些过程 2. 代码&#xff1a; #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <assert.h> #include <stdio.h>…

XTU OJ 1339 Interprime 学习笔记

链接 传送门 代码 #include<bits/stdc.h> using namespace std;const int N1e610; //78498 我计算了一下&#xff0c;6个0的范围内有这么多个素数&#xff0c;所以开这么大的数组存素数 //计算的代码是一个循环 int prime[80000]; int a[N],s[N];//s数组是前缀和数组b…

自定义链 SNAT / DNAT 实验举例

参考原理图 实验前的环境搭建 1. 准备三台虚拟机&#xff0c;定义为内网&#xff0c;外网以及网卡服务器 2. 给网卡服务器添加网卡 3. 将三台虚拟机的防火墙和安全终端全部关掉 systemctl stop firewalld && setenforce 0 4. 给内网虚拟机和外网虚拟机 yum安装 httpd…

Echarts的引入使用

ECharts文档 1.下载并引入Echarts 2.准备一个具备大小的DOM容器 3.初始化echarts实例对象 4.指定配置项和数据(option) 5.将配置项设置给echarts实例对象 最后是一个js文件 echarts的引入 1.引入echarts - js 文件 <script src"js/echarts.min.js"></scri…

「Linux」使用C语言制作简易Shell

&#x1f4bb;文章目录 &#x1f4c4;前言简易shell实现shell的概念系统环境变量shell的结构定义内建命令完整代码 &#x1f4d3;总结 &#x1f4c4;前言 对于很多学习后端的同学来讲&#xff0c;学习了C语言&#xff0c;发现除了能写出那个经典的“hello world”以外&#xff…

XUbuntu22.04之OBS30.0设置录制音频降噪(一百九十六)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…

LabVIEWL实现鸟巢等大型结构健康监测

LabVIEWL实现鸟巢等大型结构健康监测 管理国家地震防备和减灾的政府机构中国地震局(CEA)选择了七座新建的巨型结构作为结构健康监测(SHM)技术的测试台。这些标志性建筑包括北京2008年夏季奥运会场馆&#xff08;包括北京国家体育场和北京国家游泳中心&#xff09;、上海104层的…

QML学习一、GridView的使用和增加添加动画、删除动画

一、效果预览 二、源码分享 import QtQuick import QtQuick.ControlsApplicationWindow {visible: truewidth: 640height: 480title: "Test"property int cnt:cnt model.countListModel{id:modelListElement{index:0}ListElement{index:1}ListElement{index:2}List…

csapp-linklab之第3阶段“输出学号”实验报告(强弱符号)

题目 新建一个phase3_patch.o&#xff0c;使其与main.o和phase3.o链接后&#xff0c;运行输出自己的学号&#xff1a; $ gcc -o linkbomb main.o phase3.o phase3_patch.o $ ./linkbomb $学号 提示 利用符号解析中的强弱符号规则。&#xff08;COOKIE字符串未初始化&#xff…

单片机AVR单片机病房控制系统设计+源程序

一、系统方案 设计一个可容8张床位的病房呼叫系统。要求每个床位都有一个按钮&#xff0c;当患者需要呼叫护士时&#xff0c;按下按钮&#xff0c;此时护士值班室内的呼叫系统板上显示该患者的床位号&#xff0c;并蜂鸣器报警。当护士按下“响应”键时&#xff0c;结束当前呼叫…