kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

硬盘安装windows及MBR、grub修复

硬盘安装win7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mount -o loop win7.iso /mnt
mount -t ntfs /dev/sda3 /tmp/kk
cp -r /mnt/* /tmp/kk/
umount /tmp/kk

reboot

https://askubuntu.com/questions/254491/failed-to-get-canonical-path-of-cow
重启后来到 grub 的引导菜单,按 c 键进入命令行模式:
grub> set root=(hd1,2)
grub> insmod ntfs
grub> ntldr /bootmgr
grub> boot

注意:

  1. 起因:从 u盘 安装极其缓慢,为什么???

  2. 从 /dev/nvmessd 的grub进入没有 ntldr 命令 ???

  3. 从 /dev/sda2 的grub进入有 ntldr 命令

  4. 技嘉主板先制作usb启动盘,加入技嘉驱动 http://download.gigabyte.cn/FileList/Utility/mb_utility_windowsimagetool.zip 方法:http://www.gigabyte.cn/WebPage/-79/usb.html 。再从u盘 cp * /tmp/kk/

修复MBR、grub

从ubuntu u盘执行:

1
2
3
4
5
mkdir /mnt
mount /dev/sda2 /mnt
cd /mnt

grub-install --recheck --root-directory=/mnt /dev/sda 

注意:

  1. ubuntu系统的 grub-install 64位的不能执行??? u盘中的grub-install i386可以执行???

  2. 临时进系统方法:

1
2
3
4
5
6
insmod linux
ls
root=(hd0,1)
linux /boot/vmlinuz root=/dev/sda1
initrd /boot/initrd
boot
1
2
3
4
# win7
set root=(hd0,1)
chainloader +1
boot

nginx ipv6、TCP_DEFER_ACCEPT

curl 7.61.1

curl 7.61.1

TCP_DEFER_ACCEPT

1
2
3
server {
	listen  80 deferred;
	...

deferred instructs to use a deferred accept() (the TCP_DEFER_ACCEPT socket option) on Linux.

ipv6

1
2
3
server {
	listen  [::]:8080; # ipv6only=on;
	...

ipv6only=on|off this parameter (0.7.42) determines (via the IPV6_V6ONLY socket option) whether an IPv6 socket listening on a wildcard address [::] will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start.

Prior to version 1.3.4, if this parameter was omitted then the operating system’s settings were in effect for the socket.

IPv6 socket

https://blog.csdn.net/u013401853/article/details/55002655

server_ip6.c

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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

#define BUF_LEN 2048
#define PORT 8080

int main(int argc, char *argv[])
{
	int serv_sock = -1, client_sock = -1;
	socklen_t addr_len = 0;
	struct sockaddr_in6 local_addr = {0}, client_addr = {0};
	char buf[BUF_LEN] = {0};
	int err = -1;

	/* 建立socket */
	serv_sock = socket(PF_INET6, SOCK_STREAM, 0);
	if (-1 == serv_sock) {
		perror("socket error: ");
		return -1;
	}

	/* 填充地址结构 */
	local_addr.sin6_family = AF_INET6;
	local_addr.sin6_port = htons(PORT);
	local_addr.sin6_addr = in6addr_any;

	/* 绑定地址 */
	err = bind(serv_sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in6));
	if (-1 == err) {
		perror("bind error: ");
		close(serv_sock);
		return -1;
	}

	/* 监听 */
	err = listen(serv_sock, 5);
	if (-1 == err) {
		perror("listen error: ");
		close(serv_sock);
		return -1;
	}

	/* 循环等待客户连接请求 */
	while (1) {
		memset(&client_addr, 0x0, sizeof(client_addr));
		addr_len = sizeof(struct sockaddr_in6);
		client_sock = accept(serv_sock, (struct sockaddr *)&client_addr, &addr_len);
		if (-1 == client_sock) {
			perror("accept error:");
			close(serv_sock);
			return -1;
		}

		/* 转换client地址为字符串并打印 */
		inet_ntop(AF_INET6, &client_addr.sin6_addr, buf, BUF_LEN);
		printf("A clinet connected, ip: %s, port %d\n", buf, ntohs(client_addr.sin6_port));

		/* 接收消息 */
		memset(buf, 0x0, BUF_LEN);
		err = recv(client_sock, buf, BUF_LEN, 0);
		if (err < 0) {
			perror("recv error:");
			close(serv_sock);
			close(client_sock);
			return -1;
		}
		printf("recv %d bytes: %s\n", err, buf);

		/* 回送消息 */
		err = send(client_sock, buf, strlen(buf), 0);
		if (err < 0) {
			perror("send error:");
			close(serv_sock);
			close(client_sock);
			return -1;
		}

		/* 关闭这个client连接 */
		close(client_sock);
	}
	return 0;
}

client_ip6.c

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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

#define BUF_LEN 2048
#define PORT 8080

int main(int argc, char *argv[])
{
	int sock = -1;
	socklen_t addr_len = 0;
	struct sockaddr_in6 serv_addr = {0};
	char buf[BUF_LEN] = {0};
	int err = -1;

	/* 建立socket */
	sock = socket(AF_INET6, SOCK_STREAM, 0);
	if (-1 == sock) {
		perror("socket error: ");
		return -1;
	}

	memset(&serv_addr, 0x0, sizeof(serv_addr));
	/* 填充地址结构 */
	serv_addr.sin6_family = AF_INET6;
	serv_addr.sin6_port = htons(PORT);

	//serv_addr.sin6_addr = in6addr_loopback;  /* 连接到环回地址 */

	//inet_pton(AF_INET6, "2002:da80:e000::1:1:9", &serv_addr.sin6_addr);

	//inet_pton(AF_INET6, "::ffff:c0a8:0208", &serv_addr.sin6_addr);
	//inet_pton(AF_INET6, "::c0a8:0205", &serv_addr.sin6_addr);

	// connect到链路本地地址,需要设置sin6_scope_id,用`ip addr show`获取
	serv_addr.sin6_scope_id = 2;
	inet_pton(AF_INET6, "fe80::a00:27ff:fea0:67d6", &serv_addr.sin6_addr);

	addr_len = sizeof(serv_addr);
	err = connect(sock, (struct sockaddr *)&serv_addr, addr_len);
	if (-1 == err) {
		perror("connect error:");
		close(sock);
		return -1;
	}

	/* 发送消息 */
	memset(buf, 0x0, BUF_LEN);
	snprintf(buf, BUF_LEN - 1, "hello server, I'm client\n");
	err = send(sock, buf, strlen(buf), 0);
	if (err < 0) {
		perror("send error:");
		close(sock);
		return -1;
	}

	/* 接收消息 */
	memset(buf, 0x0, BUF_LEN);
	err = recv(sock, buf, BUF_LEN, 0);
	if (err < 0) {
		perror("recv error:");
		close(sock);
		return -1;
	}
	printf("recv %d bytes: %s\n", err, buf);

	close(sock);

	return 0;
}