菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
330
0

zxc

原创
05/13 14:22
阅读数 99145

/boot/config-内核版本.x86_64为内核编译时的配置文件
grep -i --context 10 'IPVS' /boot/config.........
CONFIG_IP_VS_PROTO_AH_ESP=y AH认证头 ESP有效载荷协议 IPSEC中概念 =y支持

ifconfig ens33 |grep 'broadcast'|tr -dc '[:digit:]. '|tr ' ' '\n'|grep -v '^$' 利用tr换行,grep删除多余空行

ifconfig ens33|grep 'ether'|tr -s ' '|cut -d' ' -f3 tr先压缩空格,后cut

^c 终止前台运行程序
^z 前台运行程序挂起到后台
^d 退出==exit
^r 搜索历史命令

glob通配符
[list] [a-z] [0-99]
[!list]
{string1,string2}

echo "$(ll)" ""保持输出格式

declare -x var == export var

ps auxf f等同于H

-n $var the length of string is nonzero 非空真
-z $var the length of string is zero 空真

-e exist -L symbolic -s exit && size>0 -S socket

[ $p == string ] [[ $p == string ]] 后面的不会报错,[[]]会避免很多逻辑错误

locale localectl echo $LANG

$(()) $[] expr let 中变量不能加""

date +%s 从 1970 年 1 月 1 日 00:00:00 UTC 到当前为为止的秒数
date +%S

RANDOM 0-32767 2^15-1

$((RANDOM%91+10)) $[$RANDOM%91+10]

/etc/rc.d/rc.local 设置全局开机启动选项

四种过滤空格和注释方法:
grep -v '^#\|^$' sudo.conf
grep -v -e '^#' -e '^$' sudo.conf

sed -e '/^#/d;/^$/d' sudo.conf

sed -e '/^#/d' -e '/^$/d' sudo.conf

sed -e '/^#\|^$/d' sudo.conf

还可使用管道


删除^M
tr -d '\r' < p > pp
tr -d '\015' < p > pp

cat p|tr -d '\r' > pp
cat p|tr -d '\015' > pp 此4种方法不能重名,否则称为空文件

sed 's/\r//g' p >pp
sed 's/^/添加的头部&/g;s/$/&添加的尾部/g'


scsi: target:
yum install scsi-target-utils
tgtadm --lld iscsi --mode target --op show
tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2020-01.mil.trait:s1.t1
tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb1
tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 1

tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.8.0/24
tgtadm --lld iscsi --mode target --op unbind --tid 1 --initiator-address 192.168.8.0/24

 

/etc/sysconfig/network
NETWORKING=yes
NETWOKKING_IPV6=yes
GATEWAY=192.168.8.2
HOSTNAME=
NISDOMAIN=
PEERDNS=nonzero


sshd_config 中开启 Banner /etc/issue.net ssh|telnet 远程登录显示 仅输出原始数据
printlastlog yes 默认开启,无此项,读取/var/log/lastlog
printmotd yes 默认关闭,读取/etc/motd

kali 开启root登录
PasswordAuthentication yes
PermitRootLogin yes

~/.ssh/config

Host *|*collate|collate
HostName ip|domain
User root|refrain
Port 22
IdentityFile ~/.ssh/id_rsa 此处为私钥

ssh保持session
/etc/ssh/ssh_config 添加 ServerAliveInterval 60 每隔60s向server发送一个空包保持连接

/etc/ssh/sshd_config
ClientAliveInterval 60
ClientAliveCountMax 100 总共发送100次空包

export TMOUT=86400
readonly TMOUT
Definition: TMOUT: If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive

PermitRootLogin yes
Use PAM yes
Password Authentication yes
PubkeyAuthentication yes
AuthorizedKeysfile ~/.ssh/authorized_keys

 


>& stdout 和 stderr 都重定向到 文件或fd(文件描述符)
0>&1 stdin重定向到stdout &用来区分文件和fd

awk中匹配 ~ !~ [[]] 中匹配 =~ !/quench/ 表示不匹配包含此正则的行
awk '27/jul/2017' log|awk '{ip[$1]++};END{ for(i in ip) { print i,ip[i]; } }' | sort -k2 -rn |head

 

scp 默认本地用户为当前用户, 当远程用户为非root用户时,只能往/home/drive(用户家目录)下拷贝,且属主属组为此用户

read 可以一次读取一行中的多个变量,以空格分隔

\(pp\)\{1,3\} \(\)用于regular expression中分组,还可用于后向引用 . [] [^] 都是单字符元字符 '^(p\|pp\|ppp)'

grep 支持 grep '^\(p\|pp\|ppp\)' () ? + {} 要发挥特殊含义需转义


pstree bash分两种 1)login生成的bash
2) sshd生成的bash


touch -a|m -t 201509090808.08 创建指定时间的文件

vim +/patter file :w! /path/to/file

相关属性设置: set number
set autoindent (ai)
hi string ctermfg=3
set nohlsearch
set smartindent
set ruler
set showmatch
syntax on
filetype on
set incsearch
set history=1000
hi type ctermfg=yellow
set nobackup
#set ignorecase
#set expandtab
set shiftwidth
set tabstop=4

[[ -e derive ]];echo $? 当derive为链接文件,测试的是derive所指向的文件存在性


cat >file <<-'END'
preponderance
END

mount -t proc proc /proc

cat /proc/filesystems 查看正在使用的文件系统
pidof -s crond

mkfs.ext4 系列文件 -m # 指定保留blocks比例 4882blocks (1.00%) reserved for super user
-b 1024(小文件多) 2048 4096 8192(大文件) 必须在格式化时指定
superblock backups stored on blocks: superblock 块组 每个元数据条目==一个inode(索引节点-inode_number)

df disk free -i --inodes list inodes information instead of block usage查看inode使用情况,只能查看磁盘,参数为目录,自动转换为目录
所在的block device

du --max-depth=0 == -s --inodes du -h --max-depth=1 /etc|sort -t' ' -k1 -nr

controller adapter

raid /proc/mdstat /dev/md[0-9]

watch --beep -n #(seconds) 'ifconfig eth0'

zip 压缩隐含压缩的根目录信息,解压出来一定是此目录(跟*.zip无关) zip -ry p /etc/* 压缩/etc目录 -r recursive -y no-dereference

for i in /etc/* dir -d /etc/* |xargs rm -rf

find ~ -maxdepth 1 -type f -not|! -iname '.*' 查找一级目录下的普通文件
find ~ -maxdepth 1 -type f -not|! -iname '.*' -print0|xargs -0 -n1 xargs -0 将\0(NULL)作为定界符

echo 1>/sys/block/sd[a-z]/device/delete 可删除磁盘

/sys/devices/virtual/block 虚拟的块设备 dm-0 loop0

cp -r /src/directory /dst 默认为--no-dereference,与cp文件不同
cp -s|--symbolic-link make symbolic-links instead of copying
cp src为多文件 dst一定为已经存在的目录
cp src为目录 结果一定是复制为一个目录,dst为文件报错,dst不存在的话,则dst的上级目录必须存在 dst存在,直接复制src为dst子目录

alias 依附于当前shell

ls /etc ls -d /etc ls -d /etc/*

标准输入 缺省输入 keyboard(文件描述符file descriptor 0)bash定义 cat
标准输出 monitor 1
标准错误输出 monitor 2
^H 0000 1000 8 0x8 BS 在最后不生效
zz^Hpp 大小为6 显示为zpp cat --show-all 显示为 zz^Hpp$

tr 只能从标准输入读数据,不能从文件读数据,不能带文件作为参数 cat 都可以 so tr < preamble cat preamble|tr

空文件没有分配block

directory的r权限缺失,导致无法ls,但是可以执行, / /bin/bash 及其依赖库权限都可导致su失败

mount -o loop *.iso /mnt

列出/下每个一级子目录文件数
for p in /*;do echo -e "$p:\t\t`find $p|wc --lines";done -e 开启转义后面必须有引号
for p in /*;do echo -n "$p ";find $p|wc --lines;done
把/etc目录下大于10k的文件复制到/tmp下
for i in $(ls -l /etc|awk '$5>10240 {print $9}');do cp -a /etc/$i /tmp;done
find /etc \( -type f -a -size +1M \) -exec cp -a {} /tmp \;

until commands;do commands;done 满足条件退出
C: do{
commands:
}while(不满足退出);

sed -n 's/r..t/&pppppp/gp' /etc/passwd

$OLDPWD $PWD

PATH give tacit consent to /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/root/bin

readlink -f| --canonicalize /usr/bin/awk ----> /usr/bin/gawk

hmac hash-based message authentication code 单向加密的延伸应用,网络通信中保证传输数据的完整性 为mac的一种

(⓿_⓿)配置多个固定ip chmod +x /etc/rc.d/rc.local ip addr add ip/prefix dev eth label eth:0 不可靠
IPADDR=ip1
NETMASK=
GATEWAY=

IPADDR1=
PREFIX1=
GATEWAY

IPADDR2=
PREFIX2=
GATEWAY=

第一个必须用NETMASK,否则无网关,其余必须用PREFIX#格式

②:设置多个网卡别名配置文件,GATEWAY如果附带DEFROUTE=yes(默认),则剩余无效
IPADDR=
PREFIX= 不能加#


virbr0 192.168.122.1 link/ether 52:54:00:xx:xx:xx
virbr0-nic link/ether 52:54:00:xx:xx:xx libvirt-daemon 在host上生成了virtual network switch,host上的虚拟机
通过virbr0连接
对于进程libvirtd <---libvirt-daemon
virsh <--- libvirt-client

virsh net-list
Name State Autostart
------------------------------------------
default active yes

virsh net-destroy default
Network default destroyed

virsh net-undefine default
Network default has been undefined

systemctl disable libvirtd
Removed symlink /etc/systemd/system/multi-user.target.wants/libvirtd.service.
Removed symlink /etc/systemd/system/sockets.target.wants/virtlockd.socket.
Removed symlink /etc/systemd/system/sockets.target.wants/virtlogd.socket.

systemctl mask libvirtd
Created symlink from /etc/systemd/system/libvirtd.service to /dev/null.

ipcs --limits show messages shared memory semaphore limits
ipcs --summary show status summary


sysctl --system read values from all system directories 读取系统预置目录的配置文件 /usr/lib/sysctl.d/*.conf
/etcsysctl.d/*.conf /etc/sysctl.conf

sysctl --all display all variables

sysctl --load
sysctl --write

/proc/sys/kernel/msgmax 指定了进程通信的max size of message,在内核内存进行,会改变os内存占用.sysctl --write kernel.msgmax=#
改变后,ipcs --limits会看到改变
/proc/sys/kernel/msgmnb 指定max size of queue消息队列最大长度.ipcs --limits
/proc/sys/kernel/msgmni 消息队列最大数量

/sys/firmware/efi efibootmgr

set -e exit immediately if a simple command exits with a non-zero status
set -e 后出现的代码,一但出现non-zero返回值,立即退出
set -e == set -o errexit set +e == set +o errexit
command || exit 7
command || { echo 'ppppppppppp';exit 7 }
if ! command;then echo 'ppppppppp';exit 7;fi
command
if [[ $? -ne 0 ]];then echo 'ppppppppppppp';exit 7;fi
command || true

set -u treat unset variables as an error when substituting
设置后,脚本中遇到未定义变量后,报错,退出脚本 emcas.sh: line5 5: p: unbound variable
set -u == set -o nounset set +u == set +o nounset

set -x print commands and their arguments as they are executed
set -x == set -o xtrace set +x == set +o xtrace

set -o option-name set the variable corresponding to option-name

删除文件technique
ls | grep [-v] ppp | xargs -i rm -rf {}
rm -rf `ls | grep [-v] ppp`

get --content-disposition(保持原文件名) --no-check-certificate --save-cookies=file

uuidgen --time|--random

halt poweroff reboot shutdown 都是调用systemctl halt(不关闭电源,电源灯亮) poweroff 关闭电源
都为/bin/systemctl的软连接
halt --halt --poweroff --reboot --force
poweroff --halt --poweroff --reboot --force
reboot --halt --poweroff --reboot --force
shutdown --halt --poweroff --reboot --force -c +2|now

yum.conf
history_list_view=users|commands

ulimit -n 同时设定soft limit和hard limit 都是临时设定
ulimit -Sn
ulimit -Hn
使用ulimit 查看同理 默认查看soft limit
ulimit -Sn ulimit -Hn

跳过首次ssh key提示
ssh-keyscan pend1 pend2 pend3 >> ~/.ssh/known_hosts ** 空格隔开
ansible: export ANSIBLE_HOST_KEY_CHECKING=false

查看内核启动顺序,设置默认启动内核
uname -r 3.10.0-957.el7.x86_64

menuentry 'CentOS Linux (3.10.0-693.11.6.el7_lustre.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_op
tion 'gnulinux-3.10.0-957.el7.x86_64-advanced-495d6dcb-ea77-47c4-974a-3c86f1357661' {

awk -F\' '$1=="menuentry " { print $2 }' /etc/grub2.cfg
CentOS Linux (3.10.0-693.11.6.el7_lustre.x86_64) 7 (Core)
CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-fe2c99e8c9c44e4092970b6372fcad3a) 7 (Core)

awk -F\' '{ if($1=="menuentry ") { print $2 } }' /boot/grub2/grub.cfg

grub2-set-default 0 index 从 0开始
grub2-set-default "CentOS Linux (3.10.0-693.11.6.el7_lustre.x86_64) 7 (Core)"

GRUB_DEFAULT=0 以位置来设定预设选单选项。第一笔选单选项为 0,第二笔为 1,以此类推。
GRUB_DEFAULT=”centos*** ” 在此例中,选单中的位置不会有影响。
例如:GRUB_DEFAULT=”Ubuntu, Linux 3.11.0-13-generic”。注意要完整全称。

GRUB_DEFAULT=saved 由储存预设的作业系统开机。可以用grub-reboot和grub-set-default指令来设定预设作业系统。预设作业系统不会由来自选单中的互动式选择而被设定。
grub-set-default 0 以位置来设定预设选单选项。第一笔选单选项为 0,第二笔为 1,以此类推。
grub-set-default “xxxx” 以名称来设定
grub-reboot 0 以位置来设定下次重启开机选项。第一笔选单选项为 0,第二笔为 1,以此类推。
grub-reboot “xxxx” 以选单名称来重启开机

genisoimage -v -cache-inodes -joliet-long -R -J -T -V AUTONOMOUS -o /root/AUTONOMOUS.iso \
-c isolinux/boot.cat -bisolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot -b images/efiboot.img -no-emul-boot .

PS1='\[\e[31;1m\]\u\[\e[0m\]\[\e[32;1m\]\[\e[0m\]@\[\e[35;1m\]\w\[\e[0m\]\$ '

.ssh/config
Host name1
HostName pend2
Port 22
User git
IdentityFile /home/intuitive/.ssh/id_dsa
id_ecdsa id_rsa
IdentitiesOnly yes

grep --color=auto '(vmx\|svm)' /proc/cpuinfo
modprobe kvm modprobe kvm_intel

libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast

yum install mesa-libGLw-devel.x86-64 # solution

/etc/mail.rc # mailx
set from="liuzheng@ginpie.com"
set smtp=smtp.ginpie.com
set smtp-auth-user=liuzheng@ginpie.com
set smtp-auth-password=password
set smtp-auth=login

echo 'pppppppppppppp' | mailx -v -s 'assortment' -a file -c -b target@target.com


cat > /etc/issue <<- eof
OS:\S VERSION:\v TTY:\l DATE:\d TIME:\t
Kernel \r on an \m DOMAIN NAME:\o HOSTNAME:\n USER:\U
Dear customer,
Thank you for choosing our product,please visit http://www.ginpie.com for more information!
eof


< /dev/urandom awk 'NR==1{print $0|"md5sum|base64|grep -Eo '^.{16}'";exit}'

echo "$(date +%s)" | sha256sum | base64 | head --bytes 10 ;echo

< /dev/urandom tr -dc [:graph:]

< /dev/urandom tr -dc 0-9a-zA-Z | head --bytes 10;echo

dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | head --bytes 10;echo

磁盘最小存储单位为sector,os每次i/o长度为块block,文件系统上最小分配单位为fragment,block可认为等同于fragment

CA
cd /etc/pki/CA
(umask 0066;openssl genrsa -out private/cakey.pem 2048)
touch index.txt;echo 01 > serial
openssl req -new -x509 -key private/cakey.pem -out cacert.pem --days 7000
openssl ca -in /tmp/httpd.csr -out certs/web1.pp.zz.crt -days 900

(umask 0066;openssl genrsa -out httpd.key 1024)
openssl req -new -key httpd.key -out httpd.csr

systemctl isolate emergency,无运行级别,启动的服务比rescue少,rescue.target的runlevel为1,emergency比rescue更彻底

+ ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

b7d844187e93cc5707691814189cd237da7fc163

发表评论

0/200
330 点赞
0 评论
收藏