三湘古邑

我想在那里最蓝的大海扬帆。

0%

1
tar cf - win11.qcow2 2> /dev/null | xz -6T 12 - > wi11.qcow2.tar.xz

压缩比:6 线程数:12

拉取镜像

1
docker pull docker.bintray.io/jfrog/artifactory-oss

启动

1
docker run --name artifactory -d -v artifactory_data:/var/opt/jfrog/artifactory -p 8082:8082  -p 8081:8081 docker.bintray.io/jfrog/artifactory-oss

默认用户密码:admin/password

新建docker-compose.yml文件

新建目录:openvpn-data/conf

1
2
3
4
5
6
7
8
9
10
11
12
version: '2'
services:
openvpn:
cap_add:
- NET_ADMIN
image: kylemanna/openvpn
container_name: openvpn
ports:
- "1194:1194/udp"
restart: always
volumes:
- ./openvpn-data/conf:/etc/openvpn

生成配置文件

1
docker-compose run --rm openvpn ovpn_genconfig -u udp://192.168.1.8

192.168.1.8可以换成自己的外网IP或域名

初始化证书

1
docker-compose run --rm openvpn ovpn_initpki

Enter New CA Key Passphrase: 123456
Common Name (eg: your user, host, or server name) [Easy-RSA CA]: 输入 hlooc
Enter pass phrase for /etc/openvpn/pki/private/ca.key: 123456

启动服务端服务

1
docker-compose up -d openvpn

注册用户

1
docker-compose run --rm openvpn easyrsa build-client-full hlooc

Enter PEM pass phrase: 234567
Verifying - Enter PEM pass phrase:234567
Enter pass phrase for /etc/openvpn/pki/private/ca.key: 123456(注意要与服务端密码一致)

导出ovpn文件

1
docker-compose run --rm openvpn ovpn_getclient hlooc > hlooc.ovpn

注销用户

1
docker-compose run --rm openvpn ovpn_revokeclient hlooc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
DROP PROCEDURE IF EXISTS `insert_hlooc`$$

CREATE DEFINER=`hlooc`@`%` PROCEDURE `insert_hlooc`(IN max_num INT(10))
BEGIN
DECLARE bbb VARCHAR(100) DEFAULT '我是谁';
DECLARE i INT DEFAULT 0;
SET autocommit = 0;
REPEAT
SET i = i + 1;
SET c1 = CONCAT(bbb,LPAD(i,6,'0'));

INSERT INTO `hlooc` (xxx) values(xxx);

IF MOD(i,10000)=0 THEN
COMMIT;
END IF;

UNTIL i = max_num
END REPEAT;
COMMIT;
END$$

DELIMITER ;

使用了CONCATLPAD函数

LPAD函数

1
LPAD(str,len,padstr)

返回字符串str,将其左填充字符串padstr至len个字符的长度。 如果str大于len,则返回值缩短为len个字符。

CONCAT

CONCAT函数用于连接两个字符串以形成单个字符串

1
2
3
4
5
6
7
mmysql> SELECT CONCAT('FIRST ', 'SECOND');
+----------------------------+
| CONCAT('FIRST ', 'SECOND') |
+----------------------------+
| FIRST SECOND |
+----------------------------+
1 row in set (0.00 sec)

systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之
分,需要开机不登陆就能运行的程序,存在系统服务里,即:/usr/lib/systemd/system目录下.
每一个服务以.service结尾,一般会分为3部分:[Unit][Service][Install]

[Unit]

部分主要是对这个服务的说明,内容包括Description和After,Description 用于描述服务,
After用于描述服务类别
[Service]部分是服务的关键,是服务的一些具体运行参数的设置.
Type=forking是后台运行的形式,
User=users是设置服务运行的用户,
Group=users是设置服务运行的用户组,
PIDFile为存放PID的文件路径,
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令,
PrivateTmp=True表示给服务分配独立的临时空间

[Service]

注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报
错!

[Install]

[Install]部分是服务安装的相关设置,可设置为多用户的
首先,使用systemctl start [ 服务名(也是文件名) ] 可测试服务是否可以成功运行,如果不能运行 则可以使用systemctl status [ 服务名(也是文件名) ]查看错误信息和其他服务信息,然后根据报
错进行修改,直到可以start,如果不放心还可以测试restart和stop命令。
接着,只要使用systemctl enable xxxxx就可以将所编写的服务添加至开机启动即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[Unit]
Description=springboot webapp
After=springboot-webapp.service

[Service]
WorkingDirectory=/home/hlooc/app/springboot-webapp
Type=forking
Environment="JAVA_HOME=/home/hlooc/app/jdk1.8.0_202"
Environment="PATH=/home/hlooc/app/jdk1.8.0_202/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/hlooc/.local/bin:/home/hlooc/bin"
Environment="CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar"
User=hlooc
Group=hlooc
PIDFile=/home/hlooc/app/springboot-webapp/upp.pid
ExecStart=/home/hlooc/app/springboot-webapp/start.sh
ExecStop=/home/hlooc/app/springboot-webapp/stop.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

服务操作

添加可执行权限:

1
chmod 754 /usr/lib/systemd/system/springboot-webapp.service

设置为开机自启动:
1
systemctl enable springboot-webapp.service

常用指令(以springboot-webapp服务为例):
启动某服务
1
systemctl start springboot-webapp.service

停止某服务
1
systemctl stop springboot-webapp.service

重启某服务
1
2
service springboot-webapp restart
systemctl restart springboot-webapp.service

使某服务自动启动(如springboot-webapp服务)
1
systemctl enable springboot-webapp.service

使某服务不自动启动
1
systemctl disable springboot-webapp.service

检查服务状态
1
2
systemctl status springboot-webapp.service (服务详细信息)
systemctl is-active springboot-webapp.service(仅显示是否Active)

显示所有已启动的服务
1
systemctl list-units --type=service

Cabllable实现龟兔赛跑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cn.hlooc;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class RaceTest implements Callable<String> {

private final Runner runner;

public RaceTest(Runner runner) {
this.runner = runner;
}

@Override

public String call() {
return runner.raceRun();
}

}

interface Runner {

String raceRun();
}

class Winner {

private static String win;

public static void setWinner(String name) {

if (win == null) {
win = name;
System.out.println(name + " is Winner.");
}

}


public static String getWinner() {
return win;
}

}

class Rabbit implements Runner {

@Override
public String raceRun() {
String name = Rabbit.class.getSimpleName();
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name + ": Run " + i + " step.");
}
Winner.setWinner(name);
return name;
}
}

class Tortoise implements Runner {

@Override
public String raceRun() {
String name = Tortoise.class.getSimpleName();
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name + ": Run " + i + " step.");
}
Winner.setWinner(name);
return name;
}
}

class M {

public static void main(String[] args) {
List<Runner> runnerList = new ArrayList<>(2);
runnerList.add(new Rabbit());
runnerList.add(new Tortoise());
ExecutorService es = Executors.newFixedThreadPool(2);
List<Future<String>> fs = new ArrayList<>();
runnerList.forEach(runner -> fs.add(es.submit(new RaceTest(runner))));
es.shutdown();
fs.forEach(future -> {
try {
System.out.println(future.get() + " has done.");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

使用语法

1
2
qemu-img convert -f <原格式> -O <目标格式> <原文件路径> <目标文件路径> 
这里 -f <原格式>可以忽略。qemu-img会自动识别

vmdk与qcow2互转
1
2
3
qemu-img convert -O qcow2 test.vmdk test.qcow2
#qcow2转vmdk
qemu-img convert -O vmdk test.qcow2 test.vmdk

vdi转qcow2
1
qemu-img convert -O qcow2 test.vdi test.qcow2

vhd&vhdx转qcow2
1
qemu-img convert -O qcow2 test.vhdx test.qcow2

RAW转qcow2
1
qemu-img convert -O qcow2 test.raw test.qcow2

img转qcow2
1
qemu-img convert -O qcow2 test.img test.qcow2

Runnable实现龟兔赛跑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class RaceTest implements Runnable {

private static String winner = null;

@Override
public void run() {
for (int i = 1; i <= 101; i++) {
boolean flag = gameOver(i);
if (flag) {
break;
}
if(Thread.currentThread().getName().equalsIgnoreCase("Rabbit")){
try {
Thread.sleep(10);//兔子睡觉了zzzz
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName() + "Run " + i + " step.");
}
}

private boolean gameOver(int steps) {
if (winner != null) {
return true;
} else {
if (steps >= 100) {
winner = Thread.currentThread().getName();
System.out.println("Winner is: " + winner);
return true;
}
}
return false;
}
}

class M {

public static void main(String[] args) {
RaceTest raceTest = new RaceTest();
new Thread(raceTest, "Rabbit").start();
new Thread(raceTest, "Tortoise").start();

}
}

linux下使用dd命令复制磁盘

1
# dd if=/dev/sdc of=/dev/sdd bs=2M status=progress

设置文件编码为新编码

1
:set fileencoding=utf-8

又或者

1
:set fenc=utf-8

去掉utf-8 BOM

1
:set nobomb  

保留utf-8 BOM

1
:set bomb 

以16进制模式打开文件

1
:%!xxd

将以16进制格式打开的文件返回文本模式编辑

1
:%!xxd -r