Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

系统管理员知识(test your sysadmin skills) #5

Open
Zhang21 opened this issue Mar 15, 2022 · 29 comments
Open

系统管理员知识(test your sysadmin skills) #5

Zhang21 opened this issue Mar 15, 2022 · 29 comments
Assignees
Labels
sa 系统管理员 skill 技能

Comments

@Zhang21
Copy link
Owner

Zhang21 commented Mar 15, 2022

参考:


系统管理员相关知识技能。记录一些自己还不太熟悉的内容。

@Zhang21 Zhang21 self-assigned this Mar 15, 2022
@Zhang21 Zhang21 added the skill 技能 label Mar 15, 2022
@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 15, 2022

# pushd, popd命令用于多个目录之间切换
# cd主要是两个目录之间切换
pushd/popd/dirs/cd

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 15, 2022

# linux中!(叹号)的用法
# !和历史命令有关

# 执行某个历史命令
!history-id
# 上一个命令
!!
# 上一个命令的所有参数
!*
# 上一个命令的第一个参数
!^
# 上一个命令的最后一个参数
!$
# 去掉最后一个参数执行上一个命令
!:-

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 15, 2022

# 强大的分屏工具
tmux/screen

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 16, 2022

vlan和subnet的区别:

  • vlan layer 2(链路层)
  • subnet layer 3(网络层)

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 16, 2022

localhost127.0.0.1的区别:

localhost还需要查找和解析

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 17, 2022

版本控制提交信息的一个规则:

  • separate subject from body with a blank line
  • limit the subject line to 50 characters
  • capitalize the subject line
  • do not end the subject line with a period
  • use the imperative mood in the subject line
  • wrap the body at 72 characters
  • use the body to explain what and why vs. how

@Zhang21 Zhang21 added the sa 系统管理员 label Mar 17, 2022
@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 17, 2022

Linux系统的启动流程:

power -> bios -> bootloader -> kernel -> init/deamon

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 17, 2022

系统负载大于1.0应该注意,大于5.0就更得处理了。

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 17, 2022

真实用户和有效用户:

  • ruid(real user id): 真是用户ID
  • euid(effective user id): 权限认证

例如让普通用户以root执行的/usr/bin/passwd来修改/etc/passwd/etc/shadow文件。

# s 设置了setuid, 更改了普通用户执行passwd进程的euid,让普通用户有权限修改/etc/passwd或/etc/shadow
-rwsr-xr-x 1 root root 45396 may 25  2012 /usr/bin/passwd

# setuid: 只对可执行文件有效, 4---
chmod u+s binA
# setgid: 只对目录有效,2---
chmod g+s dirB
# sticky bit: 防删除,other有w也无法删除,1---
chmod o+t file1

# 如
0644  rw-r--r--
2644  rwSr--r--
2744  rwsr--r--

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 21, 2022

strace:查看系统调用和信号。别在生产环境对正在运行的进程使用strace,因为它的每次系统调用都会暂停进程。会对应用性能造成影响。
ltrace:system calls和library calls

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 23, 2022

ulimit: 系统资源限制和控制

  • threads
  • files
  • network connections
# 文件
/etc/security/limits.conf

# hard limits
# sort limits

# 命令
ulimit

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 23, 2022

ldd命令找出可执行程序运行需要的动态库。

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 28, 2022

tcp三次握手和四次挥手

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 28, 2022

数据结构基础知识:

  • 生成树(spinning tree)

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 29, 2022

为程序运行提供动态运行库:

# LD_LIBRARY_PATH环境变量
export LD_LIBRARY_PATH="/list/of/library/paths:/another/path" ./program

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 29, 2022

Linux系统调用:

  • fork():创建新进程
  • exec():执行新进程
  • wait():让进程等待
  • exit():退出或终止进程
  • getpid():获取PID
  • getppid():获取PPID
  • nice():修改当前运行程序的优先级

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 30, 2022

中断(interrupt)和中断处理程序(interrupt handler)。

Linux内核使用中断来管理硬件设备。中断本质上是一种电信号。中断是异步的。当接收到一个中断时,内核会执行中断处理程序,每个可以产生中断的设备都有一个对应的中断处理程序。中断处理程序是设备驱动的一部分。

可通过/proc/interrupts查看系统的中断的状态。


image

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 30, 2022

inode上存储的字段:

  • device id
  • file mode
  • link count
  • uid
  • gid
  • 文件大小
  • 时间戳
    • ctime
    • mtime
    • atime
  • io块大小
  • 块数量

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 30, 2022

chroot的优点:

  • 救援模式
  • 沙箱环境

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 30, 2022

segfault(segmentation fault),是导致程序奔溃的常见条件,通常由于程序尝试读/写非法内存位置引起。也有可能是内存限制太低。

程序内存空间被分为不同的段:

  • 栈(stack segment):子程序和函数中定义的临时变量
  • 堆(heap segment):函数在运行时分配的变量(如malloc
  • 未初始化数据(bss(Block Started by Symbol) segment)
  • 初始化的数据(data segment):编译时定义的变量和数组
  • 代码(text segment):程序指令

使用ulimit查看和设置相关限制项。程序奔溃生成core file。使用gdb调试core file。


1
2

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 30, 2022

这几个的区别:

  • /sbin/nologin:不可登录系统,但可以使用其它服务(如ftp)
  • /bin/false:一切服务都不能用。只是一个立即退出的二进制文件,当调用时,它返回false($? 1)
  • /bin/true:当调用时,它返回true($? 0)

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 31, 2022

文件描述符(fd, file descriptor):Linux 系统中,把一切都看做是文件,当进程打开现有文件或创建新文件时,内核向进程返回一个文件描述符,文件描述符就是内核为了高效管理已被打开的文件所创建的索引,用来指向被打开的文件,所有执行I/O操作的系统调用都会通过文件描述符。

可通过ulimit -n命令查看用户打开文件数限制,通过/proc/pid/limits查看进程的限制,通过/proc/pid/fd查看进程的fd。

特殊的三个文件描述符:

  • 0: stdin
  • 1: stdout
  • 2: stderr

  • 2>&-: 是M>&-的缩写,也就是关闭。这里是关闭标准输出
  • 2>/dev/null: 是M>/dev/null的缩写
  • 2>&1: 是M>&N的缩写形式,M和N是文件描述符号
  • |&: 是2>&1的缩写
  • &>/dev/null:是>/dev/null 2>&1的缩写

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 31, 2022

系统负载高,cpu使用率不高:最有可能的原因是磁盘IO问题。查看哪个进程或哪个磁盘有异常。

以下几个工具:

  • top
  • atop
  • iotop

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 31, 2022

nice, renice设定进程优先级(-20到19,越小越优先,默认0)。

ionice设定或获取程序IO调度类和优先级(0到7,越小越优先)。

  • 0: none,默认
  • 1: realtime,实时调度,立即访问磁盘。
  • 2: best-effort
  • 3: idle,空闲磁盘调度,没有其它进程使用磁盘才使用。

nice -n 10 bin/xxx
renice -n 5 -p pid

ionice -c3 dd if=/dev/zero of=/tmp/ddfile

通过fd可以查看使用该文件的进程,命令 fuser filename通过查找/proc/pid/fd来找出使用该文件的进程。

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 31, 2022

限制进程的cpu使用:

  • nice
  • cpulimit
  • cgroup

@Zhang21
Copy link
Owner Author

Zhang21 commented Mar 31, 2022

挂载一个临时ram分区,tmpfs是一种虚拟内存文件系统。

mount -t tmpfs tmpfs /mnt/haha -o size=64M

@Zhang21
Copy link
Owner Author

Zhang21 commented Apr 1, 2022

是否可以有IP地址的SSL证书?

只要它是公网IP就可以,但用的很少。

@Zhang21
Copy link
Owner Author

Zhang21 commented Apr 1, 2022

bash的一个特殊功能:

  • /dev/tcp/host/port
  • /dev/udp/host/port

根据$?为0还是1,判断连接是否正常。

timeout 2 bash -c "</dev/tcp/host/port"; echo $?

@Zhang21
Copy link
Owner Author

Zhang21 commented Apr 1, 2022

使用nc创建tcp/udp代理:

### TCP -> TCP
nc -l -p 2000 -c "nc [ip|hostname] 3000"

### TCP -> UDP
nc -l -p 2000 -c "nc -u [ip|hostname] 3000"

### UDP -> UDP
nc -l -u -p 2000 -c "nc -u [ip|hostname] 3000"

### UDP -> TCP
nc -l -u -p 2000 -c "nc [ip|hostname] 3000"

@Zhang21 Zhang21 changed the title test your sysadmin skills 系统管理员知识(test your sysadmin skills) Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sa 系统管理员 skill 技能
Projects
None yet
Development

No branches or pull requests

1 participant