Decorative image frame

解决maven依赖问题

起因

由于项目比较老,下载下来以后,发现maven依赖好多找不到了。找同事要了包,放到了对应的本地仓库目录下还是不行。
报错信息如下

1
Could not find artifact com.github.everit-org.json-schema:org.everit.json.schema:pom:1.11.1 in aliyunmaven (https://maven.aliyun.com/repository/public)

解决办法

  1. 删除本地仓库中的包
  2. 使用命令将依赖安装到本地仓库
    1
    2
    mvn install:install-file -Dfile=path/to/your/jar/file.jar -DgroupId=com.github.everit-org.json-schema -DartifactId=org.everit.json.schema -Dversion=1.11.1 -Dpackaging=jar

  3. 打开idea刷新mavne依赖,发现已经正常了

ubuntu格式化硬盘并挂载

1
2
3
4
sudo fdisk -l

sudo fdisk /dev/vdb

选择n新建分区,选择p主分区,选择1,回车确认默认起始扇区,回车确认默认结束扇区,输入+200G,回车确认格式化,输入w保存并退出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x29c5f384.

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-419430399, default 419430399):

Created a new partition 1 of type 'Linux' and of size 200 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

将分区进行格式化

1
sudo mkfs.ext4 /dev/vdb1

创建挂载目录,并将分区挂载到目录

1
2
sudo mkdir /mnt/vdb
sudo mount /dev/vdb1 /mnt/vdb

上面挂载是临时的,重启后会失效,需要修改fstab文件,开启自动挂载

1
echo '/dev/vdb1 /mnt/vdb ext4 defaults 0 0' | sudo tee -a /etc/fstab

mysql log迁移

记录一次mysql log迁移经理

系统:Ubuntu18.04.6
mysql版本:mysql5.7

停止mysql服务

1
systemctl stop mysql.service

复制文件到新目录

1
2
3
sudo mkdir /data/log/mysql
sudo chown mysql:adm /data/log/mysql
sudo cp /var/log/mysql/* /data/log/mysql

修改配置文件/etc/mysql/mysql.conf.d/mysqld.cnf,找到log的相关的配置修改目录

1
2
3
log_error = /data/log/mysql/error.log
slow_query_log_file = /data/log/mysql/mysql-slow.log
log_bin = /var/log/mysql/mysql-bin.log

修改启动文件/etc/apparmor.d/usr.sbin.mysqld添加以下配置

1
2
3
4
/data/log/mysql.err rw,
/data/log/mysql.log rw,
/data/log/mysql/ r,
/data/log/mysql/** rw,

重启服务

1
2
systemctl restart apparmor
systemctl start mysql.service

springboot整合jasypt加密数据库配置

项目中会遇到数据库名称和密码需要加密防止泄露的需求,因此引入了jasypt。下面的例子是将jasypt的加密密钥写在了配置文件中,为了安全,实际引用时,需要将配置放到服务器的启动命令中,避免在代码中暴露密钥

1.引入maven依赖jasypt-spring-boot-starter

1
2
3
4
5
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>

2.启动类添加注解@EnableEncryptableProperties

1
2
3
4
5
6
7
8
9
10
11
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableEncryptableProperties
public class AdminMain {

public static void main(String[] args) {
SpringApplication.run(AdminMain.class, args);
}
}

阅读全文...

jar包运行参数配置

三种jar包启动时传参的方式

  1. jvm传值 -Dkey_name=value
    这种方式已 -D开头,放在jar包之前

    1
    java  -Ddatabasename=test  -jar  test.jar
  2. 给main函数传值 key_name=value

    1
    java  -jar  test.jar databasename=test

    治理要求参数放在jar包之后,main方法中可以接收参数

    1
    2
    3
    4
    5
    public static void main(String[] args) throws IOException {
    for(String arg : args){
    log.info("参数:" + arg);
    }
    }
  3. 覆盖yaml或properties 文件参数 –key_name=value

    1
    java -jar tes.jar --logName=log.txt

    这里要求参数放在jar包之后用--开头,程序中可以使用@Value注解获取参数值

    1
    2
    @Value("${logName}")
    private String logName; //输出:log.txt

mysql root用户增加超级权限,解决无法给新建用户配置权限问题

mysql root用户通过外网登录数据库后,想要添加用户分配权限,结果发现不行。但是在服务器上通过localhost登录后可以配置。

原因是新增的root@%没有超级权限。只有个root@localhost才有。

解决方法是,使用root@localhost账户为root@%添加超级权限。

在服务器上使用mysql -u root -p登录,然后执行以下命令

1
2
UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;

这是通过mysql客户端工具,使用外网链接数据库就可以设置用户权限了

ubuntu18.4多版本php安装

安装php ppa源

1
2
3
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

老版本的12.4之前的ubuntu用下面的命令

1
2
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php

更新源

1
2

sudo apt-get update

安装对应的版本

比如安装7.0

1
2
sudo apt-get install -y php7.0