三湘古邑

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

0%

启动docker

1
docker service start

停止docker

1
docker service stop

重启docker

1
docker service restart
  • 添加docker用户组:sudo groupadd docker
  • 将登陆用户加入到docker用户组中:sudo gpasswd -a $USER docker
  • 更新用户组:newgrp docker
  • 测试docker命令是否可以使用sudo正常使用:docker ps

Python学习笔记

斐波那契数列实验

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
x = int(input('请输入一个数字: '))
def test():
n1 = 0
n2 = 1
counter = 0
list = [n1,n2]
while counter < x :
nth = n1 + n2
n1 = n2
n2 = nth
counter +=1
list.append(nth)
print(list)

test()

def test1():
n1,n2=0,1
list = [n1,n2]
for i in range(0,x):
nth = n1 +n2
n1 = n2
n2 = nth
list.append(nth)
#print(nth)
print (list)

test1()

SpringBoot仿Zuul报文转发

基于RestTemplaterequest中提取出headerbody等内容,构造一个RequestEntity,后续可以用RestTemplate来发送请求

请求入口RestController

1
2
3
4
5
6
7
8
9
10
11
public final static String DELEGATE_PREFIX = "/api";

public final static String TARGET_URL = "http://hlooc.cn";

@Autowired
private RoutingDelegate routingDelegate;

@RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE}, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity catchAll(HttpServletRequest request, HttpServletResponse response) {
return routingDelegate.redirect(request, response, TARGET_URL, DELEGATE_PREFIX);

报文处理RoutingDelegate

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
    private static final Logger logger = LoggerFactory.getLogger(RoutingDelegate.class);


public ResponseEntity<String> redirect(HttpServletRequest request, HttpServletResponse response,String routeUrl, String prefix) {
try {
// build up the redirect URL
String redirectUrl = createRedictUrl(request,routeUrl, prefix);
RequestEntity requestEntity = createRequestEntity(request, redirectUrl);
return route(requestEntity);
} catch (Exception e) {
logger.error("处理异常:{}",e.getLocalizedMessage(),e);
return new ResponseEntity("REDIRECT ERROR", HttpStatus.INTERNAL_SERVER_ERROR);
}
}

private String createRedictUrl(HttpServletRequest request, String routeUrl, String prefix) {
String queryString = request.getQueryString();
return routeUrl + request.getRequestURI().replace(prefix, "") +
(queryString != null ? "?" + queryString : "");
}


private RequestEntity createRequestEntity(HttpServletRequest request, String url) throws URISyntaxException, IOException {
String method = request.getMethod();
HttpMethod httpMethod = HttpMethod.resolve(method);
MultiValueMap<String, String> headers = parseRequestHeader(request);
byte[] body = parseRequestBody(request);
return new RequestEntity<>(body, headers, httpMethod, new URI(url));
}

private ResponseEntity route(RequestEntity requestEntity) {
RestTemplate restTemplate = new RestTemplate();
// 乱码处理
// List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
// for (HttpMessageConverter<?> messageConverter : messageConverters) {
// if (messageConverter instanceof StringHttpMessageConverter) {
// ((StringHttpMessageConverter) messageConverter).setDefaultCharset(StandardCharsets.UTF_8);
// }
// }
return restTemplate.exchange(requestEntity, Resource.class);
}


private byte[] parseRequestBody(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
return StreamUtils.copyToByteArray(inputStream);
}

private MultiValueMap<String, String> parseRequestHeader(HttpServletRequest request) {
HttpHeaders headers = new HttpHeaders();
List<String> headerNames = Collections.list(request.getHeaderNames());
for (String headerName : headerNames) {
List<String> headerValues = Collections.list(request.getHeaders(headerName));
for (String headerValue : headerValues) {
headers.add(headerName, headerValue);
}
}
return headers;
}

restTemplate.exchange(requestEntity, Resource.class);使用Resource可以解决以下异常:

1
2
Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [application/octet-stream;charset=GBK]

下载安装镜像,使用安装镜像启动系统后执行如下命令

UEFI启动

本地磁盘使用GPT分区

1
2
3
4
5
6
#fdisk /dev/sdx
mkfs.vfat -F32 /dev/sdx1 #以vfat方式创建efi
mkfs.ext4 /dev/sdx2 #以ext4方式格式化磁盘/dev/sda的/dev/sda1分区
#mount /dev/sdxx /mnt
#mount /dev/sdxx /mnt/boot/EFI
#genfstab -U -p /mnt >> /mnt/etc/fstab

第一句就是将原来系统的根目录所在分区挂载到livecd的/mnt中,第二句是将原来系统
/boot目录所在分区挂载到livecd的/mnt/boot/EFI,这两句的先后顺序不能换。第三句往后直接照抄
就行,这几句都是挂载目录,为一会儿的在livecd中使用原来系统做准备。以上命令输完之后输入
下一条命令:
1
#arch-chroot /mnt

重新执行grub-installgrub-mkconfig
1
2
3
grub-install /dev/sdx
grub-install --target=x86-64-efi --efi-directory=/boot/EFI --bootloader-id=ArchLinux
grub-mkconfig -o /boot/grub/grub.cfg

BIOS启动

本地磁盘使用DOS分区

1
2
3
4
5
6
#fdisk /dev/sdx
mkfs.vfat -F32 /dev/sdx1 #以vfat方式创建efi
mkfs.ext4 /dev/sdx2 #以ext4方式格式化磁盘/dev/sda的/dev/sda1分区
#mount /dev/sdxx /mnt
#mount /dev/sdxx /mnt/boot
#genfstab -U -p /mnt >> /mnt/etc/fstab

第一句就是将原来系统的根目录所在分区挂载到livecd的/mnt中,第二句是将原来系统
/boot目录所在分区挂载到livecd的/mnt/boot,这两句的先后顺序不能换。第三句往后直接照抄
就行,这几句都是挂载目录,为一会儿的在livecd中使用原来系统做准备。以上命令输完之后输入
下一条命令:
1
#arch-chroot /mnt

重新执行grub-installgrub-mkconfig
1
2
# grub-install --target=i386-pc --recheck /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg

如果分区格式有变化,需重现安装内核模块,在执行grub-installgrub-mkconfig

1
pacman -S linux linux-headers

ubuntu重新安裝grub

启动系统并挂载设备

1
2
3
4
5
6
7
sudo fdisk -l 
sudo mount /dev/sdan /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt

安装grub

1
2
3
4
grub-install /dev/sda
update-grub
update-initramfs -u -k all
exit

卸载设备重启

1
2
3
4
5
6
sudo umount /dev/pts
sudo umount /dev
sudo umount /proc
sudo umount /sys
sudo umount /dev/sdan
sudo reboot

格式话U盘

挂载U盘

1
sudo mount /dev/sdc1 /mnt -o uid=$USER,gid=$USER
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
# path to the partition holding ISO images (using UUID)
probe -u $root --set=rootuuid
set imgdevpath="/dev/disk/by-uuid/$rootuuid"

# define globally (i.e outside any menuentry)
insmod search_fs_uuid
search --no-floppy --set=isopart --fs-uuid $rootuuid
insmod all_video

menuentry "Archlinux-x86_64.iso" {
echo 'Loading ArchLinux Installer ...'
set isofile=/boot/iso/archlinux-2021.03.01-x86_64.iso
loopback loop ($isopart)$isofile
linux (loop)/arch/boot/x86_64/vmlinuz-linux archisolabel=$isolabel img_dev=$imgdevpath img_loop=$isofile
echo 'Loading initial ramdisk ...'
initrd (loop)/arch/boot/x86_64/initramfs-linux.img
}

menuentry "OMV 64bit ISO" {
echo 'Loading openmediavault Installer ...'
set isofile=/boot/iso/openmediavault_5.5.11-amd64.iso
loopback loop ($isopart)$isofile
linux (loop)/install/vmlinuz vga=normal quiet
echo 'Loading initial ramdisk ...'
initrd (loop)/install/initrd.gz
}

menuentry "Ubuntu Server 64bit ISO" {
echo 'Loading Ubuntu Server Installer ...'
set isofile=/boot/iso/ubuntu-20.10-live-server-amd64.iso
loopback loop ($isopart)$isofile
linux (loop)/casper/vmlinuz quiet ---
echo 'Loading initial ramdisk ...'
initrd (loop)/casper/initrd
}

menuentry "Proxmox-ve ISO" {
echo 'Loading Proxmox VE Installer ...'
set isofile=/boot/iso/proxmox-ve_6.3-1.iso
loopback loop ($isopart)$isofile
linux (loop)/boot/linux26 quiet splash=silent
echo 'Loading initial ramdisk ...'
initrd (loop)/boot/initrd.img
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
February 23, 2022
3:06 PM
shadow.service: Deactivated successfully.
3:06 PM
Started Verify integrity of password and group files.
8:40 AM
shadow.service: Failed with result 'exit-code'.
8:40 AM
shadow.service: Main process exited, code=exited, status=1/FAILURE
8:40 AM
'hlooc' is a member of the 'vboxusers' group in /etc/group but not in /etc/gshadow
8:40 AM
pwck:无改变
8:40 AM
用户“ntp”:目录 /var/lib/ntp 不存在
8:40 AM
Started Verify integrity of password and group files.

执行以下命令自动修复

1
sudo grpconv

FTP说明

ftp本身不提供目录下载命令,不管get还是mget都只能下载文件,区别在于mget可以下载多个文件,而get只能下载单个文件

FTP下载download目录

1
wget ftp://192.168.4.8:21/test/download --ftp-user=ftp --ftp-password=ftp -r

FTP下载全部目录

1
wget ftp://192.168.4.8:21/* --ftp-user=ftp --ftp-password=ftp -r

*号不能丢,否则只能下载下来一个index索引文件

Callable实现龟兔赛跑

线程池使用的Executors.newFixedThreadPool(2)

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
package cn.hlooc;

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

public class RaceSimpleTest {

public static void main(String[] args) {
List<String> raceList = new ArrayList<>(2);
raceList.add("Rabbit");
raceList.add("Tortoise");

ExecutorService es = Executors.newFixedThreadPool(2);
List<Future<String>> ft = new ArrayList<>();
raceList.forEach(s -> ft.add(es.submit(new Race(s))));
es.shutdown();
ft.forEach(s -> {
try {
System.out.println(s.get() + " come on.");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

class Race implements Callable<String> {

static String winner = "";

String name;

public Race(String name) {
this.name = name;
}

@Override
public String call() throws Exception {

for (int i = 0; i < 100; i++) {
//Rabbit want to sleep.
if (name.equalsIgnoreCase("Rabbit") && i == 88) {
Thread.sleep(100);
}
System.out.println(name + " run " + i + " step.");
if (i == 99 && winner.isEmpty()) {
winner = name;
}
}
System.out.println(name + ",Game is over,Winner is " + winner);
return name;
}
}