kk Blog —— 通用基础


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

CPU温控

常规调节

1
2
echo 72 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
echo 1  > /sys/devices/system/cpu/intel_pstate/no_turbo

参数解释

https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt

/sys/devices/system/cpu/intel_pstate/

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
      max_perf_pct: Limits the maximum P-State that will be requested by
      the driver. It states it as a percentage of the available performance. The
      available (P-State) performance may be reduced by the no_turbo
      setting described below.

      min_perf_pct: Limits the minimum P-State that will be requested by
      the driver. It states it as a percentage of the max (non-turbo)
      performance level.

      no_turbo: Limits the driver to selecting P-State below the turbo
      frequency range.

      turbo_pct: Displays the percentage of the total performance that
      is supported by hardware that is in the turbo range. This number
      is independent of whether turbo has been disabled or not.

      num_pstates: Displays the number of P-States that are supported
      by hardware. This number is independent of whether turbo has
      been disabled or not.

For example, if a system has these parameters:
	Max 1 core turbo ratio: 0x21 (Max 1 core ratio is the maximum P-State)
	Max non turbo ratio: 0x17
	Minimum ratio : 0x08 (Here the ratio is called max efficiency ratio)

Sysfs will show :
	max_perf_pct:100, which corresponds to 1 core ratio
	min_perf_pct:24, max_efficiency_ratio / max 1 Core ratio
	no_turbo:0, turbo is not disabled
	num_pstates:26 = (max 1 Core ratio - Max Efficiency Ratio + 1)
	turbo_pct:39 = (max 1 core ratio - max non turbo ratio) / num_pstates

Refer to "Intel庐 64 and IA-32 Architectures Software Developer鈥檚 Manual
Volume 3: System Programming Guide" to understand ratios.

There is one more sysfs attribute in /sys/devices/system/cpu/intel_pstate/
that can be used for controlling the operation mode of the driver:

      status: Three settings are possible:
      "off"     - The driver is not in use at this time.
      "active"  - The driver works as a P-state governor (default).
      "passive" - The driver works as a regular cpufreq one and collaborates
                  with the generic cpufreq governors (it sets P-states as
                  requested by those governors).
      The current setting is returned by reads from this attribute.  Writing one
      of the above strings to it changes the operation mode as indicated by that
      string, if possible.  If HW-managed P-states (HWP) are enabled, it is not
      possible to change the driver's operation mode and attempts to write to
      this attribute will fail.

https://huataihuang.gitbooks.io/cloud-atlas/os/linux/kernel/cpu/intel_pstate.html

http://www.litrin.net/2018/12/28/cpu%E7%9A%84%E7%94%B5%E6%BA%90%E7%8A%B6%E6%80%81%E5%88%86%E7%B1%BB/

ubuntu 16.04 & 18.04

删除snap,snap会自动更新,严重占带宽

1
2
3
4
5
6
7
8
snap list
sudo snap remove gtk-common-themes
...
sudo apt-get remove snapd

df -h | grep snap
sudo systemctl stop snap-core-6350.mount
sudo systemctl disable snap-core-6350.mount

ssh 保持连接

服务端

1
2
ClientAliveInterval 60
ClientAliveCountMax 1

SSH Server 每 60 秒就会自动发送一个信号给 Client,客户端没有回应数超过 ClientAliveCountMax 时,才会断开连接。

客户端

1
2
TCPKeepAlive yes
ServerAliveInterval 300

前一个参数是说要保持连接,后一个参数表示每过5分钟发一个数据包到服务器

命令行进行设定即:

1
ssh -o TCPKeepAlive=yes -o ServerAliveInterval=300 root@1.2.3.4

dns 命令

1
2
3
4
5
6
7
8
9
sudo apt-get install pppconfig
/etc/init.d/dns-clean

systemctl stop systemd-resolved
systemctl start systemd-resolved

systemd-resolve --statistics
systemd-resolve --status
systemd-resolve --flush-caches

代理设置

1
2
3
4
5
6
7
8
9
10
11
12
13
# cat /etc/apt/apt.conf
Acquire::https::Proxy "http://proxy.proxy.com:8080";
# err? http_proxy=http://proxy.proxy.com:8080
# err? https_proxy=http://proxy.proxy.com:8080

# cat /etc/environment
http_proxy=http://proxy.proxy.com:8080
https_proxy=http://proxy.proxy.com:8080
no_proxy=localhost,127.0.0.0/8,::1,*.pp.com,*.oa.com

# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.proxy.com:8080"

amdgpu.dc

VGA,DIV-D接口 4.15.0 以后内核黑屏,需要设置amdgpu.dc=0 HDMI,DP接口支持音频,需要设置amdgpu.dc=1

注释掉下面这行将会显示引导菜单

1
#GRUB_HIDDEN_TIMEOUT=0

设定默认启动项 /etc/default/grub

1
2
3
4
5
6
7
8
9
# 用数字
GRUB_DEFAULT=0

# 最近启动
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

# 指定内核
GRUB_DEFAULT="gnulinux-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b>gnulinux-4.15.0-55-generic-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b"

Warning: Please don’t use old title Ubuntu, with Linux 4.15.0-55-generic' for GRUB_DEFAULT, useAdvanced options for Ubuntu>Ubuntu, with Linux 4.15.0-55-generic' (for versions before 2.00) or `gnulinux-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b>gnulinux-4.15.0-55-generic-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b' (for 2.00 or later)

卸载amazon

1
2
3
4
5
# 16.04
sudo apt-get remove unity-webapps-common

# 18.04
sudo apt-get remove ubuntu-web-launchers

新立得

1
sudo apt-get install synaptic

禁用apport

1
2
/etc/default/apport
enabled=0

禁用service

1
2
3
4
5
6
7
8
9
# 禁用
sudo systemctl disable apport.service

# 如果这不起作用,那么您需要屏蔽该服务
systemctl mask apport.service

# 重新启用
systemctl unmask apport.service # if you masked it
sudo systemctl enable apport.service

中文输入法

1
2
3
sudo apt-get install ibus-pinyin
# 选择全拼模式,同时勾选“简拼”, 然后运行
sudo ibus restart

温度

1
2
3
4
sudo apt-get install lm-sensors hddtemp
sudo sensors-detect
sensors
sudo apt-get install psensor

查看SSD状态

https://www.cnblogs.com/fiberhome/p/8275961.html

1
2
3
4
5
6
7
8
hdparm -t --direct /dev/sda

smartctl -i /dev/sda

sudo smartctl -data -A /dev/sda
sudo smartctl -A /dev/sda

# 233一行的值就是寿命,默认为100,当小于10的时候就要非常注意了。

个人桌面系统可以加 noatime

1
2
3
4
vim /etc/fstab
增加 noatime

stat /etc/fstab

nvme硬盘温度

1
2
3
4
5
6
7
sudo apt-get install nvme-cli
sudo nvme list

sudo nvme smart-log /dev/nvme0
sudo watch -n 1 nvme smart-log /dev/nvme0

sudo nvme smart-log /dev/nvme0 | grep "^temperature"

SSD

1
2
3
4
5
Aggressive LPM Support功能是SATA口的节能电源管理,开启会导致SSD掉盘,不认盘,掉速等问题。

解决方法:

到BIOS中找到Aggressive LPM Support并关闭。

18.04 unity

1
2
3
4
5
6
sudo apt install ubuntu-unity-desktop
select lightdm

# 恢复gnome
sudo apt purge ubuntu-unity-desktop
sudo dpkg-reconfigure gdm3

18.04 用synergy1.6.2

https://packages.ubuntu.com/xenial/libcrypto++9v5

https://packages.ubuntu.com/xenial/synergy

synergy_1.6.2-0ubuntu2_amd64.deb

libcrypto++9v5_5.6.1-9ubuntu0.1_amd64.deb

发送arp请求报文

https://blog.51cto.com/13560258/2084527

https://blog.csdn.net/yldfree/article/details/83181283

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
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/ethernet.h>
#include <netpacket/packet.h>
#include <string.h>
#include <net/if.h>
 
#define SRC_MAC  { 0x00,0x0C,0x29,0x6F,0x57,0xE7 }//源MAC地址
#define DEST_MAC { 0x00,0x0C,0x29,0xD3,0xD6,0xF7 }//目的MAC地址
 
struct arppacket
{
	unsigned char dest_mac[ETH_ALEN];//接收方MAC
	unsigned char src_mac[ETH_ALEN];//发送方MAC
	unsigned short type;       //0x0806是ARP帧的类型值
	unsigned short ar_hrd;//硬件类型 - 以太网类型值0x1
	unsigned short ar_pro;//上层协议类型 - IP协议(0x0800)
	unsigned char  ar_hln;//MAC地址长度
	unsigned char  ar_pln;//IP地址长度
	unsigned short ar_op;//操作码 - 0x1表示ARP请求包,0x2表示应答包
	unsigned char  ar_sha[ETH_ALEN];//发送方mac
	unsigned char ar_sip[4];//发送方ip
	unsigned char ar_tha[ETH_ALEN];//接收方mac
	unsigned char ar_tip[4];//接收方ip
} __attribute__ ((__packed__));

int main(int argc,char *argv[])
{
	int fd = 0;
	struct in_addr s,r;
	struct sockaddr_ll sl;
 
	struct arppacket arp={
		DEST_MAC,
		SRC_MAC,
		htons(0x0806),
		htons(0x01),
		htons(0x0800),
		ETH_ALEN,
		4,
		htons(0x01),
		SRC_MAC,
		{0},
		DEST_MAC,
		{0}
	};
 
	fd = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
	if (fd < 0) {
		printf("socket error\n");
		return -1;
	}
	memset(&sl, 0, sizeof(sl));
 
	inet_aton("192.168.11.220", &s);
	memcpy(&arp.ar_sip, &s, sizeof(s));
 
	inet_aton("192.168.11.192", &r);
	memcpy(&arp.ar_tip, &r, sizeof(r));
 
 
	sl.sll_family = AF_PACKET;
	sl.sll_ifindex = IFF_BROADCAST;
	
	while (1) {
		if (sendto(fd, &arp, sizeof(arp), 0, (struct sockaddr*)&sl, sizeof(sl)) <= 0)
			printf("send error\n");
		else
			printf("send success\n");
 
		sleep(1);
	}
 
	close(fd);
 
	return 0;
}