目录

Life in Flow

知不知,尚矣;不知知,病矣。
不知不知,殆矣。

X

Quick Find 置顶!

dictionary

System

RockyLinux9 root用户通过ssh

允许Rocky Linux 9 root用户通过ssh登录方法:

1. 编辑SSH配置文件

vi /etc/ssh/sshd_config 按键盘i 进行编辑

找到以下内容

#PermitRootLogin prohibit-password

将其修改为

PermitRootLogin yes

按键盘Esc 键 :wq 保存退出

重启SSH服务

systemctl restart sshd

此时root用户可以通过ssh远程登录

RockyLinux9 安装docker镜像不兼容(Selinux)

https://www.sujx.net/2023/07/10/RockyLinux-Container/index.html

Firewalld

# 启动
systemctl start firewalld

# 查看状态
systemctl status firewalld

# 禁用,禁止开机启动
systemctl disable firewalld

# 停止运行
systemctl stop firewalld

SyncTime

# 安装ntp服务
yum install ntp 

# 开机启动服务
systemctl enable ntpd 

# 启动服务
systemctl start ntpd

# 更改时区
timedatectl set-timezone Asia/Shanghai

# 启用ntp同步
timedatectl set-ntp yes 

# 同步时间
ntpq -p



###  crontab
[root@master tmp]# vi /tmp/synctime.sh
#!/bin/bash
systemctl restart ntpd
timedatectl set-timezone Asia/Shanghai
timedatectl set-ntp yes
ntpq -p

[root@master tmp]# crontab -e
* * * * * /tmp/synctime.sh

Partition

在这里插入图片描述

socks5 Agent

[root@DevOps ~]# vim /etc/profile
[root@DevOps ~]# source /etc/profile
export ALL_PROXY="socks5://192.168.10.88:10808"
export https_proxy="http://192.168.10.88:10809"
export http_proxy="http://192.168.10.88:10809"

Yum 2 Aliyun

### 备份yum源文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

### 新建yum仓库配置文件
vi /etc/yum.repos.d/CentOS-Base.repo
# 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-vault/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7

### 清除缓存并重建元数据缓存
yum clean all && yum makecache

Maven

https://blog.csdn.net/aaxzsuj/article/details/130524829

SpringBoot

启动类

package net.xdclass;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("net.xdclass.mapper")
public class UserApplication {
    public static void main(String[] args) {
        SpringApplication.run(UserApplication.class,

application.yml

server:
  port: 9001
  
spring:
  application:
    name: xdclass-user-service

  # 数据库配置
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.10.21:3307/xdclass_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: abc1024.pub

# 配置plus打印sql日志
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# 设置日志级别,ERROR/WARN/INFO/DEBUG,默认是INFO以上才显示
logging:
  level:
    root: INFO

Docker

Install

#安装并运行Docker。
yum install docker-io -y
systemctl start docker

#检查安装结果。
docker info

#启动使用Docker
systemctl start docker     #运行Docker守护进程
systemctl stop docker      #停止Docker守护进程
systemctl restart docker   #重启Docker守护进程


#修改镜像仓库
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://mirror.baidubce.com",
        "https://docker.nju.edu.cn",
        "https://mirror.iscas.ac.cn",
        "https://88bit3po.mirror.aliyuncs.com"
    ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

#查看信息
docker info

daemon.json

https://patzer0.com/archives/configure-docker-registry-mirrors-with-mirrors-available-in-cn-mainland

[root@Flink ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://dockerpull.com"]
}

sudo systemctl daemon-reload
sudo systemctl restart docker

升级

升级https://blog.csdn.net/u011990675/article/details/141320931

升级后启动以前容器遇到的问题Error response from daemon: unknown or invalid runtime name: docker-runc

解决问题https://blog.csdn.net/weixin_40918145/article/details/133855258

MongoDB

配置文件

net:
    port: 27017
    bindIp: "0.0.0.0"

storage:
    dbPath: "/data/db"

security:
    authorization: enabled

命令

docker run -it -d --name mongo \
-p 27017:27017 \
--net mynet \
--ip 172.18.0.8 \
-v /root/mongo:/etc/mongo \
-v /root/mongo/data/db:/data/db \
-m 400m --privileged=true \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=abc123456 \
-e TZ=Asia/Shanghai \
docker.io/mongo --config /etc/mongo/mongod.conf

Redis

配置文件

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 12
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
requirepass abc123456

命令

docker run -it -d --name redis -m 200m \
-p 6379:6379 --privileged=true \
--net mynet --ip 172.18.0.9 \
-v /root/redis/conf:/usr/local/etc/redis \
-e TZ=Asia/Shanghai redis:6.0.10 \
redis-server /usr/local/etc/redis/redis.conf

RabbitMQ

命令

docker run -it -d --name mq \
--net mynet --ip 172.18.0.11 \
-p 5672:5672 -m 500m \
-e TZ=Asia/Shanghai --privileged=true \
rabbitmq

Minio

我们打开浏览器,访问 http://127.0.0.1:9001/login,然后填写好登陆信息,就能进入Web管理画面。 root abc123

目录

docker load < Minio.tar.gz
mkdir /root/minio
mkdir /root/minio/data
chmod -R 777 /root/minio/data

命令

docker run -it -d --name minio \
-p 9000:9000 -p 9001:9001 \
-v /root/minio/data:/data \
-e TZ=Asia/Shanghai --privileged=true \
--env MINIO_ROOT_USER="root" \
--env MINIO_ROOT_PASSWORD="abc123456" \
-e MINIO_SKIP_CLIENT="yes" \
bitnami/minio:latest


### 最新版
docker run -it -d --name minio -m 400m \
-p 9000:9000 -p 9001:9001 \
-v /data/minio/data:/data \
-e TZ=Asia/Shanghai --privileged=true \
--env MINIO_ROOT_USER="root" \
--env MINIO_ROOT_PASSWORD="abc123456" \
bitnami/minio:latest

http://192.168.10.21:9001/login

Nacos

http://localhost:8848/nacos/
nacos
nacos

docker run -it -d -p 8848:8848 --env MODE=standalone \
--net mynet --ip 172.18.0.12 -e TZ=Asia/Shanghai \
--name nacos nacos/nacos-server

### new
docker run -d \
-e NACOS_AUTH_ENABLE=true \
-e MODE=standalone \
-e JVM_XMS=128m \
-e JVM_XMX=128m \
-e JVM_XMN=128m \
-p 8848:8848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.10.58 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=abc1024.pub \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false' \
--restart=always \
--privileged=true \
-v /home/data/nacos/logs:/home/nacos/logs \
--name xdclass_nacos_auth \
nacos/nacos-server:2.0.2

SQL脚本,库名nacos_config

Sentinel

打开浏览器访问http://localhost:8858/#/login,然后填写登陆帐户,用户名和密码都是 sentinel

docker run -it -d --name sentinel \
-p 8719:8719 -p 8858:8858 \
--net mynet --ip 172.18.0.13 \
-e TZ=Asia/Shanghai -m 600m \
bladex/sentinel-dashboard

Mysql

docker run \
    -p 3306:3306 \
    -e MYSQL_ROOT_PASSWORD=123456 \
    -v /home/data/mysql/conf:/etc/mysql/conf.d \
    -v /home/data/mysql/data:/var/lib/mysql:rw \
    -v /home/data/mysql/my.cnf:/etc/mysql/my.cnf \
    --name mysql \
    --restart=always \
    -d mysql:8.0.22

docker run \
    -p 3306:3306 \
    -e MYSQL_ROOT_PASSWORD=123456 \
    --name mysql \
    -d mysql:8.0.22

webssh

docker run -d --name webssh -p 5032:5032 --restart always lihaixin/webssh2:ssh

Mybatis-plus-generator

依赖

<dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-generator</artifactId>
        <version>3.4.1</version>
    </dependency>
    <!-- velocity -->
    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity-engine-core</artifactId>
        <version>2.0</version>
    </dependency>
    <!-- 代码自动生成依赖 end-->

代码(标记TODO的记得修改)

package net.xdclass.db;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyBatisPlusGenerator {

    public static void main(String[] args) {
        //1. 全局配置
        GlobalConfig config = new GlobalConfig();
        // 是否支持AR模式
        config.setActiveRecord(true)
                // 作者
                .setAuthor("soulboy")
                // 生成路径,最好使用绝对路径,window路径是不一样的
                //TODO  TODO  TODO  TODO
                .setOutputDir("C:\\Users\\chao1\\Desktop\\demo\\src\\main\\java")
                // 文件覆盖
                .setFileOverride(true)
                // 主键策略
                .setIdType(IdType.AUTO)

                .setDateType(DateType.ONLY_DATE)
                // 设置生成的service接口的名字的首字母是否为I,默认Service是以I开头的
                .setServiceName("%sService")

                //实体类结尾名称
                .setEntityName("%sDO")

                //生成基本的resultMap
                .setBaseResultMap(true)

                //不使用AR模式
                .setActiveRecord(false)

                //生成基本的SQL片段
                .setBaseColumnList(true);

        //2. 数据源配置
        DataSourceConfig dsConfig = new DataSourceConfig();
        // 设置数据库类型
        dsConfig.setDbType(DbType.MYSQL)
                .setDriverName("com.mysql.cj.jdbc.Driver")
                //TODO  TODO  TODO  TODO
                .setUrl("jdbc:mysql://192.168.10.21:3307/xdclass_user?useSSL=false")
                .setUsername("root")
                .setPassword("abc1024.pub");

        //3. 策略配置globalConfiguration中
        StrategyConfig stConfig = new StrategyConfig();

        //全局大写命名
        stConfig.setCapitalMode(true)
                // 数据库表映射到实体的命名策略
                .setNaming(NamingStrategy.underline_to_camel)

                //使用lombok
                .setEntityLombokModel(true)

                //使用restcontroller注解
                .setRestControllerStyle(true)

                // 生成的表, 支持多表一起生成,以数组形式填写
                //TODO  TODO  TODO  TODO
                .setInclude("user","address");

        //4. 包名策略配置
        PackageConfig pkConfig = new PackageConfig();
        pkConfig.setParent("net.xdclass")
                .setMapper("mapper")
                .setService("service")
                .setController("controller")
                .setEntity("model")
                .setXml("mapper");

        //5. 整合配置
        AutoGenerator ag = new AutoGenerator();
        ag.setGlobalConfig(config)
                .setDataSource(dsConfig)
                .setStrategy(stConfig)
                .setPackageInfo(pkConfig);

        //6. 执行操作
        ag.execute();
        System.out.println("=======  Done 相关代码生成完毕  ========");
    }
}

SwaggerConfiguration

依赖

<!--swagger ui接口文档依赖-->
       <dependency>
           <groupId>io.springfox</groupId>
           <artifactId>springfox-boot-starter</artifactId>
           <version>3.0.0</version>
       </dependency>

SwaggerConfiguration

package net.xdclass.config;

import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.*;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ScalarType;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

@Component
@EnableOpenApi
@Data
public class SwaggerConfiguration {

    /**
     * 对C端用户的接口文档
     *
     * @return
     */
    @Bean
    public Docket webApiDoc() {

        return new Docket(DocumentationType.OAS_30)
                .groupName("用户端接口文档")
                .pathMapping("/")
                // 定义是否开启swagger,false为关闭,可以通过变量控制,线上关闭
                .enable(true)
                //配置api文档元信息
                .apiInfo(apiInfo())
                // 选择哪些接口作为swagger的doc发布
                .select()
                .apis(RequestHandlerSelectors.basePackage("net.xdclass"))
                //正则匹配请求路径,并分配至当前分组
                .paths(PathSelectors.ant("/api/**"))
                .build()
                //新版swagger3.0配置
                .globalRequestParameters(getGlobalRequestParameters())
                .globalResponses(HttpMethod.GET, getGlobalResponseMessage())
                .globalResponses(HttpMethod.POST, getGlobalResponseMessage());
    }


    /**
     * 生成全局通用参数, 支持配置多个响应参数
     * 可以携带 token 信息
     * @return
     */
    private List<RequestParameter> getGlobalRequestParameters() {
        List<RequestParameter> parameters = new ArrayList<>();
        parameters.add(new RequestParameterBuilder()
                .name("token")
                .description("登录令牌")
                .in(ParameterType.HEADER)
                .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
                .required(false)
                .build());

//        parameters.add(new RequestParameterBuilder()
//                .name("version")
//                .description("版本号")
//                .required(true)
//                .in(ParameterType.HEADER)
//                .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
//                .required(false)
//                .build());

        return parameters;
    }

    /**
     * 生成通用响应信息
     *
     * @return
     */
    private List<Response> getGlobalResponseMessage() {
        List<Response> responseList = new ArrayList<>();
        responseList.add(new ResponseBuilder().code("4xx").description("请求错误,根据code和msg检查").build());
        return responseList;
    }

    /**
     * api文档元信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("1024电商平台")
                .description("微服务接口文档")
                .contact(new Contact("soulboy", "abc1024.pub", "410686931@qq.com"))
                .version("v1.0")
                .build();
    }
}

AddressController

package net.xdclass.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
/**
 * <p>
 * 电商-公司收发货地址表 前端控制器
 * </p>
 *
 * @author soulboy
 * @since 2023-10-21
 */
@Api(tags = "收货地址接口")
@RestController
@RequestMapping("/api/address/v1")
public class AddressController {
    @Autowired
    AddressService addressService;
    @ApiOperation("根据id查找地址详情")
    @GetMapping("find/{address_id}")
    public Object detail(@ApiParam(value = "地址id",required = true)
                             @PathVariable("address_id") long addressId){
        return addressService.detail(addressId);
    }
}

访问地址

http://192.168.10.88:9001/swagger-ui/index.html#/

Git

git add ./*

git commit -m "init2"

git push -u origin "master"

Hyper-v

### 关闭
bcdedit /set hypervisorlaunchtype off 

### 开启
bcdedit /set hypervisorlaunchtype auto

Docker打包Maven插件配置

### 聚合工程pom添加全局变量
        <docker.image.prefix>xdclass-cloud</docker.image.prefix>

### 每个微服务都添加依赖(服务名记得修改)
 <build>
        <finalName>alibaba-cloud-user</finalName>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <!--需要加这个,不然打包镜像找不到启动文件-->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>

                </configuration>
            </plugin>

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.10</version>
                <configuration>

                    <repository>${docker.image.prefix}/${project.artifactId}</repository>

                    <buildArgs>
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>

        </plugins>

    </build>

Dockerfile

### Dockerfile文件内容
#FROM  adoptopenjdk/openjdk11:ubi
FROM  adoptopenjdk/openjdk11:jre11u-nightly
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

### mvn打包命令()
# 步骤一:最外层 mvn clean install
mvn clean install

# 步骤二:去到子模块pom文件下
mvn install -Dmaven.test.skip=true dockerfile:build

front-end

cnpm

npm install -g cnpm --registry=https://registry.npmmirror.com

Plan

  1. 工业级 PaaS 云平台 +SpringCloudAlibaba+JDK11 (SEATA)
  2. XXL-Job
  3. 容器编排 k8s 最佳实践 kubernetes+Rancher2.x
  4. 工业级 PaaS 云平台 +SpringCloudAlibaba+JDK11
  5. 海量数据处理-商用短链平台(58xueke : 77.4)

作者:Soulboy