Netty核心技术八--Netty编解码器和handler的调用机制

1.基本说明

  1. netty的组件设计:Netty的主要组件有ChannelEventLoopChannelFuture

    ChannelHandlerChannelPipe等

  2. ChannelHandler充当了处理入站和出站数据的应用程序逻辑的容器。

    例如,实现ChannelInboundHandler接口(或ChannelInboundHandlerAdapter),你就可以接收入站事件和数据,这些数据会被业务逻辑处理。当要给客户端发送响应时,也可以从ChannelInboundHandler冲刷数据。**业务逻辑通常写在一个或者多个ChannelInboundHandler中。**ChannelOutboundHandler原理一样,只不过它是用来处理出站数据的

  3. ChannelPipeline提供了ChannelHandler链的容器以客户端应用程序为例,如果事件的运动方向是从客户端到服务端的,那么我们称这些事件为出站的,即客户端发送给服务端的数据会通过pipeline中的一系列ChannelOutboundHandler,并被这些Handler处理,反之则称为入站的

    image-20230701143140904

2. 编码解码器

  1. 当Netty发送或者接受一个消息的时候,就将会发生一次数据转换。
    • 入站消息会被解码:从字节转换为另一种格式(比如java对象);
    • 如果是出站消息,它会被编码成字节
  2. **Netty提供一系列实用的编解码器,他们都实现了ChannelInboundHadnler或者ChannelOutboundHandler接口。**在这些类中,channelRead方法已经被重写了。
    • 以入站为例,对于每个从入站Channel读取的消息,这个方法会被调用。随后,它将调用由解码器所提供的decode()方法进行解码,并将已经解码的字节转发给ChannelPipeline中的下一个ChannelInboundHandler。

2.1 解码器-ByteToMessageDecoder

  1. 继承关系图

    image-20230701144226731

  2. 由于不可能知道远程节点是否会 一次性发送一个完整的信息, tcp有可能出现粘包拆包的问题, 这个类会对入站数据进行缓冲, 直到它准备好被处理.

  3. 一个关于ByteToMessageDecoder实例分析

    这个例子,**每次入站从ByteBuf中读取4字节,将其解码为一个int,然后将它添加到下一个List中。**当没有更多元素可以被添加到该List中时,它的内容将会被发送给下一个ChannelInboundHandler。int在被添加到List中时,会被自动装箱为Integer。在调用readInt()方法前必须验证所输入的ByteBuf是否具有足够的数据

    public class ToIntegerDecoder extends ByteToMessageDecoder {@Overrideprotected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {if (in.readableBytes() >= 4) {out.add(in.readInt());}}
    }
    

    案例分析:

    image-20230701144910374

    1. 已知一个int4个字节,那我们在解码的时候就需要将4个字节组成一个int然后添加到下一个handler可以读取到的list中
    2. 在执行readInt方法时,ByteBuf中的readerIndex指针会向后移动,所以我们只需要一直读取即可
    3. 同理:

2.2 Netty的handler链的调用机制-实例1

实例要求:

使用自定义的编码器和解码器来 说明Netty的handler 调用机制 客户端发送long -> 服务器 服务端发送long -> 客户端

因为数据是从客户端到服务端,我先从客户端开始写(数据流转比较清除)

2.2.1 MyClient

  • 需要一个MyClientInitializer()
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;/*** @author zr* @date 2023/7/1 16:40*/
public class MyClient {public static void main(String[] args)  throws  Exception{EventLoopGroup group = new NioEventLoopGroup();try {Bootstrap bootstrap = new Bootstrap();bootstrap.group(group).channel(NioSocketChannel.class).handler(new MyClientInitializer()); //自定义一个初始化类ChannelFuture channelFuture = bootstrap.connect("localhost", 8888).sync();channelFuture.channel().closeFuture().sync();}finally {group.shutdownGracefully();}}
}

2.2.2 MyClientInitializer

  1. 因为数据是从客户端到服务器端是出站,所以需要编码,我们需要加入自定义编码器MyLongToByteEncoder
  2. 处理后续业务需要MyClientHandler
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;/*** @author zr* @date 2023/7/1 16:40*/
public class MyClientInitializer extends ChannelInitializer<SocketChannel> {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline = ch.pipeline();//加入一个出站的handler 对数据进行一个编码pipeline.addLast(new MyLongToByteEncoder());//加入一个自定义的handler , 处理业务pipeline.addLast(new MyClientHandler());}
}

2.2.3 MyLongToByteEncoder

  1. 继承MessageToByteEncoder<T>
  2. 重写encode方法来自定义编码方式,将数据编码
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;/*** @author zr* @date 2023/7/1 16:44*/
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {//编码方法@Overrideprotected void encode(ChannelHandlerContext ctx, Long msg, ByteBuf out) throws Exception {System.out.println("MyLongToByteEncoder encode 被调用");System.out.println("msg=" + msg);out.writeLong(msg);}
}

2.2.4 MyClientHandler

这里就是将我们编码的数据在channel激活的时候发送一个long类型的数据到服务端

package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;/*** @author zr* @date 2023/7/1 16:41*/
public class MyClientHandler extends SimpleChannelInboundHandler<Long> {@Overrideprotected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {}//重写channelActive 发送数据@Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {System.out.println("MyClientHandler 发送数据");//ctx.writeAndFlush(Unpooled.copiedBuffer(""))ctx.writeAndFlush(123456L); //发送的是一个long}
}

2.2.5 MyServer

将处理器封装为MyServerInitializer

package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;/*** @author zr* @date 2023/7/1 15:16*/
public class MyServer {public static void main(String[] args) throws InterruptedException {NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);NioEventLoopGroup workerGroup = new NioEventLoopGroup(8);try {ServerBootstrap serverBootstrap = new ServerBootstrap();serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class).childHandler(new MyServerInitializer());ChannelFuture channelFuture = serverBootstrap.bind(8888).sync();channelFuture.channel().closeFuture().sync();}finally {bossGroup.shutdownGracefully();workerGroup.shutdownGracefully();}}
}

2.2.6 MyServerInitializer

  1. 因为数据是从客户端到服务器端是出站,所以需要解码,我们需要加入自定义解码器MyByteToLongDecoder
  2. 处理后续业务需要MyServerHandler
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;/*** @author zr* @date 2023/7/1 15:21*/
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline = ch.pipeline();//一会下断点//入站的handler进行解码 MyByteToLongDecoderpipeline.addLast(new MyByteToLongDecoder());//自定义的handler 处理业务逻辑pipeline.addLast(new MyServerHandler());System.out.println("xx");}
}

2.2.7 MyByteToLongDecoder

  1. 继承ByteToMessageDecoder
  2. 重写decode方法来自定义解码方式,将数据解码
  3. decode 会根据接收的数据,被调用多次, 直到确定没有新的元素被添加到list或者是ByteBuf 没有更多的可读字节为止
  4. 如果list out 不为空,就会将list的内容传递给下一个 channelinboundhandler处理, 该处理器的方法也会被调用多次
  5. 参数说明:
    • ctx:上下文对象
    • in: 入站的 ByteBuf
    • out:List 集合,将解码后的数据传给下一个handler
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import io.netty.handler.codec.ByteToMessageDecoder;import java.util.List;/*** @author zr* @date 2023/7/1 16:36*/
public class MyByteToLongDecoder extends ByteToMessageDecoder {/**** decode 会根据接收的数据,被调用多次, 直到确定没有新的元素被添加到list* , 或者是ByteBuf 没有更多的可读字节为止* 如果list out 不为空,就会将list的内容传递给下一个 channelinboundhandler处理, 该处理器的方法也会被调用多次** @param ctx 上下文对象* @param in 入站的 ByteBuf* @param out List 集合,将解码后的数据传给下一个handler* @throws Exception*/@Overrideprotected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {System.out.println("MyByteToLongDecoder 被调用");//因为 long 8个字节, 需要判断有8个字节,才能读取一个longif (in.readableBytes()>=8){out.add(in.readLong());}}
}

2.2.8 MyServerHandler

  1. MyByteToLongDecoder解码的数据会传到下一个handler,那么数据类型就确定了所以SimpleChannelInboundHandler<Long>
  2. 将数据打印到控制台
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;/*** @author zr* @date 2023/7/1 16:34*/
public class MyServerHandler extends SimpleChannelInboundHandler<Long> {@Overrideprotected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {System.out.println("从客户端" + ctx.channel().remoteAddress() + " 读取到long " + msg);}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {cause.printStackTrace();ctx.close();}
}

2.2.9 测试

  1. 启动服务端

    image-20230701170558556

  2. 启动客户端

    image-20230701170620726

    image-20230701170634222

编码器和解码器都被调用,服务端拿到客户端编码后的数据解码后输出成功

2.2.10 特殊情况测试-发送数据与与编解码器的类型不一致

当我们客户端发送的数据为一个16个字节的字符串的时候会发生什么情况?

package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;/*** @author zr* @date 2023/7/1 16:41*/
public class MyClientHandler extends SimpleChannelInboundHandler<Long> {@Overrideprotected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {}//重写channelActive 发送数据@Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {System.out.println("MyClientHandler 发送数据");//ctx.writeAndFlush(Unpooled.copiedBuffer(""))
//        ctx.writeAndFlush(123456L); //发送的是一个long//分析//1. "abcdabcdabcdabcd" 是 16个字节//2. 该处理器的前一个handler 是  MyLongToByteEncoder//3. MyLongToByteEncoder 父类  MessageToByteEncoder//4. 父类  MessageToByteEncoder/*public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {ByteBuf buf = null;try {if (acceptOutboundMessage(msg)) { //判断当前msg 是不是应该处理的类型,如果是就处理,不是就跳过encode@SuppressWarnings("unchecked")I cast = (I) msg;buf = allocateBuffer(ctx, cast, preferDirect);try {encode(ctx, cast, buf);} finally {ReferenceCountUtil.release(cast);}if (buf.isReadable()) {ctx.write(buf, promise);} else {buf.release();ctx.write(Unpooled.EMPTY_BUFFER, promise);}buf = null;} else {ctx.write(msg, promise);}}4. 因此我们编写 Encoder 是要注意传入的数据类型和处理的数据类型一致*/ctx.writeAndFlush(Unpooled.copiedBuffer("abcdabcdabcdabcd", CharsetUtil.UTF_8));}
}
  1. 启动服务端

    image-20230701171859900

  2. 启动客户端

    image-20230701171926115

    image-20230701171938680

  • 服务端输出了两次MyByteToLongDecoder 被调用代表MyByteToLongDecoder的decode方法被调用了两次

    1. decode 会根据接收的数据,被调用多次, 直到确定没有新的元素被添加到list或者是ByteBuf 没有更多的可读字节为止
    2. 如果list out 不为空,就会将list的内容传递给下一个 channelinboundhandler处理, 该处理器的方法也会被调用多次
  • 我们发现没有客户端没有打印MyLongToByteEncoder 被调用,代表MyLongToByteEncoder的encode方法没有被调用

    image-20230701172633093

2.3 Netty的handler链的调用机制-实例2

实例要求:

  • 使用自定义的编码器和解码器来 说明Netty的handler 调用机制 客户端发送long -> 服务器 服务端发送long -> 客户端

    image-20230701174422543

实现图

image-20230701174601262

实例1已经实现客户端向服务端发送数据,我们只需要在示例1的基础上在服务端打印客户端发送的数据的同时发送编码数据,然后客户端在解码读取数据即可

2.3.1 MyServerInitializer

加上编码器

image-20230701175712684

2.3.2 MyServerHandler

发送数据

image-20230701175759225


2.3.3 MyClientInitializer

客户端加上解码器

image-20230701175843496

2.3.4 MyClientHandler

打印数据

image-20230701175910802

2.3.5 测试

  1. 启动服务端

    image-20230701180041752

  2. 启动客户端

    image-20230701180100543

    image-20230701180113276

服务端也成功接收到了数据

  • 结论:
    • 不论解码器handler 还是 编码器handler 即接 收的消息类型必须与待处理的消息类型一致, 否则该handler不会被执行
    • 在解码器 进行数据解码时,需要判断 缓存 区(ByteBuf)的数据是否足够,否则接收到的结果会和期望结果可能不一致

2.2.6 调用链debug

  1. 为了方便查看handler,最好起一个名字

    image-20230701182649511

  2. 启动服务端和客户端,代码走到断点查看head为整个调用链的(pipeline)的头结点

    image-20230701182840166

  3. 点击next查看下一个handler,是我们的MyServerInitializer

    image-20230701182951165

  4. 点击next查看下一个handler,是我们的MyByteToLongDecoder

    image-20230701183035091

  5. 点击next查看下一个handler,是我们的MyLongToByteEncoder

    image-20230701183118118

  6. 点击next查看下一个handler,是我们的MyServerHandler

    image-20230701183149070

  7. 点击next查看下一个handler,这是netty的默认尾节点next已经为空了

    image-20230701183225481

第四步和第五步只会执行一个,因为他们继承的父类不同出入站,出站和入站只会执行对应的一个

3. 解码器-ReplayingDecoder

  1. public abstract class ReplayingDecoder extends ByteToMessageDecoder
  2. ReplayingDecoder扩展了ByteToMessageDecoder类,使用这个类,我们不必调用readableBytes()方法参数S指定了用户状态管理的类型,其中Void代表不需要状态管理(由ByteToMessageDecoder来帮我们自动识别并管理)
  3. ReplayingDecoder使用方便,但它也有一些局限性:
    • 并不是所有的 ByteBuf 操作都被支持,如果调用了一个不被支持的方法,将会抛出一个UnsupportedOperationException
    • ReplayingDecoder 在某些情况下可能稍慢于 ByteToMessageDecoder,例如网络缓慢并且消息格式复杂时,消息会被拆成了多个碎片,速度变慢

3.1 应用实例

3.1.1 MyByteToLongDecoder2

  • ReplayingDecoder<Void>代表没有指定类型,ReplayingDecoder来帮我们识别并管理
  • 读取数据的时候也不需要判断数据是否足够读取,内部会进行处理判断
package site.zhourui.nioAndNetty.netty.inboundhandlerandoutboundhandler;import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;import java.util.List;public class MyByteToLongDecoder2 extends ReplayingDecoder<Void> {@Overrideprotected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {System.out.println("MyByteToLongDecoder2 被调用");//在 ReplayingDecoder 不需要判断数据是否足够读取,内部会进行处理判断out.add(in.readLong());}
}

3.1.2 将实例2中的MyByteToLongDecoder替换为MyByteToLongDecoder2

MyClientInitializer

image-20230702103638354

MyServerInitializer

image-20230702103710988

3.1.3 测试

image-20230702103813374

image-20230702103830587

仍然能实现实例2的功能

4. 其它编解码器

4.1 LineBasedFrameDecoder

这个类在Netty内部也有使用,它使用行尾控制字符(\n或者\r\n)作为分隔符来解析数据。

4.2 DelimiterBasedFrameDecoder

使用自定义的特殊字符作为消息的分隔符。

4.3 HttpObjectDecoder

一个HTTP数据的解码器,之前的笔记中使用过

4.4 LengthFieldBasedFrameDecoder

通过指定长度来标识整包消息,这样就可以自动的处理黏包和半包消息。

5. Log4j 整合到Netty

  1. 在Maven 中添加对Log4j的依赖 在 pom.xml

          <dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.25</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.25</version><scope>test</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId><version>1.7.25</version><scope>test</scope></dependency>
    
  2. 配置 Log4j , 在 resources/log4j.properties

    log4j.rootLogger=DEBUG, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[%p] %C{1} - %m%n
    
  3. 随便启动一个服务

    image-20230702104506403

为了方便以后学习查看控制台清楚一点可以先关闭日志功能

把步骤2和步骤2的内容注释掉,当然你需要日志功能也可以打开

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2023 中兴捧月算法挑战赛-自智网络-参赛总结

“中兴捧月”是由中兴通讯面向在校大学生举办的全球性系列赛事活动&#xff0c;致力于培养学生建模编程、创新、方案策划和团队合作能力。今年是在学校的宣传下了解到比赛&#xff0c;最初抱着学习的态度报名了比赛&#xff0c;最终进入了决赛&#xff0c;完成了封闭的开发与赛…

mysql行数据转为列数据

最近在开发过程中遇到问题&#xff0c;需要将数据库中一张表信息进行行转列操作&#xff0c;再将每列&#xff08;即每个字段&#xff09;作为与其他表进行联表查询的字段进行显示。 借此机会&#xff0c;在网上查阅了相关方法&#xff0c;现总结出一种比较简单易懂的方法备用…

Qt弱加密漏洞分析

0x00 漏洞背景 Qt是一个跨平台的C应用程序开发框架&#xff0c;用于创建图形用户界面&#xff08;GUI&#xff09;应用程序、命令行工具、嵌入式系统和网络应用等各种类型的应用。 Qt框架包含的Qt Network&#xff08;网络模块&#xff09;&#xff0c;提供了QNetworkAccessM…

抖音本地生活团购软件开发

抖音本地生活团购软件开发需要考虑以下几个方面&#xff1a; 功能设计&#xff1a;根据本地生活团购服务特点&#xff0c;设计相应的功能模块&#xff0c;如商家入驻、商品展示、订单管理、支付等。 技术选型&#xff1a;选择适合该项目的技术和框架&#xff0c;如移动…

RabbitMq应用延时消息

一.建立绑定关系 package com.lx.mq.bind;import com.lx.constant.MonitorEventConst; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annota…

【计算机网络】可靠传输的实现机制

参考视频 https://www.bilibili.com/video/BV1c4411d7jb 1、停止-等待协议SW (Stop-and-Wait) 1.1 信道利用率 1.2 题目 1.3 小结 2.回退N帧协议GBN (Go-Back-N) 1.1 题目 1.2 小结 3.选择重传协议SR (Selective-Repeat) 3.1 过程 3.2 发送窗口 和 接收窗口尺寸范围 4.小结 5.…

MATLAB 之 Simulink系统的仿真与分析

这里写目录标题 一、Simulink 系统的仿真与分析1. 设置仿真参数1.1 Solver 参数设置1.2 Data lmport/Export 参数设置 2. 运行仿真与仿真结果分析2.1 运行仿真2.2 仿真结果分析 一、Simulink 系统的仿真与分析 系统的模型建立之后&#xff0c;选择仿真参数和数值算法&#xff…

ModaHub魔搭社区:向量数据库Milvus性能调优教程(一)

目录 性能调优 插入性能调优 查询性能调优 硬件环境 系统参数 性能调优 插入性能调优 “数据插入”到“数据写入磁盘”的基本流程请参考 存储操作。 如果数据量小于单次插入上限&#xff08;256 MB&#xff09;&#xff0c;批量插入比单条插入要高效得多。 系统配置中…

three.js点材质(PointsMaterial)常用属性设置

一、前景回顾 上一章节简单介绍了下怎么使用点材质和点对象创建物体点对象和点材质介绍 点材质和点对象基本运用示例代码&#xff1a; import * as THREE from "three"; // 导入轨道控制器 import { OrbitControls } from "three/examples/jsm/controls/Orbit…

沉浸式三维虚拟展厅交互体验科技感十足

随着科技的不断发展进步&#xff0c;展厅的表现形式也变得多样化&#xff0c;紧跟时代发展步伐&#xff0c;迭代创新。 3D虚拟展厅具有四大优势 一、降低成本&#xff0c;提高效率 3D“VR线上展厅”将艺术优势资源转到线上搭建的艺术线上展平台&#xff0c;相对传统艺术展来说有…

基于redis的bitmap实现签到功能(后端)

项目环境 MacOS springboot: 2.7.12 JDK 11 maven 3.8.6 redis 7.0.11 StringRedisTemplate 的key和value默认都是String类型 可以避免不用写配置类&#xff0c;定义key和value的序列化。 实现逻辑&#xff1a; 获取用户登录信息 根据日期获取当天是多少号 构建…

Cetos7.x连接不上网络解决办法

Cetos7.x连接不上网络解决办法 Cetos7.x连接不上网络解决办法 在VM中设置网络连接为桥接&#xff0c;修改后仍无法连接网络 ##配置centos7中ens33&#xff0c;将默认的no修改为yes 启动CentOS系统&#xff0c;并打开一个连接终端会话&#xff0c;使用root登录&#xff1b;进…