修改内容
This commit is contained in:
parent
bfc862fec8
commit
ff705416ed
|
@ -0,0 +1,182 @@
|
||||||
|
CentOS 9 Stream
|
||||||
|
|
||||||
|
yum配置文件路径
|
||||||
|
|
||||||
|
```
|
||||||
|
/etc/yum.repos.d/centos.repo
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
备份源配置
|
||||||
|
|
||||||
|
```
|
||||||
|
mv /etc/yum.repos.d/centos.repo /etc/yum.repos.d/centos.repo.backup
|
||||||
|
```
|
||||||
|
|
||||||
|
阿里源配置
|
||||||
|
|
||||||
|
```
|
||||||
|
# CentOS-Base.repo
|
||||||
|
#
|
||||||
|
# The mirror system uses the connecting IP address of the client and the
|
||||||
|
# update status of each mirror to pick mirrors that are updated to and
|
||||||
|
# geographically close to the client. You should use this for CentOS updates
|
||||||
|
# unless you are manually picking other mirrors.
|
||||||
|
#
|
||||||
|
# If the mirrorlist= does not work for you, as a fall back you can try the
|
||||||
|
# remarked out baseurl= line instead.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
[base]
|
||||||
|
name=CentOS-$releasever - Base - mirrors.aliyun.com
|
||||||
|
#failovermethod=priority
|
||||||
|
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/os/
|
||||||
|
http://mirrors.aliyuncs.com/centos-stream/$stream/BaseOS/$basearch/os/
|
||||||
|
http://mirrors.cloud.aliyuncs.com/centos-stream/$stream/BaseOS/$basearch/os/
|
||||||
|
gpgcheck=1
|
||||||
|
gpgkey=https://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
|
||||||
|
|
||||||
|
#additional packages that may be useful
|
||||||
|
#[extras]
|
||||||
|
#name=CentOS-$releasever - Extras - mirrors.aliyun.com
|
||||||
|
#failovermethod=priority
|
||||||
|
#baseurl=https://mirrors.aliyun.com/centos-stream/$stream/extras/$basearch/os/
|
||||||
|
# http://mirrors.aliyuncs.com/centos-stream/$stream/extras/$basearch/os/
|
||||||
|
# http://mirrors.cloud.aliyuncs.com/centos-stream/$stream/extras/$basearch/os/
|
||||||
|
#gpgcheck=1
|
||||||
|
#gpgkey=https://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
|
||||||
|
|
||||||
|
#additional packages that extend functionality of existing packages
|
||||||
|
[centosplus]
|
||||||
|
name=CentOS-$releasever - Plus - mirrors.aliyun.com
|
||||||
|
#failovermethod=priority
|
||||||
|
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/centosplus/$basearch/os/
|
||||||
|
http://mirrors.aliyuncs.com/centos-stream/$stream/centosplus/$basearch/os/
|
||||||
|
http://mirrors.cloud.aliyuncs.com/centos-stream/$stream/centosplus/$basearch/os/
|
||||||
|
gpgcheck=1
|
||||||
|
enabled=0
|
||||||
|
gpgkey=https://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
|
||||||
|
|
||||||
|
[PowerTools]
|
||||||
|
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
|
||||||
|
#failovermethod=priority
|
||||||
|
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/PowerTools/$basearch/os/
|
||||||
|
http://mirrors.aliyuncs.com/centos-stream/$stream/PowerTools/$basearch/os/
|
||||||
|
http://mirrors.cloud.aliyuncs.com/centos-stream/$stream/PowerTools/$basearch/os/
|
||||||
|
gpgcheck=1
|
||||||
|
enabled=0
|
||||||
|
gpgkey=https://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
|
||||||
|
|
||||||
|
|
||||||
|
[AppStream]
|
||||||
|
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
|
||||||
|
#failovermethod=priority
|
||||||
|
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/os/
|
||||||
|
http://mirrors.aliyuncs.com/centos-stream/$stream/AppStream/$basearch/os/
|
||||||
|
http://mirrors.cloud.aliyuncs.com/centos-stream/$stream/AppStream/$basearch/os/
|
||||||
|
gpgcheck=1
|
||||||
|
gpgkey=https://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[baseos]
|
||||||
|
name=CentOS Stream $releasever - BaseOS
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/os
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
countme=1
|
||||||
|
enabled=1
|
||||||
|
|
||||||
|
[baseos-debuginfo]
|
||||||
|
name=CentOS Stream $releasever - BaseOS - Debug
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/debug/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-debug-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
|
||||||
|
[baseos-source]
|
||||||
|
name=CentOS Stream $releasever - BaseOS - Source
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/source/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-source-$stream&arch=source&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
|
||||||
|
[appstream]
|
||||||
|
name=CentOS Stream $releasever - AppStream
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/os
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
countme=1
|
||||||
|
enabled=1
|
||||||
|
|
||||||
|
[appstream-debuginfo]
|
||||||
|
name=CentOS Stream $releasever - AppStream - Debug
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/debug/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-debug-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
|
||||||
|
[appstream-source]
|
||||||
|
name=CentOS Stream $releasever - AppStream - Source
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/source/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-source-$stream&arch=source&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
|
||||||
|
[crb]
|
||||||
|
name=CentOS Stream $releasever - CRB
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/os
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
countme=1
|
||||||
|
enabled=1
|
||||||
|
|
||||||
|
[crb-debuginfo]
|
||||||
|
name=CentOS Stream $releasever - CRB - Debug
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/debug/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-debug-$stream&arch=$basearch&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
|
||||||
|
[crb-source]
|
||||||
|
name=CentOS Stream $releasever - CRB - Source
|
||||||
|
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/source/tree/
|
||||||
|
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-source-$stream&arch=source&protocol=https,http
|
||||||
|
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
|
||||||
|
gpgcheck=1
|
||||||
|
repo_gpgcheck=0
|
||||||
|
metadata_expire=6h
|
||||||
|
enabled=0
|
||||||
|
```
|
||||||
|
|
||||||
|
更新缓存
|
||||||
|
|
||||||
|
```
|
||||||
|
yum makecache && yum update
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,321 @@
|
||||||
|
# ProtoBuf简明教程
|
||||||
|
|
||||||
|
## 1.什么是Protobuf
|
||||||
|
|
||||||
|
Protobuf 是一个无关语言,无关平台的,用于序列化结构 化数据的工具。相较于JSON体积更小,传输更快。
|
||||||
|
Protobuf 定义在,proto文件中,在特定语言进行编译时,进行动态编译。
|
||||||
|
|
||||||
|
1. 序列化:将数据结构转换为字节流,便于网络传输和存储。
|
||||||
|
2. 高效性:相比于JSON,Protobuf 序列化后的字节流更小,传输更快。
|
||||||
|
3. 兼容性:Protobuf 支持多种语言,使得数据在不同语言之间进行通信和交互更加方便。
|
||||||
|
4. 可读性:Protobuf 的定义文件是纯文本
|
||||||
|
|
||||||
|
## 2.主要应用场景
|
||||||
|
|
||||||
|
1. 网络通信:Protobuf 适用于网络通信场景,例如在分布式系统中进行数据传输和通信。
|
||||||
|
2. 数据存储:Protobuf 可以将数据结构存储在文件或数据库中,使得数据的存储和检索更加高效。
|
||||||
|
3. 配置文件:Protobuf 可以用于存储和传输配置信息,例如应用程序的配置参数。
|
||||||
|
|
||||||
|
## 3.Java中使用
|
||||||
|
|
||||||
|
创建一个Maven项目其中使用 Java 作为 Client 端,Python 作为 Server 端
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>4.27.2</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
在项目中创建文件夹 `script` 在其下创建 Protobuf 文件 `video_info.proto`
|
||||||
|
|
||||||
|
其中内容如下
|
||||||
|
|
||||||
|
```protobuf
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
message VideoFeature {
|
||||||
|
optional int32 author_gender = 1 ;
|
||||||
|
optional int64 channel_id = 2;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
然后导入对应的 `protoc` 工程文件,[下载对应版本的文件](https://github.com/protocolbuffers/protobuf/releases/tag/v27.2)
|
||||||
|
并解压到`script`目录下
|
||||||
|
|
||||||
|
然后创建一个生成脚本 `build_pb.sh`内容如下
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/bash
|
||||||
|
SRC_DIR="."
|
||||||
|
JAVA_DST_DIR="../src/main/java"
|
||||||
|
PYTHON_DST_DIR="../src/main/python"
|
||||||
|
|
||||||
|
./protoc-27.2-osx-aarch_64/bin/protoc -I=$SRC_DIR --java_out=$JAVA_DST_DIR $SRC_DIR/AllTypes.proto
|
||||||
|
./protoc-27.2-osx-aarch_64/bin/protoc -I=$SRC_DIR --python_out=$PYTHON_DST_DIR $SRC_DIR/AllTypes.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
其中最后面的文件名是上面创建的`proto`文件的名称,运行sh脚本
|
||||||
|
|
||||||
|
能够生成两个文件 `VideoInfo.java` `video_info_pb2.py`
|
||||||
|
|
||||||
|
然后我们创建两个运行文件 `Client.java` `Server.py`,其中内容如下
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: Client
|
||||||
|
* Package: com.yovinchen.protobuf
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @since 2024/7/25 上午9:33
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Client {
|
||||||
|
|
||||||
|
public static byte[] msg;
|
||||||
|
|
||||||
|
static {
|
||||||
|
VideoInfo.VideoFeature feature = VideoInfo.VideoFeature.newBuilder()
|
||||||
|
.setAuthorGender(123)
|
||||||
|
.setChannelId(321)
|
||||||
|
.build();
|
||||||
|
msg = feature.toByteArray();
|
||||||
|
|
||||||
|
// msg = "测试字符串".getBytes();
|
||||||
|
// msg = "{\"author_gender\":123,\"channel_id\":321}".getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
System.out.println("客户端启动...");
|
||||||
|
// 创建一个流套接字并将其连接到指定主机上的指定端口号
|
||||||
|
Socket socket = new Socket("localhost", 8001);
|
||||||
|
// 向服务器端发送数据
|
||||||
|
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
||||||
|
out.write(msg);
|
||||||
|
out.close();
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
import socket
|
||||||
|
|
||||||
|
import video_info_pb2
|
||||||
|
|
||||||
|
|
||||||
|
def parse(buf):
|
||||||
|
try:
|
||||||
|
video_feature = video_info_pb2.VideoFeature()
|
||||||
|
video_feature.ParseFromString(buf)
|
||||||
|
return video_feature
|
||||||
|
except Exception:
|
||||||
|
return "暂时不支持转换"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("Server is starting")
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.bind(('localhost', 8001)) # 配置soket,绑定IP地址和端口号
|
||||||
|
sock.listen(5) # 设置最大允许连接数
|
||||||
|
while True: # 循环轮询socket状态,等待访问
|
||||||
|
connection, address = sock.accept()
|
||||||
|
buf = connection.recv(1024)
|
||||||
|
print(f"原始数据:{buf}")
|
||||||
|
print(f"数据长度:{len(buf)}")
|
||||||
|
|
||||||
|
print(parse(buf))
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
然后先运行 `Server.py` 然后再运行 `Client.java`,然后就能在Server看到原始数据以及解析出来的数据。
|
||||||
|
|
||||||
|
解除`msg`中的注释测试`Json`进行数据传输的数据长度
|
||||||
|
|
||||||
|
![image-20240729103528251](https://lsky.hhdxw.top/imghub/2024/07/image-202407291722220767.png)
|
||||||
|
|
||||||
|
## 4.测试
|
||||||
|
|
||||||
|
```protobuf
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
// 定义一个消息,该消息包含所有基本的数据类型。
|
||||||
|
message AllTypes {
|
||||||
|
// 布尔类型
|
||||||
|
bool bool_field = 1; // 布尔值
|
||||||
|
|
||||||
|
// 字符串类型
|
||||||
|
string string_field = 2; // UTF-8 编码的字符串
|
||||||
|
|
||||||
|
// 字节流类型
|
||||||
|
bytes bytes_field = 3; // 原始字节流
|
||||||
|
|
||||||
|
// 整数类型
|
||||||
|
int32 int32_field = 4; // 32位有符号整数
|
||||||
|
int64 int64_field = 5; // 64位有符号整数
|
||||||
|
uint32 uint32_field = 6; // 32位无符号整数
|
||||||
|
uint64 uint64_field = 7; // 64位无符号整数
|
||||||
|
sint32 sint32_field = 8; // 32位有符号整数,使用 zigzag 编码
|
||||||
|
sint64 sint64_field = 9; // 64位有符号整数,使用 zigzag 编码
|
||||||
|
|
||||||
|
// 浮点数类型
|
||||||
|
float float_field = 14; // 单精度浮点数
|
||||||
|
double double_field = 15; // 双精度浮点数
|
||||||
|
|
||||||
|
// 固定宽度整数类型
|
||||||
|
fixed32 fixed32_field = 10; // 32位无符号整数,小端存储
|
||||||
|
fixed64 fixed64_field = 11; // 64位无符号整数,小端存储
|
||||||
|
sfixed32 sfixed32_field = 12; // 32位有符号整数,小端存储
|
||||||
|
sfixed64 sfixed64_field = 13; // 64位有符号整数,小端存储
|
||||||
|
|
||||||
|
// 重复字段类型
|
||||||
|
repeated int32 repeated_int32_field = 31; // 可以包含多个元素的 int32 字段
|
||||||
|
|
||||||
|
// 映射字段类型
|
||||||
|
map<int32, string> map_int32_string_field = 32; // 键为 int32,值为 string 的映射
|
||||||
|
|
||||||
|
// 枚举类型
|
||||||
|
EnumType enum_field = 33; // 枚举类型字段
|
||||||
|
|
||||||
|
// 嵌套消息类型
|
||||||
|
MessageType nested_message_field = 34; // 另一个消息类型的字段
|
||||||
|
|
||||||
|
// 嵌套的消息类型定义
|
||||||
|
message MessageType {
|
||||||
|
string nested_string_field = 1; // 嵌套消息中的字符串字段
|
||||||
|
}
|
||||||
|
|
||||||
|
// 枚举类型定义
|
||||||
|
enum EnumType {
|
||||||
|
ENUM_VALUE_0 = 0; // 枚举值 0
|
||||||
|
ENUM_VALUE_1 = 1; // 枚举值 1
|
||||||
|
ENUM_VALUE_2 = 2; // 枚举值 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 以下是用于包装基本类型的特殊消息类型,它们允许携带额外的元数据,如 null 值。
|
||||||
|
message BoolValue {bool value = 1;} // 包装布尔值
|
||||||
|
message StringValue {string value = 1;} // 包装字符串值
|
||||||
|
message BytesValue {bytes value = 1;} // 包装字节流值
|
||||||
|
message Int32Value {int32 value = 1;} // 包装 32 位整数值
|
||||||
|
message Int64Value {int64 value = 1;} // 包装 64 位整数值
|
||||||
|
message UInt32Value {uint32 value = 1;} // 包装无符号 32 位整数值
|
||||||
|
message UInt64Value {uint64 value = 1;} // 包装无符号 64 位整数值
|
||||||
|
message SInt32Value {sint32 value = 1;} // 包装 zigzag 编码的 32 位整数值
|
||||||
|
message SInt64Value {sint64 value = 1;} // 包装 zigzag 编码的 64 位整数值
|
||||||
|
message Fixed32Value {fixed32 value = 1;} // 包装小端存储的 32 位整数值
|
||||||
|
message Fixed64Value {fixed64 value = 1;} // 包装小端存储的 64 位整数值
|
||||||
|
message SFixed32Value {sfixed32 value = 1;} // 包装小端存储的 32 位有符号整数值
|
||||||
|
message SFixed64Value {sfixed64 value = 1;} // 包装小端存储的 64 位有符号整数值
|
||||||
|
message FloatValue {float value = 1;} // 包装单精度浮点数值
|
||||||
|
message DoubleValue {double value = 1;} // 包装双精度浮点数值
|
||||||
|
```
|
||||||
|
|
||||||
|
服务端和接收端`AllTypesClient.java` `AllTypeServer.py`
|
||||||
|
|
||||||
|
```java
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: Client
|
||||||
|
* Package: com.yovinchen.protobuf
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @since 2024/7/25 上午9:33
|
||||||
|
*/
|
||||||
|
public class AllTypesClient {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
System.out.println("客户端启动...");
|
||||||
|
|
||||||
|
// 创建一个 AllTypes 消息实例
|
||||||
|
AllTypesOuterClass.AllTypes.Builder builder = AllTypesOuterClass.AllTypes.newBuilder();
|
||||||
|
builder.setBoolField(true);
|
||||||
|
builder.setStringField("测试字符串");
|
||||||
|
builder.setBytesField(ByteString.copyFromUtf8("字节流"));
|
||||||
|
builder.setInt32Field(123);
|
||||||
|
builder.setInt64Field(123L);
|
||||||
|
builder.setUint32Field(456);
|
||||||
|
builder.setUint64Field(456L);
|
||||||
|
builder.setSint32Field(-123);
|
||||||
|
builder.setSint64Field(-123L);
|
||||||
|
builder.setFixed32Field(123);
|
||||||
|
builder.setFixed64Field(123L);
|
||||||
|
builder.setSfixed32Field(-123);
|
||||||
|
builder.setSfixed64Field(-123L);
|
||||||
|
builder.setFloatField(123.45f);
|
||||||
|
builder.setDoubleField(123.45);
|
||||||
|
builder.addRepeatedInt32Field(1);
|
||||||
|
builder.addRepeatedInt32Field(2);
|
||||||
|
builder.putMapInt32StringField(1, "value1");
|
||||||
|
builder.putMapInt32StringField(2, "value2");
|
||||||
|
builder.setEnumField(AllTypesOuterClass.AllTypes.EnumType.ENUM_VALUE_1);
|
||||||
|
builder.setNestedMessageField(AllTypesOuterClass.AllTypes.MessageType.newBuilder()
|
||||||
|
.setNestedStringField("嵌套字符串")
|
||||||
|
.build());
|
||||||
|
|
||||||
|
// 构建消息
|
||||||
|
AllTypesOuterClass.AllTypes allTypesMsg = builder.build();
|
||||||
|
|
||||||
|
// 创建一个流套接字并将其连接到指定主机上的指定端口号
|
||||||
|
Socket socket = new Socket("localhost", 8001);
|
||||||
|
|
||||||
|
// 向服务器端发送数据
|
||||||
|
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
||||||
|
out.write(allTypesMsg.toByteArray());
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
import socket
|
||||||
|
|
||||||
|
import AllTypes_pb2
|
||||||
|
|
||||||
|
|
||||||
|
def parse(buf):
|
||||||
|
try:
|
||||||
|
all_types_msg = AllTypes_pb2.AllTypes() # 创建 AllTypes 消息实例
|
||||||
|
all_types_msg.ParseFromString(buf) # 从字节流中解析消息
|
||||||
|
return all_types_msg # 返回解析后的消息实例
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error parsing message: {e}")
|
||||||
|
return None # 如果解析失败,返回 None 或者自定义的错误信息
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("Server is starting")
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.bind(('localhost', 8001))
|
||||||
|
sock.listen(5)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
connection, address = sock.accept()
|
||||||
|
buf = connection.recv(1024)
|
||||||
|
print(f"原始数据: {buf}")
|
||||||
|
print(f"数据长度:{len(buf)}")
|
||||||
|
|
||||||
|
parsed_msg = parse(buf)
|
||||||
|
if parsed_msg is not None:
|
||||||
|
print(parsed_msg) # 输出解析后的消息
|
||||||
|
else:
|
||||||
|
print("无法解析消息")
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
![image-20240729103332905](https://lsky.hhdxw.top/imghub/2024/07/image-202407291722220780.png)
|
|
@ -199,8 +199,8 @@ redis-cli --cluster reshard <host>:<port> --cluster-from <arg> --cluster-to <arg
|
||||||
**参数**:
|
**参数**:
|
||||||
|
|
||||||
- `host:port`: 集群中任意一个节点的地址。
|
- `host:port`: 集群中任意一个节点的地址。
|
||||||
- `--cluster-from <arg>`: 指定源节点。
|
- `--cluster-from <arg>`: 指定源节点IP。
|
||||||
- `--cluster-to <arg>`: 指定目标节点。
|
- `--cluster-to <arg>`: 指定目标节点IP。
|
||||||
- `--cluster-slots <arg>`: 指定需要迁移的槽数。
|
- `--cluster-slots <arg>`: 指定需要迁移的槽数。
|
||||||
- `--cluster-yes`: 自动确认操作。
|
- `--cluster-yes`: 自动确认操作。
|
||||||
- `--cluster-timeout <arg>`: 设置操作超时时间。
|
- `--cluster-timeout <arg>`: 设置操作超时时间。
|
||||||
|
@ -212,7 +212,7 @@ redis-cli --cluster reshard <host>:<port> --cluster-from <arg> --cluster-to <arg
|
||||||
将槽从节点127.0.0.1:7000移动到节点127.0.0.1:7001。
|
将槽从节点127.0.0.1:7000移动到节点127.0.0.1:7001。
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
redis-cli --cluster reshard 127.0.0.1:7000 --cluster-from 127.0.0.1:7000 --cluster-to 127.0.0.1:7001 --cluster-slots 5 --cluster-yes
|
redis-cli --cluster reshard 127.0.0.1:7000 --cluster-from 17e7723239cbc85133bc5f89f24cc0e600bb9eb0 --cluster-to a8ee09617d7c526c9870f5d34b09c52e23f4b9f1 --cluster-slots 5 --cluster-yes
|
||||||
```
|
```
|
||||||
|
|
||||||
### 6.重新平衡
|
### 6.重新平衡
|
||||||
|
|
|
@ -0,0 +1,158 @@
|
||||||
|
单选题考了简单的代码输出和linux命令
|
||||||
|
|
||||||
|
不定项考了线程、抽象类、接口、唯一索引还有Math的函数
|
||||||
|
|
||||||
|
算法题,相对来说比较简单
|
||||||
|
|
||||||
|
(1)一道点菜的题
|
||||||
|
https://www.luogu.com.cn/problem/P1164
|
||||||
|
|
||||||
|
```C++
|
||||||
|
#include<iostream>
|
||||||
|
#include<cstring>
|
||||||
|
#include<algorithm>
|
||||||
|
using namespace std;
|
||||||
|
int a[101],f[101][10001]={0};
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,m;
|
||||||
|
cin>>n>>m;
|
||||||
|
for(int i=1;i<=n;++i)cin>>a[i];
|
||||||
|
for(int i=1;i<=n;++i)
|
||||||
|
for(int j=1;j<=m;++j)
|
||||||
|
{
|
||||||
|
if(j==a[i])f[i][j]=f[i-1][j]+1;
|
||||||
|
if(j>a[i]) f[i][j]=f[i-1][j]+f[i-1][j-a[i]];
|
||||||
|
if(j<a[i]) f[i][j]=f[i-1][j];
|
||||||
|
}
|
||||||
|
cout<<f[n][m];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(2)求从1到n中输出和为m的所有可能
|
||||||
|
https://www.nowcoder.com/questionTerminal/11cc498832db489786f8a03c3b67d02c
|
||||||
|
|
||||||
|
```C++
|
||||||
|
#include<iostream>
|
||||||
|
#include<vector>
|
||||||
|
using namespace std;
|
||||||
|
void help(int n, int m, vector<int>& v, int beg) {
|
||||||
|
//if (beg>n) return;
|
||||||
|
if (m == 0) {
|
||||||
|
for (int i = 0; i<v.size(); i++) {
|
||||||
|
i == 0 ? cout << v[i] : cout << " " << v[i];
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
for (int i = beg; i <= n&&i <= m; i++) {
|
||||||
|
v.push_back(i);
|
||||||
|
help(n, m - i, v, i + 1);
|
||||||
|
v.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
|
int n, m;
|
||||||
|
while (cin >> n >> m) {
|
||||||
|
vector<int>v;
|
||||||
|
help(n, m, v, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(3)求从输入的三个数中最接近x 的然后输出对应字符
|
||||||
|
https://leetcode.cn/problems/3sum-closest/solutions/1891439/javati-jie-by-zejiang-wga8/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1.实现多线程方法有哪些
|
||||||
|
2.线程池核心参数和执行流程
|
||||||
|
3.工具类实现线程池有哪些已经如何选择(不知道应用场景,扯了扯美团动态线程池)
|
||||||
|
4.java里面锁有哪些
|
||||||
|
5.synchrorized 锁升级、锁粗化、锁消退(就答了锁升级)
|
||||||
|
6.markword除了对象头还有哪些
|
||||||
|
7.jvm内存结构、对象判断存活算法、垃圾回收算法
|
||||||
|
8.类加载过程、双亲委派机制、如何打破(打破忘记了,举了热部署插件可能用到)
|
||||||
|
9.JMM内存模型、cas原理、volatile关键字
|
||||||
|
10.mysql索引有哪些、b树和b加树区别、索引失效情况、索引下推、回表查询
|
||||||
|
11.范围查询索引会失效吗?explain 中关注哪些字段、type字段怎么判断是不是最优
|
||||||
|
12.事务特性、隔离级别、事务产生问题
|
||||||
|
13.redis 数据结构有哪些项目里面如何使用
|
||||||
|
14.大key问题如何解决、aof和rdb区别、项目中用到那种redis集群模式?都有什么区别?
|
||||||
|
15.缓存击穿、穿透、雪绷怎么解决、说一说布隆过滤器
|
||||||
|
16.项目里面使用到的一级缓存、二级缓存双写一致性(这个问题和我讨论了10分钟)
|
||||||
|
17. 项目里面使用到的aop+注解+redis实现的滑动窗口限流怎么做的。
|
||||||
|
18.手撕二路归并算法(直接秒了)
|
||||||
|
19.反问
|
||||||
|
|
||||||
|
有个场景题是问导入10万数据入Excel如何优化,还有一个是数据同步时如何保证最终一致性
|
||||||
|
然后一直拷打项目
|
||||||
|
最后问了选择题那个byte值赋128会变成什么,然后问赋129会变成什么
|
||||||
|
讲一下tcp/ip协议
|
||||||
|
项目中用到了ConCurrentHashMap,讲一下
|
||||||
|
讲一下丢包
|
||||||
|
讲一下mysql索引结构
|
||||||
|
一面 4月18
|
||||||
|
50分钟
|
||||||
|
为什么想来长沙?
|
||||||
|
了解操作系统吗,内核态和用户态
|
||||||
|
还有一个操作系统的忘记了
|
||||||
|
TCP和UDP的区别
|
||||||
|
TCP怎么实现可靠的
|
||||||
|
讲一下数据结构,数组,链表,hashmap
|
||||||
|
Hashmap扩容,为什么要2的指数这样扩容
|
||||||
|
只是因为取余用位运算提高效率吗
|
||||||
|
介绍下java中的乐观锁和悲观锁
|
||||||
|
Volite关键字,可见性是怎么实现的
|
||||||
|
CAS介绍一下?
|
||||||
|
在什么地方用的?Concurrenthashmap
|
||||||
|
什么是幂等,幂等怎么实现的,
|
||||||
|
Spring了解吗,ioc和aop,循环依赖怎么解决的
|
||||||
|
Mysql事务了解吗
|
||||||
|
怎么实现原子性的,
|
||||||
|
Mysql三大日志
|
||||||
|
Mysam和innodb 的区别
|
||||||
|
怎么优化sql查询
|
||||||
|
MVCC
|
||||||
|
JMM了解吗?
|
||||||
|
JVM了解多少
|
||||||
|
OOM在什么情况下会出现,有了解吗?
|
||||||
|
怎么解决的?尽量避免OOM
|
||||||
|
Redis了解吗?介绍一下
|
||||||
|
Redis持久化
|
||||||
|
Redis怎么保证原子性
|
||||||
|
了解IO多路复用吗
|
||||||
|
Lua脚本
|
||||||
|
AOF你有了解过吗?AOF日志重写知道吗
|
||||||
|
RocketMQ怎么保证消息不丢失的
|
||||||
|
如何保证不重复消费
|
||||||
|
|
||||||
|
场景题:
|
||||||
|
1.QPS 10000,怎么让接口顶住压力,已经有一万,不能通过前端控制,也不能限流
|
||||||
|
|
||||||
|
2.抽奖活动怎么保证,数据库不宕机
|
||||||
|
|
||||||
|
建议,多看源码,看看书
|
||||||
|
|
||||||
|
二面 4月23
|
||||||
|
50分钟
|
||||||
|
自我介绍
|
||||||
|
拷打实习
|
||||||
|
拷打项目
|
||||||
|
各种数据结构
|
||||||
|
设计模式
|
||||||
|
|
||||||
|
场景
|
||||||
|
怎么确定一个项目的,性能瓶颈出现在哪里
|
||||||
|
怎么去优化
|
||||||
|
怎么提高项目的性能瓶颈
|
||||||
|
从代码层面,架构设计层面等分析
|
||||||
|
高并发下的解决方案
|
||||||
|
反问
|
||||||
|
🕒岗位/面试时间
|
||||||
|
长沙 Java后端
|
||||||
|
|
||||||
|
作者:想逆袭好楠
|
||||||
|
链接:[https://www.nowcoder.com/feed/main/detail/cad5079c35ba4006936a7deec6780cd9?sourceSSR=dynamic](https://www.nowcoder.com/feed/main/detail/cad5079c35ba4006936a7deec6780cd9?sourceSSR=dynamic)
|
||||||
|
来源:牛客网
|
|
@ -64,7 +64,7 @@ CentOS Stream 9 x86_64
|
||||||
cd /etc/yum.repos.d/
|
cd /etc/yum.repos.d/
|
||||||
|
|
||||||
//创建新文件夹并将源文件备份为repo.bak
|
//创建新文件夹并将源文件备份为repo.bak
|
||||||
mkdir backup && mv *repo backup/
|
mkdir backup && mv *repo backup/
|
||||||
|
|
||||||
//下载国内yum源文件
|
//下载国内yum源文件
|
||||||
sed -i 's|metalink|#metalink|g' /etc/yum.repos.d/*.repo
|
sed -i 's|metalink|#metalink|g' /etc/yum.repos.d/*.repo
|
||||||
|
|
|
@ -75,6 +75,22 @@ sudo vim /etc/docker/daemon.json
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /etc/docker
|
||||||
|
sudo tee /etc/docker/daemon.json <<-'EOF'
|
||||||
|
{
|
||||||
|
"registry-mirrors": [
|
||||||
|
"https://docker.m.daocloud.io",
|
||||||
|
"https://dockerproxy.com",
|
||||||
|
"https://docker.mirrors.ustc.edu.cn",
|
||||||
|
"https://docker.nju.edu.cn"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl restart docker
|
||||||
|
```
|
||||||
|
|
||||||
上传地址设置
|
上传地址设置
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,14 @@
|
||||||
|
---
|
||||||
|
dg-publish: true
|
||||||
|
title: GrayLog 分布式日志
|
||||||
|
date: 2024-01-09 21:14:07.464
|
||||||
|
updated: 2024-01-11 09:47:32.724
|
||||||
|
url: https://blog.hhdxw.top/archives/321
|
||||||
|
tags:
|
||||||
|
- GrayLog
|
||||||
|
categories:
|
||||||
|
- 日志管理平台
|
||||||
|
---
|
||||||
`GrayLog`是一个轻量型的分布式日志管理平台,一个开源的日志聚合、分析、审计、展示和预警工具。在功能上来说,和 ELK类似,但又比 ELK要简单轻量许多。依靠着更加简洁,高效,部署使用简单的优势很快受到许多公司的青睐。
|
`GrayLog`是一个轻量型的分布式日志管理平台,一个开源的日志聚合、分析、审计、展示和预警工具。在功能上来说,和 ELK类似,但又比 ELK要简单轻量许多。依靠着更加简洁,高效,部署使用简单的优势很快受到许多公司的青睐。
|
||||||
|
|
||||||
![](https://lsky.hhdxw.top/imghub/2024/01/image-202401091704805912.png)
|
![](https://lsky.hhdxw.top/imghub/2024/01/image-202401091704805912.png)
|
||||||
|
|
Loading…
Reference in New Issue