站长信息
jeffery.xu
jeffery.xu

软件工程师

欢迎访问我的个人笔记网站!我是一名热爱技术的开发者,专注于Web开发和技术分享。

811495111@qq.com
18521510875
筛选

个人笔记

Ubuntu Docker安装完整指南 📦
人工智能学习

## Ubuntu Docker安装完整指南 📦

---

### 方法一:一键安装(推荐,国内服务器)

```bash
# 使用阿里云镜像安装(国内服务器首选)
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
```

---

### 方法二:手动安装(Ubuntu 24.04/22.04/20.04)

#### 1. 更新系统
```bash
sudo apt update && sudo apt upgrade -y
```

#### 2. 安装依赖
```bash
sudo apt install -y ca-certificates curl gnupg lsb-release
```

#### 3. 添加Docker官方GPG密钥
```bash
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
```

#### 4. 添加Docker仓库
```bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

#### 5. 安装Docker
```bash
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

---

### 启动Docker

```bash
# 启动Docker
sudo systemctl start docker

# 设置开机自启
sudo systemctl enable docker

# 验证安装
docker --version
```

---

### 常见问题解决

#### 问题1:权限问题
```bash
# 将当前用户加入docker组
sudo usermod -aG docker $USER

# 重新登录后生效,或执行
newgrp docker
```

#### 问题2:临时解决方案(每次命令前加sudo)
```bash
# 修改socket权限(不推荐生产环境)
sudo chmod 666 /var/run/docker.sock
```

---

### 验证Docker

```bash
# 查看Docker版本
docker --version

# 运行测试容器
docker run hello-world

# 查看运行中的容器
docker ps
```

---

### Docker常用命令

| 命令 | 说明 |
|------|------|
| `docker ps` | 查看运行中的容器 |
| `docker ps -a` | 查看所有容器 |
| `docker stop 容器名` | 停止容器 |
| `docker rm 容器名` | 删除容器 |
| `docker images` | 查看镜像列表 |
| `docker rmi 镜像名` | 删除镜像 |
| `docker logs 容器名` | 查看容器日志 |

---

### 完整流程

```bash
# 1. 一键安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

# 2. 启动
sudo systemctl start docker
sudo systemctl enable docker

# 3. 验证
docker --version
```

安装完成后就可以部署您的网站了!

Docker SCP部署完整流程 📦
人工智能学习

## Docker SCP部署完整流程 📦

---

### 一、本地操作(Windows)

#### 1. 构建Docker镜像
```powershell
cd c:\Users\jeff\Documents\GitHub\Diary
docker build -t diary-website .
```

#### 2. 导出镜像为tar文件
```powershell
docker save -o diary-website.tar diary-website:latest
```

#### 3. 传输到服务器
```powershell
scp diary-website.tar ubuntu@106.54.42.242:/home/ubuntu/
```
> 第一次会提示输入yes确认,然后输入服务器密码

---

### 二、服务器操作(腾讯云Ubuntu)

#### 1. 加载镜像
```bash
docker load -i diary-website.tar
```

#### 2. 停止并删除旧容器(如有)
```bash
sudo docker stop diary-website
sudo docker rm diary-website
```

#### 3. 运行新容器
```bash
sudo docker run -d -p 80:80 --name diary-website diary-website
```

#### 4. 验证运行状态
```bash
sudo docker ps
```

---

### 三、完整命令汇总

**本地:**
```powershell
# 构建 → 导出 → 传输
cd c:\Users\jeff\Documents\GitHub\Diary
docker build -t diary-website .
docker save -o diary-website.tar diary-website:latest
scp diary-website.tar ubuntu@106.54.42.242:/home/ubuntu/
```

**服务器:**
```bash
# 加载 → 重启
docker load -i diary-website.tar
sudo docker stop diary-website
sudo docker rm diary-website
sudo docker run -d -p 80:80 --name diary-website diary-website
```

---

### 四、注意事项

| 项目 | 说明 |
|------|------|
| 端口 | 腾讯云安全组需开放80端口 |
| 镜像大小 | 约390MB |
| 首次SSH | 输入yes确认服务器指纹 |
| Docker权限 | 使用sudo执行docker命令 |

---

### 五、访问网站

```
http://106.54.42.242
```

---

需要我帮您执行这些命令吗?

腾讯云服务器安装 XFCE 桌面完整指南
人工智能学习

# 腾讯云服务器安装 XFCE 桌面完整指南

## 一、环境要求
- 服务器:腾讯云 Ubuntu 20.04/22.04
- 网络:已开放 5901 端口(安全组)

---

## 二、安装步骤

### 1. 更新系统
```bash
sudo apt update && sudo apt upgrade -y
```

### 2. 安装 XFCE 桌面环境
```bash
sudo apt install xfce4 xfce4-goodies dbus-x11 -y
```

### 3. 安装 TigerVNC
```bash
sudo apt install tigervnc-standalone-server tigervnc-common -y
```

### 4. 创建普通用户(可选,推荐使用非 root 用户)
```bash
sudo adduser ubuntu
```

### 5. 切换到目标用户并配置
```bash
su - ubuntu
vncpasswd          # 设置 VNC 密码
touch ~/.Xresources
```

### 6. 创建 xstartup 启动脚本
```bash
cat > ~/.vnc/xstartup << 'EOF'
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
unset XDG_SESSION_DIR
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP=XFCE
export XDG_SESSION_TYPE=x11
export DISPLAY=:1
xrdb ~/.Xresources
xsetroot -solid grey
/usr/bin/startxfce4
EOF

chmod +x ~/.vnc/xstartup
```

### 7. 测试启动 VNC
```bash
vncserver -localhost no -geometry 1920x1080 :1
```

### 8. 配置腾讯云安全组
在腾讯云控制台 → 安全组 → 添加入站规则:
- 协议:TCP
- 端口:5901
- 来源:0.0.0.0/0

---

## 三、配置开机自启(推荐)

### 创建 systemd 服务
```bash
sudo tee /etc/systemd/system/vnc.service << 'EOF'
[Unit]
Description=VNC Server
After=network.target

[Service]
Type=forking
User=ubuntu
ExecStart=/usr/bin/vncserver -localhost no -geometry 1920x1080 :1
ExecStop=/usr/bin/vncserver -kill :1
WorkingDirectory=/home/ubuntu

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable vnc
sudo systemctl start vnc
```

---

## 四、连接方式

1. 下载 VNC 客户端(TigerVNC Viewer)
2. 连接地址:`服务器公网IP:5901`
3. 输入 VNC 密码

---

## 五、常见问题排查

| 问题 | 解决方法 |
|------|----------|
| 连接不上 | 检查腾讯云安全组是否开放 5901 端口 |
| 黑屏 | 检查 xstartup 脚本是否正确,查看日志 `cat ~/.vnc/*.log` |
| 端口被占用 | `vncserver -kill :1` 停止后重新启动 |
| 服务启动失败 | `systemctl status vnc.service` 查看错误 |

---

## 六、日常使用

```bash
# 手动启动
vncserver -localhost no -geometry 1920x1080 :1

# 手动停止
vncserver -kill :1

# 查看状态
vncserver -list
systemctl status vnc
```

 

ping端口
编程技巧

 telnet 127.0.0.1 6379

telnet功能需要在控制面板,程序与功能中勾选出来,同IIS

@Bean注解详解
编程技巧

@Bean注解是Spring框架中的核心注解,用于将方法返回的对象注册为Spring容器管理的Bean。


@Bean的核心作用
1. Bean注册


将方法返回的对象注册到Spring的IoC容器中
成为Spring管理的组件,可以被依赖注入
2. 生命周期管理


Spring负责Bean的创建、初始化和销毁
默认为单例模式(Singleton)
3. 依赖注入
可以在任何Spring管理的类中通过@Autowired注入使用

@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

执行过程:
Spring启动时扫描到这个方法
调用方法创建BCryptPasswordEncoder实例
将实例注册到容器中,Bean名称为passwordEncoder
全应用共享这一个实例

常见的Bean作用域
singleton(默认):全局单例
prototype:每次注入创建新实例
request:每个HTTP请求一个实例
session:每个HTTP会话一个实例

@Bean本质上是告诉Spring:"这个方法返回的对象请帮我管理,其他地方需要时直接注入给它们"。
Mysql强行清空有外键的表
编程技巧
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE users;
初步pom配置
编程技巧
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.mobizone</groupId>
    <artifactId>kb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>kb</name>
    <description>kb</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>24</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <dependencies>
    <!--    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>-->
<!--        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>com.mysql</groupId>-->
<!--            <artifactId>mysql-connector-j</artifactId>-->
<!--            <scope>runtime</scope>-->
<!--        </dependency>-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>
        <!-- JWT -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.38</version>
            <optional>true</optional>
        </dependency>
        <!-- Swagger (springdoc-openapi) -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

总结几个问题
1. springboot 3.5.4  Lombok要版本高
2. mybatis 版本要新
3. 其他的暂时没碰到问题

如何使用 WSL(Windows Subsystem for Linux)
编程技巧

先决条件

必须运行 Windows 10 版本 2004 及更高版本(内部版本 19041 及更高版本)或 Windows 11 才能使用以下命令。 如果使用的是早期版本,请参阅 手动安装页

安装 WSL 命令

现在,可以使用单个命令安装运行 WSL 所需的所有内容。 右键单击并选择“以管理员身份运行”,在 管理员 模式下打开 PowerShell 或 Windows 命令提示符,输入 wsl --install 命令,然后重新启动计算机。

PowerShell
wsl --install

此命令将启用运行 WSL 并安装 Linux 的 Ubuntu 分发所需的功能。 (可以更改此默认分布)。

如果运行的是较旧的版本,或者只是不想使用安装命令,并且想要分步说明,请参阅 适用于旧版本的 WSL 手动安装步骤

首次启动新安装的 Linux 分发版时,控制台窗口将打开,系统会要求你等待文件取消压缩并存储在计算机上。 所有未来的发射应该需要不到一秒钟的时间。

知识库数据库设计
编程技巧
-- 用户表
CREATE TABLE users (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(50) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    email VARCHAR(100) UNIQUE,
    nickname VARCHAR(50),
    avatar VARCHAR(255),
    status TINYINT DEFAULT 1 COMMENT '1:正常 0:禁用',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- 角色表
CREATE TABLE roles (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    role_name VARCHAR(50) UNIQUE NOT NULL,
    role_code VARCHAR(50) UNIQUE NOT NULL,
    description TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 用户角色关联表
CREATE TABLE user_roles (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT NOT NULL,
    role_id BIGINT NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (role_id) REFERENCES roles(id),
    UNIQUE KEY uk_user_role (user_id, role_id)
);

-- 知识分类/目录表
CREATE TABLE categories (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL,
    parent_id BIGINT DEFAULT 0 COMMENT '父分类ID,0为顶级分类',
    sort_order INT DEFAULT 0,
    description TEXT,
    icon VARCHAR(100),
    status TINYINT DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- 知识文章表
CREATE TABLE articles (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    title VARCHAR(200) NOT NULL,
    content LONGTEXT,
    summary TEXT,
    category_id BIGINT,
    author_id BIGINT NOT NULL,
    view_count INT DEFAULT 0,
    like_count INT DEFAULT 0,
    status TINYINT DEFAULT 1 COMMENT '1:发布 0:草稿 -1:删除',
    is_top TINYINT DEFAULT 0 COMMENT '是否置顶',
    tags VARCHAR(500),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (category_id) REFERENCES categories(id),
    FOREIGN KEY (author_id) REFERENCES users(id)
);

-- 附件表
CREATE TABLE attachments (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    article_id BIGINT,
    file_name VARCHAR(255) NOT NULL,
    file_path VARCHAR(500) NOT NULL,
    file_size BIGINT,
    file_type VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (article_id) REFERENCES articles(id)
);
java知识库网站初步设想
编程技巧

前后端分离 + Spring Boot + MyBatis + MySQL 暂定的项目架构:

## 后端技术栈

```xml
<!-- 主要依赖 -->
Spring Boot 3.x
├── Spring Security (认证授权)
├── MyBatis Plus (数据访问层)
├── MySQL 8.0 (数据库)
├── Redis (缓存)
├── JWT (Token认证)
└── Swagger (API文档)
```

## 项目结构

```
knowledge-base-backend/
├── src/main/java/com/example/kb/
│   ├── config/          # 配置类
│   ├── controller/      # 控制器
│   ├── service/         # 业务层
│   ├── mapper/          # MyBatis映射接口
│   ├── entity/          # 实体类
│   ├── dto/             # 数据传输对象
│   ├── vo/              # 视图对象
│   ├── common/          # 公共类
│   └── utils/           # 工具类
├── src/main/resources/
│   ├── mapper/          # MyBatis XML映射文件
│   ├── application.yml  # 配置文件
│   └── static/          # 静态资源
└── pom.xml
```

## Maven依赖配置

```xml
<dependencies>
    <!-- Spring Boot Starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    
    <!-- MyBatis Plus -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.5.4</version>
    </dependency>
    
    <!-- MySQL驱动 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <!-- Redis -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    
    <!-- JWT -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-api</artifactId>
        <version>0.11.5</version>
    </dependency>
    
    <!-- Swagger -->
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>
```

## 核心实体类设计

### User实体类
```java
@Data
@TableName("users")
public class User {
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private String username;
    private String password;
    private String email;
    private String nickname;
    private String avatar;
    private Integer status;
    
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
}
```

### Article实体类
```java
@Data
@TableName("articles")
public class Article {
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private String title;
    private String content;
    private String summary;
    private Long categoryId;
    private Long authorId;
    private Integer viewCount;
    private Integer likeCount;
    private Integer status;
    private Integer isTop;
    private String tags;
    
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
}
```

## MyBatis配置

### application.yml
```yaml
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/knowledge_base?useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: your_password
    
  redis:
    host: localhost
    port: 6379
    database: 0

mybatis-plus:
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.example.kb.entity
```

## 前端技术栈

### 前台用户端
```json
{
  "技术栈": {
    "框架": "Vue 3 + Vite",
    "UI库": "Element Plus",
    "路由": "Vue Router 4", 
    "状态管理": "Pinia",
    "HTTP客户端": "Axios",
    "编辑器": "Vditor/TinyMCE"
  }
}
```

### 后台管理端
```json
{
  "技术栈": {
    "框架": "Vue 3 + Vite",
    "UI库": "Element Plus",
    "模板": "vue-element-plus-admin",
    "图表": "ECharts",
    "表格": "Element Plus Table"
  }
}
```

## API接口设计示例

### 文章相关接口
```java
@RestController
@RequestMapping("/api/articles")
public class ArticleController {
    
    @GetMapping("/list")
    public R<IPage<ArticleVO>> getArticleList(@RequestParam Map<String, Object> params) {
        // 分页查询文章列表
    }
    
    @GetMapping("/{id}")
    public R<ArticleVO> getArticleById(@PathVariable Long id) {
        // 获取文章详情
    }
    
    @PostMapping
    public R<Void> saveArticle(@RequestBody ArticleDTO articleDTO) {
        // 新增文章
    }
    
    @PutMapping("/{id}")
    public R<Void> updateArticle(@PathVariable Long id, @RequestBody ArticleDTO articleDTO) {
        // 更新文章
    }
}
```

## 开发建议

1. **数据库设计**:先创建数据库表结构
2. **后端开发**:从Entity → Mapper → Service → Controller的顺序开发
3. **前端开发**:先搭建基础框架,再开发具体页面
4. **接口联调**:使用Swagger进行接口测试

需要我提供具体的某个模块的详细代码吗?比如用户认证、文章管理等。