1、yum源的優(yōu)化
CentOS base epel
?
自建yum倉庫
?
使用一個較為穩(wěn)定的倉庫
?
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
[epel]
name="huawei epel repo"
baseurl=https://repo.huaweicloud.com/epel/7/x86_64/
gpgcheck=0
2、系統主機名
1、hotnamectl
?
2、vim /etc/hostname
3、系統之間的域名解析
vim /etc/hosts
?
ip 主機名
4、關閉selinux和防火墻
1、臨時關閉
setenforce 0
?
2、永久關閉
vim /etc/selinux/config
systemctl disable --now firewalld
5、配置ntp時間同步
1、安裝ntp
yum install ntpdate
?
2、同步時間
?
ntpdate [時間服務器的地址]
?
ntp.aliyun.com
ntp.tuna.tsinghua.edu.cn
北斗 ---> 原子鐘
6、ulimit:設置系統開啟進程或者文件句柄數的
-n 最大文件句柄數
-u 最大進程數
永久修改 加大文件描述符與最大打開的進程數
cat >>/etc/security/limits.conf<<EOF
-
soft nofile 102400
-
hard nofile 102400
-
soft nproc 102400
-
hard nproc 102400 EOF
ELK elasticsearch ---> 65536 65535
import os import time from threading import Thread
print(os.getpid())
def task(n): with open('%s.txt' %n,mode='wt') as f1: time.sleep(1000) if name == "main": count=1 while True: Thread(target=task,args=(count,)).start() count+=1 time.sleep(3)
import os import time from threading import Thread
print(os.getpid())
def task(n): with open('shanhe%s.txt' %n,mode='wt') as f1: time.sleep(1000) if name == "main": count=1 while True: Thread(target=task,args=(count,)).start() count+=1 time.sleep(3)
7、最大PID數
1、臨時修改
echo 111111 > /proc/sys/kernel/pid_max
2、永久修改
echo "kernel.pid_max= 4194303" >> /etc/sysctl.conf
sysctl -p
8、調整內核參數
cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range = 4000 65000 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans = 16384 net.ipv4.ip_forward = 1 EOF
10、NetworkManager
在CentOS系統上,目前有NetworkManager和network兩種網絡管理工具。如果兩種都配置會引起沖突,而且NetworkManager在網絡斷開的時候,會清理路由,如果一些自定義的路由,沒有加入到NetworkManager的配置文件中,路由就被清理掉,網絡連接后需要自定義添加上去。
推薦
[root@localhost ~]# systemctl disable --now NetworkManager
11、禁ping
禁止主機被ping:echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
12、用戶提權sudo
當普通用戶臨時使用root用戶的權限時使用。
?
前提:
?
這個用戶必須在/etc/sudoer文件中添加權限
[root@localhost ~]# vim /etc/sudoers
oldboy01 ALL=(ALL) ALL
?
[oldboy01@localhost tmp]$ sudo vim a.txt
13、字符處理
sort命令
?
sort是排序的命令,默認使用第一個字符進行排序
?
-n # 依照數值的大小排序
[root@localhost ~]# cat 1.txt | sort -n
-r # 以相反的順序來排序
[root@localhost ~]# cat 1.txt | sort -n -r
-k # 以某列進行排序(默認的分隔符是空格)
[root@localhost ~]# cat 2.txt | sort -n -k2
-t # 指定分割符,默認是以空格為分隔符
[root@localhost ~]# cat 3.txt | sort -n -k2 -t:
uniq 命令(去重,默認只去重相鄰的數據)
?
[root@localhost ~]# cat 1.txt | sort -n | uniq
?
-c # 在每列旁邊顯示該行重復出現的次數。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c
-d # 僅顯示重復出現的行列。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c -d
-u # 僅顯示出一次的行列。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c -u
?
cut 命令(分割字符)
?
cut分割字符有局限性。
?
-d # 指定字段的分隔符,默認的字段分隔符為"TAB";
[root@localhost ~]# cut -d: -f1 3.txt
?
-f # 顯示指定字段的內容
[root@localhost ~]# cut -d: -f3 /etc/passwd
tr命令(替換字符)
?
[root@localhost ~]# cat 3.txt | tr "123" "abc"
?
-d # 刪除字符
[root@localhost ~]# cat 3.txt | tr -d "456"
?
wc命令(統計字符)
?
-c # 統計文件的Bytes數
[root@localhost ~]# cat 3.txt | wc -c
-l # 統計文件的行數
[root@localhost ~]# cat 3.txt | wc -l
-w # 統計文件中單詞的個數,默認以空白字符做為分隔符
[root@localhost ~]# cat 3.txt | wc -w
14、時間
案例1:要求打印當前時間 :2021-3-3 00:00:00
?
[root@localhost ~]# date +"%Y-%m-%d %H:%M:%S"
[root@localhost ~]# date +"%F %H:%M:%S"
案例2:設置本機的時間
date -s ""
cp /usr/share/zoneinfo/America/New_York /etc/localtime
浙公網安備 33010602011771號