Windows SSH免密连接Linux服务器

📅 2022-04-02 13:58 👁️ 653 💬 0

Windows SSH免密连接Linux服务器

我们在自己电脑上需要远程连接Linux服务器时,每次都需要输入 ssh @username ip -p port,还需要输入登录密码,过程复杂,因此准备在Windows上配置SSH免密连接Linux服务器

前提:电脑上已经存在一对SSH-Key,准备新建一对SSH-Key

1 创建SSH-Key

# 1.生产密钥 以rsa算法
C:\Users\Administrator\.ssh> ssh-keygen -t rsa -C "linux" 
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa): C:\Users\Administrator/.ssh/id_rsa_linux #2.填写新的地址
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa_linux.
Your public key has been saved in C:\Users\Administrator/.ssh/id_rsa_linux.pub.
The key fingerprint is:
SHA256:QeTc5iTO6rhOTW1a5IfgcOw3rMPjhdCYpcrz2VPpbMg linux
The key's randomart image is:
+---[RSA 2048]----+
|       .o        |
|     . + .       |
|    . = * +      |
|     @ O B       |
|    = = S.o      |
| . . = Ooo       |
|  + ..X=.        |
|   + *E++        |
|   .*.+o         |
+----[SHA256]-----+
PS C:\Users\Administrator\.ssh>
 

image-20220402101618962

2 将公钥拷贝到Linux服务器上(拷贝或上传)

位置:/root/.ssh

image-20220402133431800

如果不存在 authorized_keys,则新建一个文件,将生成的公钥复制追加到authorized_keys中

还可以通过上传的方式,将公钥上传到服务器上:

  1. 使用 Git Bash ,在Windows ssh文件夹下右击打开 Git Bash 输入 ssh-copy-id root@ip -p prot

  2. 输入密码,后即可上传

3 Linux服务器修改SSH配置

位置:/etc/ssh/sshd_config

image-20220402133827103

PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes

注意:修改玩后重启SSH服务:

  1. service ssh restart // centos 6的命令
  2. systemctl restart sshd // centos 7的命令

4.在Windows ssh文件下新建config文件

image-20220402135158873

内容如下:

Host name ## 自定义名称
  HostName ip  ## ip地址
  Port port ## 端口号
  User user ## 登录用户名
  IdentityFile ~/.ssh/id_rsa_linux ##使用的私钥

5.测试使用

命令行中输入:ssh 自定义名称 (与上述 Host 后面定义的名称一致)

image-20220402135540085

阅读更多

MySQL 间隔取数据

📅 2022-03-21 13:07 👁️ 376 💬 0

MySQL 间隔取数据

背景介绍:系统中存在一张坐标表,存取一段路线桩号的具体坐标,坐标点多且密,如果全部返回给前端,后端接口响应很慢,为了解决这个问题,准备在查询数据库的时候,间隔取出一些坐标点即可,如每十个桩号取一个即可

数据表如下:

image-20220321130234445

具体实现

SELECT
n,id,longitude,latitude	
FROM
	(
	SELECT
		@n:= @n + 1 AS n,
		a.*
	FROM
		 ( SELECT * FROM biz_project_coordinates WHERE hidden = 0 AND geometry_id = "8ae4240e7c83a953017c83e07c043a91" ORDER BY origin_pile ) a,
		 ( SELECT @n := 0 ) b
	) c 
WHERE
	c.n % 10 = 1  // 每十条取一条
	OR c.n = 1 

结果:

image-20220321130536404

阅读更多

MySql 分组 获取每组最新的一条数据

📅 2022-03-21 12:45 👁️ 2207 💬 0

MySql 分组 获取每组最新的一条数据

前提:学生成绩表如下

image-20220321123800495

问题描述:获取每门科目成绩最高的记录,即取出 语文成绩最高(id=3)、数学成绩最高(id=4)的两条数据

解决方案:先按成绩(grade)降序,在进行分组

注意 :DISTINCT(s.id) tid 必需

SELECT * 
FROM (
    SELECT DISTINCT(s.id) tid, s.*  FROM `student` s
    ORDER BY s.grade DESC
) t
GROUP BY t.`subject`

结果:

image-20220321124234069

阅读更多

SpringBoot 集成 knife4j (Swagger2)

📅 2021-12-09 17:47 👁️ 873 💬 0

SpringBoot 集成 knife4j (Swagger2)

前提 :本文 spring boot版本为 2.6.1 ,knife4j 版本为:3.0.3

1、初始化项目,导入pom依赖

<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>3.0.3</version>
</dependency>

2、创建Swagger配置类

@Configuration
public class Swagger2Config {



    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())
                .select()
                // 这里可以指定扫描包的路径 或者 扫描指定的注解
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build().protocols(this.newHashSet("https","http"));
    }

    @SafeVarargs
    private final <T> Set<T> newHashSet(T... ts) {
        return ts.length > 0 ? new LinkedHashSet(Arrays.asList(ts)) : null;
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger接口文档")
                .description("文档描述")
                .contact( new Contact("xmStudy","https://www.cnblogs.com/XiaoMingStudy1/","123@qq.com"))
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }

}

最终项目结构图如下:

image-20211209181859354

3、出现的问题

项目启动失败

image-20211209145058757

4、解决问题

原因分析:在springboot 2.6.0会提示documentationPluginsBootstrapper NullPointerException,具体位置的WebMvcPatternsRequestConditionWrapper中的condition为null。原因是在springboot2.6.0中将SpringMVC 默认路径匹配策略从AntPathMatcher 更改为PathPatternParser,导致出错,解决办法是切换会原先的AntPathMatcher

解决问题:在properties中加上spring.mvc.pathmatch.matching-strategy=ant-path-matcher

5、项目正常启动,访问一下

ip为 ip:port/doc.html, 如 http://localhost:8080/doc.html#/home

image-20211209181922447

6 参考连接

  1. Knife4j 官方文档:https://doc.xiaominfo.com/knife4j/
  2. Github地址:https://github.com/xiaoymin/swagger-bootstrap-ui/issues/396
  3. Gitee地址:https://toscode.gitee.com/xiaoym/knife4j
阅读更多

idea Mybatis mapper配置文件删除SQL语句背景色

📅 2021-09-26 15:06 👁️ 270 💬 0

原样式:

image-20210926144955488

看着很不爽

本文 idea 版本为:idea 2020.3.1,以下操作均基于此版本进行

解决办法

1.去除警告

Settings>Editor>Inspections>SQL>No data sources configured 和 SQL dialect detection

No data sources configured :没有配置数据源

SQL dialect detection:SQL方言检测

image-20210926145946787

去除警告过后还有默写语句存在背景色

image-20210926150043943

2.去除“注入语言”背景色

**Settings>Editor>Color Scheme>Code>Injected language fragement **

image-20210926150349152

最终样式:

image-20210926150421000

阅读更多

Spring data jpa 报错: java.sql.SQLSyntaxErrorExceptoion: Table ' test.hibernate_sequence' doesn`t exists

📅 2021-09-13 11:13 👁️ 188 💬 0

错误信息如图:

image-20210912124916155

错误原因:在自定义主键是没有注明自增策略

解决办法:明确主键自增策略,比如

@Entity
@Table(name = "t_order")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Order implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String customer;

    private Date orderDate;
}

扩展:Jpa GenerationType的四种类型

  • TABLE :使用一个特定的数据库表格来保存主键
  • SEQUENCE:根据底层数据库序列来生成主键,条件是数据库支持序列
  • IDENTITY:主键由数据库自动生成,数据库设置了自增主键
  • AUTO:主键由程序控制,是Jpa的默认策略,可以不写
阅读更多

Springboot项目 配置数据库连接属性后,启动项目报错

📅 2021-09-13 11:02 👁️ 1032 💬 0

Springboot项目 配置数据库连接属性后,启动项目报错,错误如下:

image-20210912121135415

错误原因分析:

1.连接信息配置错误

当使用properties为配置文件时,如图所示,上面的 spring.datasource.name 这种写法是错误的,应该是username,还有一种情况可以将spring.datasource.driver-class-name 改成 spring.datasource.driverClassName

image-20210912121147828

​ 当使用yaml作为配置文件时,除了需要注意空格的情况,当用户名和密码为数字时,需要小心

​ 如下这个配置将会报错:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
    username: root
    password: 000000

这里的password为000000 ,最终获取的值是0 ,所以连接时将会报错

正确配置如下:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
    username: root
    password: "000000"

2.数据库授权失败

当连接信息都配置正确的化,很有可能是数据库授权失败,所以需要进数据库对当前用户授权

  • 从控制台进入mysql

    GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
    
  • 刷新权限表

    FLUSH PRIVILEGES;
    
阅读更多

新建SpringBoot项目报错

📅 2021-09-13 10:42 👁️ 195 💬 0

新建一个Springboot项目时,当勾选了SQL相关的依赖(如引入了jpa 或MyBatis依赖),直接启动项目时报错

image-20210912120159945

原因:没有配置数据库相关的属性,如 url driver 等

解决办法:在application.properties 中设置数据库链接的相关属性

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
阅读更多

MySQL报错 SQL ERROR:1064 ,SQLState:42000

📅 2021-09-10 09:36 👁️ 923 💬 0

使用mysql新增数据时报错,具体信息如图所示:

错误原因:
所建的表中 表名或字段名与数据库关键字冲突

解决办法
可以根据报错信息,查看错误的具体位置,找到数据库中对应的字段,查询是否与关键字(不分大小写)一样,如果一样需要进行修改

阅读更多

PicGo+Typora配置gitee图床

📅 2021-08-05 09:35 👁️ 115 💬 0

1 、下载Typora

Typora官网地址:https://www.typora.io/#windows

本文使用的Typora版本为 0.11.2

image-20210728101754216

根据自己的要求进行安装即可!

2、下载PicGo

GitHub地址为:https://github.com/Molunerfinn/PicGo/releases/tag/v2.3.0-beta.6

在页面最下有下载链接

image-20210728102049832

根据自己的要求进行安装即可!

本文PicGo版本为:2.3.0-beat.6

3、下载node.js (安装插件时需要使用)

nodejs官网下载地址:https://nodejs.org/en/download/)

安装教程可参考菜鸟教程:Node.js 教程 | 菜鸟教程 (runoob.com)

注意:菜鸟教程中的第五步,可以选择第二选项,其他照旧

image-20210728102833498

4、安装gitee插件

打开PicGo--->插件设置----->搜索gitee---->安装gitee插件

image-20210728103134436

注意:如果没有安装nodejs,这一步也会提示安装的,所以nodejs 是必需的

5、gitee创建仓库

注册账号后登录gitee,注册仓库即可

image-20210728105201365

6、生成私人令牌

image-20210728105306367

image-20210728105329341

image-20210728105344373

image-20210728105357413

7、PicGo配置

image-20210728105526980

owner:拥有者

repo:仓库名

path:网址路径

token:私人令牌

8、Typora配置

文件-->偏好设置--->图像--->上传服务设定

image-20210728105847880

9 、踩坑记录 2021-12-09

  1. gitee仓库必须是公开的,不然所有图片都访问不了
  2. 上传失败的话,可能是 文件名称重复,可以换个名试试
阅读更多
点击右上角即可分享
微信分享提示