赞
踩
输出命令信息需要在命令提示符之后输入
命令提示符:
[root@oldboy ~]#
root 表示当前登录系统用户名称
oldboy 表示当前系统主机名称
~ 表示当前所进入的系统目录路径
# 表示当前登录系统用户的权限
# 为root 管理员权限
$ 为非管理员权限
命令输入格式
e.g.
[root@oldboy ~]# ls
e.g.
ip 查看网络信息
[root@oldboy ~]# ip address(参数) show(参数)
[root@oldboy ~]# ip route(参数) show(参数)
e.g.
[root@oldboy ~]# cat -n /etc/hosts
ip 查看网络信息
[root@oldboy ~]# ip address show
[root@oldboy ~]# ip address show eth0
[root@oldboy ~]# ip a s eth0
[root@oldboy ~]#nmtui
255.255.255.0 | /24 C类地址 |
---|---|
255.255.0.0 | /16 B类地址 |
255.0.0.0 | /8 A类地址 |
255.192.0.0 | /10 A类地址子网掩码 |
255.255.192.0 | /18 B类地址子网掩码 |
255.255.255.252 | /30 C类地址子网掩码 |
[root@oldboy ~]# systemctl restart network
[root@oldboy ~]#systemctl status sshd
XShell软件设置:
文件-默认会话属性
缓冲区大小:200000(最大值)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H3sLv3rY-1654492271967)(image/3d838214934fdbbbbbb89002f3f050e0_8N1oFPWseE.png)]
勾选使用闪烁的光标
速度:500millisec
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pYrFlkiN-1654492271969)(image/ab6417281b49957ba17a2728c6dbf2a2_M8UNlUxcLd.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-c3vUwYNo-1654492271969)(image/391bcb1329afe802ff88330931423c2e_hX7DhVDz0A.png)]
延迟关机(默认延迟1分钟)
[root@oldboy ~]#shutdown -h
延迟10分钟关机
[root@oldboy ~]#shutdown -h 10
立即关机
[root@oldboy ~]#shutdown -h now
或者
[root@oldboy ~]#shutdown -h 0
问题:如何指定在某个时间点(零点)关机?
延迟重启(默认延迟1分钟)
[root@oldboy ~]#shutdown -r
延迟10分钟重启
[root@oldboy ~]#shutdown -r 10
立即重启
[root@oldboy ~]#shutdown -r now
或者
[root@oldboy ~]#shutdown -r 0
[root@oldboy ~]#shutdown -c
e.g.
[root@oldboy ~]# man cat CAT(1) User Commands CAT(1) NAME cat - concatenate files and print on the standard output SYNOPSIS cat [OPTION]... [FILE]... DESCRIPTION Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, --number-nonblank number nonempty output lines, overrides -n -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank suppress repeated empty output lines -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit With no FILE, or when FILE is -, read standard input. EXAMPLES cat f - g Output f's contents, then standard input, then g's contents. cat Copy standard input to standard output. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cat translation bugs to <http://translationproject.org/team/> AUTHOR Written by Torbjorn Granlund and Richard M. Stallman. COPYRIGHT Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent per‐ mitted by law. SEE ALSO tac(1) The full documentation for cat is maintained as a Texinfo manual. If the info and cat programs are properly installed at your site, the command info coreutils 'cat invocation' should give you access to the complete manual. GNU coreutils 8.22 April 2018
e.g.
[root@oldboy ~]# cat --help 用法:cat [选项]... [文件]... 将[文件]或标准输入组合输出到标准输出。 -A, --show-all 等于-vET -b, --number-nonblank 对非空输出行编号 -e 等于-vE -E, --show-ends 在每行结束处显示"$" -n, --number 对输出的所有行编号 -s, --squeeze-blank 不输出多行空行 -t 与-vT 等价 -T, --show-tabs 将跳格字符显示为^I -u (被忽略) -v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外 --help 显示此帮助信息并退出 --version 显示版本信息并退出 如果没有指定文件,或者文件为"-",则从标准输入读取。 示例: cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。 cat 将标准输入的内容复制到标准输出。 GNU coreutils online help: <http://www.gnu.org/software/coreutils/> 请向<http://translationproject.org/team/zh_CN.html> 报告cat 的翻译错误 要获取完整文档,请运行:info coreutils 'cat invocation'
系统中的命令分为两种类型:
① 内置命令:系统自带的命令,包含以下命令:
bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue,declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history,jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt,source, suspend, test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait
② 外置命令:需要安装第三方软件包才能使用的命令
e.g.
[root@oldboy ~]# help cd cd: cd [-L|[-P [-e]]] [dir] Change the shell working directory. Change the current directory to DIR. The default DIR is the value of the HOME shell variable. The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is the same as the current directory. If DIR begins with a slash (/), then CDPATH is not used. If the directory is not found, and the shell option `cdable_vars' is set, the word is assumed to be a variable name. If that variable has a value, its value is used for DIR. Options: -L force symbolic links to be followed -P use the physical directory structure without following symbolic links -e if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status The default is to follow symbolic links, as if `-L' were specified. Exit Status: Returns 0 if the directory is changed, and if $PWD is set successfully when -P is used; non-zero otherwise.
mkdir - make directories 创建目录
语法结构:
mkdir [OPTION]… DIRECTORY…
e.g.
创建一个目录
[root@oldboy ~]# mkdir /data
创建多个连续的目录
[root@oldboy ~]# mkdir /data{01..50}}
创建多个等差为2的目录
[root@oldboy ~]# mkdir /data/oldboy{01..10..2}
创建多个无序列顺序的目录
[root@oldboy ~]# mkdir {conf,log,data}
创建多级目录
-p no error if existing, make parent directories as needed/如果想创建的目录已经存在,以及当创建一个目录,需要创建父级目录的时候,不要显示错误提示
[root@oldboy ~]# mkdir -p /data/oldboy/oldgirl/oldbaby/olddog
[root@oldboy data]# tree /data/oldboy
/data/oldboy
└── oldgirl
└── oldbaby
└── olddog
rmdir - remove empty directories 删除空目录
语法结构:
rmdir [OPTION]… DIRECTORY…
e.g.
[root@oldboy ~]# rmdir /data/oldboy01
cd - Change the shell working directory 切换工作目录
语法结构:
cd [OPTION]… DIRECTORY…
e.g.
绝对路径切换目录:从根开始切换目录
[root@oldboy etc]# cd /data/oldboy
相对路径切换目录:从当前路径开始切换目录
[root@oldboy oldboy]# cd oldgirl/
返回上一级目录
[root@oldboy oldgirl]# cd ..或者cd../
返回指定的上级目录
[root@oldboy olddog]# cd ../../../
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-G4H6iDSz-1654492271970)(image/1e1e5063e09b784f884113498279fbc8_fVcABQbiIL.png)]
目录之间的互相切换:切换到上次所在目录
[root@oldboy olddog]# cd -
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VjcrNTWT-1654492271970)(image/ee59d85e1e389062595b36485ce01776_gHTO8EO9IF.png)]
快速返回家目录
[root@oldboy olddog]# cd ~
或者
[root@oldboy olddog]# cd ~
pwd - Print the full filename of the current working directory
[root@oldboy ~]# pwd
/root
ls - list directory contents
语法结构:
ls [OPTION]… [FILE]…
e.g.
绝对路径方式查看目录信息
[root@oldboy /]# ls /data/oldboy
oldgirl
相对路径方式查看目录信息
[root@oldboy data]# ls oldboy
oldgirl
查看当前路径下的所有数据信息
[root@oldboy oldboy]# ls
oldgirl
查看指定文件是否存在
* - 匹配任意字符
[root@oldboy oldboy]# ls /etc/hosts
/etc/hosts
[root@oldboy oldboy]# ls /etc/host*
/etc/host.conf /etc/hostname /etc/hosts /etc/hosts.allow /etc/hosts.deny
查看文件详细属性信息
[root@oldboy oldboy]# ls -l /etc/hosts
-rw-r--r--. 1 root root 158 6月 7 2013 /etc/hosts
[root@oldboy oldboy]# ll /etc/hosts
-rw-r--r--. 1 root root 158 6月 7 2013 /etc/hosts
查看指定目录详细属性信息
[root@oldboy oldboy]# ls -ld /etc/
drwxr-xr-x. 80 root root 8192 3月 24 16:10 /etc/
查看最新修改的文件信息(按照时间排序显示数据信息)
-t 按正向时间排序 历史数据显示在最下面
-r 反向排序
-tr 按反向时间排序 最新数据显示在最下面
[root@oldboy oldboy]# ll -tr /data/
总用量 0
drwxr-xr-x. 2 root root 6 3月 26 09:49 oldboy01
drwxr-xr-x. 3 root root 21 3月 25 17:19 oldboy
drwxr-xr-x. 2 root root 6 3月 25 17:10 data
drwxr-xr-x. 2 root root 6 3月 25 17:10 conf
drwxr-xr-x. 2 root root 6 3月 25 17:10 log
drwxr-xr-x. 2 root root 6 3月 25 17:07 oldboy09
drwxr-xr-x. 2 root root 6 3月 25 17:07 oldboy03
drwxr-xr-x. 2 root root 6 3月 25 17:07 oldboy05
drwxr-xr-x. 2 root root 6 3月 25 17:07 oldboy07
-S 按文件大小排序查看文件信息
-r 反向排序
[root@oldboy oldboy]# ll -S /data/
总用量 0
drwxr-xr-x. 3 root root 21 3月 25 17:19 oldboy
drwxr-xr-x. 2 root root 6 3月 25 17:10 conf
drwxr-xr-x. 2 root root 6 3月 25 17:10 data
[root@oldboy oldboy]# ll -Sr /data/
drwxr-xr-x. 2 root root 6 3月 25 17:10 data
drwxr-xr-x. 2 root root 6 3月 25 17:10 conf
drwxr-xr-x. 3 root root 21 3月 25 17:19 oldboy
-lh 以人类可读方式显示文件大小信息
[root@oldboy ~]# ll -h /etc/services
-rw-r--r--. 1 root root 655K 6月 7 2013 /etc/services
touch - change file timestamps
语法结构:
touch [OPTION]… FILE…
e.g.
创建空文件信息
[root@oldboy data]# touch oldgirl.txt
语法结构:
echo [SHORT-OPTION]… [STRING]…
echo LONG-OPTION
e.g.
输出hello
[root@oldboy data]# echo hello
hello
e.g.
echo “文件信息” > /data/oldboy.txt 标准输出重定向**(会清空文件内原有的内容)**
[root@oldboy data]# echo oldboyedu > oldboy.txt
[root@oldboy data]# cat oldboy.txt
oldboyedu
[root@oldboy data]# echo oldgriledu > oldboy.txt
[root@oldboy data]# cat oldboy.txt
oldgriledu
echo “文件信息” >>/data/oldboy.txt 标准追加输出重定向**(在文件原有内容重启一行写入新内容)**
[root@oldboy data]# echo oldbaby >> oldboy.txt
[root@oldboy data]# cat oldboy.txt
oldgriledu
oldbaby
清空文件原有内容
[root@oldboy data]# > oldboy.txt
[root@oldboy data]# cat oldboy.txt
e.g.
[root@oldboy data]# > oldboy.txt
[root@oldboy data]# cat oldboy.txt
e.g.
实现多个用户之间传输会话
[root@oldboy data]# ps -ef
sshd: root@pts/0 root登录的会话进程
sshd: root@pts/1 oldboy登录的会话进程
[root@oldboy data]# echo "oldboy你在做什么"> /dev/pts/1
oldboy你在做什么
[root@oldboy data]# cat >>oldboy.txt << EOF
> 1
> 2
> 3
> EOF
[root@oldboy data]# cat oldboy.txt
1
2
3
cat xxx文件 > xxx文件 将某文件中的文本内容覆盖输出到另外一个文件(此文件可以原本不存在)中
[root@oldboy ~]# ll /tmp/
总用量 0
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
[root@oldboy ~]# cat /etc/services > /tmp/oldboy.txt
[root@oldboy ~]# ll /tmp/
总用量 656
-rw-r--r--. 1 root root 670293 4月 19 17:19 oldboy.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
cat xxx文件 >> xxx文件 将某文件中的文本内容追加输出到另外一个文件(此文件可以原本存在)原有的文本内容后面
[root@oldboy ~]# cat /etc/services >> /tmp/oldboy.txt
[root@oldboy ~]# ll /tmp/
总用量 1728
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
回车 逐行查看文件内容
空格 逐页查看文件内容
n 逐行查看文件内容
空格 逐页查看文件内容
head -n n表示看前几行
[root@oldboy ~]# cat /tmp/oldgirl.txt 01.老男孩学科:Linux 02.老男孩学科:Python 03.老男孩学科:网络安全 04.老男孩学科:dba 05.老男孩学科:新媒体 [root@oldboy ~]# head -2 /tmp/oldgirl.txt 01.老男孩学科:Linux 02.老男孩学科:Python [root@oldboy ~]# head /tmp/oldboy.txt # /etc/services: # $Id: services,v 1.55 2013/04/14 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2013-04-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
tail -n n表示看后几行
[root@oldboy ~]# cat /tmp/oldgirl.txt 01.老男孩学科:Linux 02.老男孩学科:Python 03.老男孩学科:网络安全 04.老男孩学科:dba 05.老男孩学科:新媒体 [root@oldboy ~]# tail -2 /tmp/oldgirl.txt 04.老男孩学科:dba 05.老男孩学科:新媒体 [root@oldboy ~]# tail /tmp/oldboy.txt 3gpp-cbsp 48049/tcp # 3GPP Cell Broadcast Service Protocol isnetserv 48128/tcp # Image Systems Network Services isnetserv 48128/udp # Image Systems Network Services blp5 48129/tcp # Bloomberg locator blp5 48129/udp # Bloomberg locator com-bardac-dw 48556/tcp # com-bardac-dw com-bardac-dw 48556/udp # com-bardac-dw iqobject 48619/tcp # iqobject iqobject 48619/udp # iqobject matahari 49000/tcp # Matahari Broker
cp - copy files and directories
语法结构:
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE…
e.g.
备份(拷贝)文件
[root@oldboy data]# cp /data/oldboy.txt /backup/
备份(拷贝)文件并重命名(建议结合日期命名)
[root@oldboy data]# cp /data/oldboy.txt /backup/oldboy.txt-11月11日
备份(拷贝)目录
[root@oldboy data]# cp -r /data/ /backup/
[root@oldboy data]# ll /backup/
总用量 12
drwxr-xr-x. 62 root root 4096 4月 24 10:30 data
备份(拷贝)目录并重命名
[root@oldboy data]# cp -r /data/ /backup/data_11月11日
[root@oldboy data]# ll /backup/
总用量 16
drwxr-xr-x. 62 root root 4096 4月 24 10:30 data
drwxr-xr-x. 62 root root 4096 4月 24 10:33 data_11月11日
mv - move (rename) files
SYNOPSIS
mv \[OPTION]... \[-T] SOURCE DEST
mv \[OPTION]... SOURCE... DIRECTORY
mv \[OPTION]... -t DIRECTORY SOURCE...
e.g.
移动文件到指定目录
[root@oldboy data]# touch /etc/oldboy.conf
[root@oldboy data]# mv /etc/oldboy.conf /data/
[root@oldboy data]# ll /etc/oldboy.conf
ls: 无法访问/etc/oldboy.conf: 没有那个文件或目录
[root@oldboy data]# ll /data/
总用量 4
-rw-r--r--. 1 root root 0 4月 24 10:45 oldboy.conf
移动文件到指定目录并重命名
[root@oldboy data]# mv /data/oldboy.conf /tmp/oldgirl.conf
[root@oldboy data]# ll /tmp/
总用量 1316
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
-rw-r--r--. 1 root root 0 4月 24 10:45 oldgirl.conf
-rw-r--r--. 1 root root 145 4月 19 18:14 oldgirl.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
文件重命名
[root@oldboy data]# mv /tmp/oldgirl.conf /tmp/oldboy.conf
[root@oldboy data]# ll /tmp/
总用量 1316
drwxr-xr-x. 5 root root 102 4月 24 10:33 bak
-rw-r--r--. 1 root root 0 4月 24 10:45 oldboy.conf
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
-rw-r--r--. 1 root root 145 4月 19 18:14 oldgirl.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
e.g.
移动目录到其他目录
[root@oldboy data]# mv /backup/ /data/
[root@oldboy data]# ll /data/
总用量 4
drwxr-xr-x. 5 root root 102 4月 24 10:33 backup
移动目录到其他目录并重命名
[root@oldboy data]# mv /data/backup/ /tmp/bak
[root@oldboy data]# ll /tmp/
总用量 1316
drwxr-xr-x. 5 root root 102 4月 24 10:33 bak
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
-rw-r--r--. 1 root root 0 4月 24 10:45 oldgirl.conf
-rw-r--r--. 1 root root 145 4月 19 18:14 oldgirl.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
目录重命名
[root@oldboy data]# mv /tmp/bak/ /tmp/backup
[root@oldboy data]# ll /tmp/
总用量 1316
drwxr-xr-x. 5 root root 102 4月 24 10:33 backup
-rw-r--r--. 1 root root 0 4月 24 10:45 oldboy.conf
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
-rw-r--r--. 1 root root 145 4月 19 18:14 oldgirl.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
rm - remove files or directories**(慎用!删除前一定要反复确认好再做个备份后再删除)**
语法结构:
rm [OPTION]… FILE…
e.g.
删除文件
[root@oldboy data]# cd /tmp/
[root@oldboy tmp]# ll
总用量 1316
drwxr-xr-x. 5 root root 102 4月 24 10:33 backup
-rw-r--r--. 1 root root 0 4月 24 10:45 oldboy.conf
-rw-r--r--. 1 root root 1340586 4月 19 17:19 oldboy.txt
-rw-r--r--. 1 root root 145 4月 19 18:14 oldgirl.txt
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
[root@oldboy tmp]# rm -f oldboy.conf oldboy.txt oldgirl.txt
[root@oldboy tmp]# ll
总用量 0
drwxr-xr-x. 5 root root 102 4月 24 10:33 backup
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
e.g.
删除目录
[root@oldboy tmp]# ll /tmp/
总用量 0
drwxr-xr-x. 5 root root 102 4月 24 10:33 backup
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
[root@oldboy tmp]# rm -rf /tmp/backup/
[root@oldboy tmp]# ll
总用量 0
drwx------. 3 root root 17 4月 9 11:01 systemd-private-ce58ab41ce4f45acb1dc61af92aebf46-chronyd.service-4na0Qq
根目录千万不要被rm命令删除,否则无法恢复
[root@oldboy tmp]# rm -rf /
rm: 在"/" 进行递归操作十分危险
rm: 使用 --no-preserve-root 选项跳过安全模式
ctrl+a 快速移动光标到行首
ctrl+e 快速移动光标到行尾
ctrl+←或→ 将光标按照单词快速移动
ctrl+k 将光标之后的内容全部删除(其实是剪切)
ctrl+u 将光标之前的内容全部删除(其实是剪切)
ctrl+w 将光标之前的字符串(光标与上一个空格之间的内容)删除(其实是剪切)
ctrl+y 将剪切或复制的内容粘贴到光标处
ctrl+c 取消当前命令/终止当前运行的程序过程
ctrl+z 暂停当前运行的程序过程
恢复暂停的程序进程
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VvGxqsfB-1654492271971)(image/eb400c754bfe51c411180e06cbec8c83_fHmQ5DodYZ.png)]
tab 对操作命令或处理对象进行补全操作
↑或↓ 调取曾经执行过的历史命令
ctrl+l 清屏操作
ctrl+s 进入远程连接锁屏状态
ctrl+q 退出远程连接锁屏状态
esc+. 快速调取上一个命令最后的对象信息
语法格式:vi/vim 文件
命令模式:可以进行一些快捷操作(进入文件的默认模式)
编辑模式:可以编辑文件内容信息
底行模式:可以完成特殊命令操作
命令模式 → i I a A o O s S C → 编辑模式
i 在光标当前位置直接进入编辑模式
I 将光标移动到行首后进入编辑模式
a 将光标从当前位置向后移动一位进入编辑模式
A 将光标移动到行尾后进入编辑模式
o 在光标所在行下方插入一行后进入编辑模式
O 在光标所在行上方插入一行后进入编辑模式
s 删除光标所在位置的内容并进入编辑模式
S 删除光标所在行的内并进入编辑模式
C 删除光标所在位置及后面的内容并进入编辑模式
编辑模式 → esc → 命令模式
/ 表示可以进入信息检索状态 n 由上到下进行检索 N 由下到上进行检索
? 表示可以进入信息检索状态 n 由下到上进行检索 N 由上到下进行检索
底行模式 → esc → 命令模式
编辑模式 → esc → 命令模式 → : / ? → 底行模式
底行模式 → esc → 命令模式 → i I a A o O s S C→ 编辑模式
命令模式 → i → 编辑模式 → esc 命令模式 → : → 底行模式 → :wq 保存退出 :q 退出 → 命令行
G 将光标快速移动到最后一行
gg 将光标快速移动到第一行
nG或者ngg 将光标快速移动到指定行(n代表行号)
$ 将光标快速移动到行尾
^或者0 将光标快速移动到行首
yy 复制光标所在行的一整行内容
nyy 复制光标所在行及以下n-1行的内容
p 粘贴复制或剪切的内容
np 粘贴n份复制或剪切的内容
dd 删除(其实是剪切)光标所在行的内容
ndd 删除(其实是剪切)光标所在行及以下n-1行内容
nG 删除光标所在行到结尾的所有内容
u 撤销编辑操作内容
ctrl+r 恢复撤销操作内容
r 将光标所在位置内容直接做替换编辑操作
R 进入替换模式(按Esc退出)
:set nu 显示文件行号信息
:set nonu 取消显示行号信息
:set list 显示行尾指示符,用于判断每行结尾是否存在空格,有的话可以删掉
:nohl 取消高亮显示
:s#被替换的内容#替换之后的内容#g 替换光标所在行的指定内容
:%s#被替换的内容#替换之后的内容#g 全部文本内容都做替换指定内容的操作
:ns#被替换的内容#替换之后的内容#g 替换第n行的指定内容
:n,ms#被替换的内容#替换之后的内容#g 从n行开始到m行结束替换指定内容
:n,$s#被替换的内容#替换之后的内容#g 从n行开始到最后一行替换指定内容
s substitution 替换信息
g global 全局
### 替换信息与被替换信息的分隔符,也可以使用/或者@等符号
e.g.
取消注释信息 :2,3s/#//g 分隔符之间没有内容则是将要替换的内容删除
vim -r 恢复文件内容的底层逻辑:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UlfuvVoj-1654492271972)(image/6b3c8b2e610897ce6d1e649eab746654_OoOmg1wq9i.png)]
将光标移动到指定位置-ctrl+v-上下/左右移动光标选中要编辑的多行内容-d 将光标选中的内容删除
将光标移动到指定位置-ctrl+v-上下/左右移动光标选中要编辑的多行内容-shift+i-编辑内容-ESC 对多行进行统一编辑
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eWJej3MA-1654492271973)(image/image_8h7fw0ftBU.png)]
优化的范围:安全方面的优化、性能方面的优化、网络通讯的优化、业务服务的优化
hostname - show or set the system’s host name
显示或者设置系统主机名称
查看目前主机名称
[root@oldboy /]# hostname
oldboy.com
设置临时主机名(重新建立远程会话生效,但系统重启后失效)
[root@oldboy ~]# hostname BJ-oldboy-muban
断开会话连接并重新连接会话后
Connecting to 10.6.132.40:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu May 19 13:52:44 2022 from 10.6.136.196
[root@BJ-oldboy-muban ~]#
重启系统后
[root@BJ-oldboy-muban ~]# reboot PolicyKit daemon disconnected from the bus. We are no longer a registered authentication agent. Connection closing...Socket close. Connection closed by foreign host. Disconnected from remote host(test.com_10.6.132.40) at 13:55:39. Type `help' to learn how to use Xshell prompt. [F:\~]$ Reconnecting in 3 seconds. Press any key to exit local shell. ... Connecting to 10.6.132.40:22... .....................Could not connect to '10.6.132.40' (port 22): Connection failed. Type `help' to learn how to use Xshell prompt. [F:\~]$ . Connecting to 10.6.132.40:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Thu May 19 13:53:57 2022 from 10.6.136.196 [root@oldboy ~]#
查看系统信息
[root@oldboy ~]# hostnamectl
Static hostname: oldboy.com
Icon name: computer-vm
Chassis: vm
Machine ID: 698c5e1565f444408f54ee9fd0a0a282
Boot ID: 46a92bc23a994018a3832ad14be17589
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
修改主机名称
[root@oldboy ~]# hostnamectl set-hostname BJ-oldboy-muban
[root@oldboy ~]# hostnamectl
Static hostname: bj-oldboy-muban
Pretty hostname: BJ-oldboy-muban
Icon name: computer-vm
Chassis: vm
Machine ID: 698c5e1565f444408f54ee9fd0a0a282
Boot ID: 46a92bc23a994018a3832ad14be17589
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
断开会话连接并重新连接会话后
Connection closed.
Disconnected from remote host(test.com_10.6.132.40) at 14:12:07.
Type `help' to learn how to use Xshell prompt.
[F:\~]$
Connecting to 10.6.132.40:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu May 19 13:56:03 2022 from 10.6.136.196
[root@bj-oldboy-muban ~]#
重启系统后
[root@bj-oldboy-muban ~]# reboot Connection closing...Socket close. Connection closed by foreign host. Disconnected from remote host(test.com_10.6.132.40) at 14:14:16. Type `help' to learn how to use Xshell prompt. [F:\~]$ Reconnecting in 3 seconds. Press any key to exit local shell. ... Connecting to 10.6.132.40:22... ...............Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Thu May 19 14:12:17 2022 from 10.6.136.196 [root@bj-oldboy-muban ~]#
修改/etc/hosts文件,增加IP地址和对应的主机名称实现主机名称解析
vim /etc/hosts
10.6.132.42 BJ-oldboy-db
意义1:可以更方便的基于主机名称访问和连接主机
意义2:简化服务配置文件改动操作,服务器网络环境变化后,只需要修改/etc/hosts文件内解析IP地址即可,无需将每一个服务的配置文件中关于IP地址的信息进行修改
[root@bj-oldboy-muban ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.6.132.42 BJ-oldboy-db [root@bj-oldboy-muban ~]# ping BJ-oldboy-db PING BJ-oldboy-db (10.6.132.42) 56(84) bytes of data. From bj-oldboy-muban (10.6.132.40) icmp_seq=1 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=2 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=3 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=4 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=5 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=6 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=7 Destination Host Unreachable From bj-oldboy-muban (10.6.132.40) icmp_seq=8 Destination Host Unreachable ^C --- BJ-oldboy-db ping statistics --- 10 packets transmitted, 0 received, +8 errors, 100% packet loss, time 16152ms pipe 5
被访问虚拟软件(比如VMware Workstation)中设置NAT映射
编辑-虚拟网络编辑器-VMnet8-NAT模式-NAT设置-添加-主机端口:9000(设置一个数字大一点的没有使用的端口号)-类型:TCP-虚拟主机IP地址:被访问虚拟主机的IP-虚拟机端口:22
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UKegIYjH-1654492271974)(image/image_I7u3TD-kSn.png)]
变量:x=10 x+y=20 求y等于多少,其中x,y就是变量
e.g.
IP_info(变量)=10.6.132.40(变量的值)
[root@bj-oldboy-muban ~]# echo $IP_info
[root@bj-oldboy-muban ~]# IP_info=10.6.132.40
[root@bj-oldboy-muban ~]# echo $IP_info
10.6.132.40
[root@bj-oldboy-muban ~]# echo $IP_info
10.6.132.40
e.g.
[root@bj-oldboy-muban ~]# vim test.sh #!/bin/bash Info=edu echo oldboyInfo.com echo oldgirledu.cn echo oldbabyInfo.net echo olddogedu.gov echo ${Info}heqing.cn [root@bj-oldboy-muban ~]# sh test.sh oldboyedu.com oldgirledu.cn oldbabyedu.net olddogedu.gov eduheqing.cn [root@bj-oldboy-muban ~]# vim test.sh #!/bin/bash Info=123 echo oldboy$Info.com echo oldgirledu.cn echo oldbaby$Info.net echo olddogedu.gov echo ${Info}heqing.cn [root@bj-oldboy-muban ~]# sh test.sh oldboy123.com oldgirledu.cn oldbaby123.net olddogedu.gov 123heqing.cn
需要自行设置规划
没有特殊功能意义
只在当前用户生效
变量名称没有特殊规范,只要不是数字或符号开头就可以
系统默认自带
对系统的功能有影响
系统全局用户生效
环境变量都是大写字母表示
[root@bj-oldboy-muban ~]#PS1='[\u@\h \t \W]\$'
[root@bj-oldboy-muban 17:02:59 ~]#
vim /etc/profile
在最后一行添加PS1='[\u@\h \t \W]\$'后保存退出
[root@bj-oldboy-muban 17:24:55 ~]#echo $PS1 [\u@\h \t \W]\$ [root@bj-oldboy-muban 17:25:01 ~]#vim /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`/usr/bin/id -u` "/etc/profile" 76L, 1819C 1,1 顶端 else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell # Current threshold for system reserved uid/gids is 200 # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge PS1='[\u@\h \t \W]\$'
在最后一行添加PS1='[[\e[34;1m]\u[\e[0m]@[\e[32;1m]\h[\e[0m] [\e[33;1m]\t[\e[0m] [\e[31;1m]\W[\e[0m]]$'后保存退出
[root@bj-oldboy-muban 13:51:36 yum.repos.d]# vim /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`/usr/bin/id -u` UID=`/usr/bin/id -ru` fi USER="`/usr/bin/id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after fi HOSTNAME=`/usr/bin/hostname 2>/dev/null` HISTSIZE=1000 if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge User_color='\[\e[34;1m\]' Hostname_color='\[\e[32;1m\]' Time_color='\[\e[33;1m\]' Path_color='\[\e[31;1m\]' End_color='\[\e[0m\]' PS1='[\[\e[34;1m\]\u\[\e[0m\]@\[\e[32;1m\]\h\[\e[0m\] \[\e[33;1m\]\t\[\e[0m\] \[\e[31;1m\]\W\[\e[0m\]]\$'
\[\e[32;1m\] 开始设置颜色
30:灰色 31:橙色 32:绿色 33:黄色 34:蓝色 35:粉色 36:青色 37:白色
vim /etc/profile
在最后一行添加PS1="[KaTeX parse error: Can't use function '\u' in math mode at position 14: {User\_color}\̲u̲{End_color}@KaTeX parse error: Undefined control sequence: \h at position 18: …ostname\_color}\̲h̲{End_color} KaTeX parse error: Undefined control sequence: \t at position 14: {Time\_color}\̲t̲{End_color} KaTeX parse error: Undefined control sequence: \W at position 14: {Path\_color}\̲W̲{End_color}]\\$"后保存退出
[root@bj-oldboy-muban 13:44:16 yum.repos.d]# vim /etc/profile umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge User_color='\[\e[34;1m\]' Hostname_color='\[\e[32;1m\]' Time_color='\[\e[33;1m\]' Path_color='\[\e[31;1m\]' End_color='\[\e[0m\]' PS1="[${User_color}\u${End_color}@${Hostname_color}\h${End_color} ${Time_color}\t${End_color} ${Path_color}\W${End_color}]\\$"
用yum将源文件从源文件服务器(相当于标准软件库,包括阿里云、清华大学、网易、搜狐、中国科技大学等)下载安装到本地服务器
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Djr8mi1J-1654492271974)(image/image_B9QoyoGVIq.png)]
[root@bj-oldboy-muban 16:29:03 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
centos8(centos8官方源已下线,建议切换centos-vault源)
[root@bj-oldboy-muban 16:29:03 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
[root@bj-oldboy-muban 16:29:03 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
centos6(centos6官方源已下线,建议切换centos-vault源)
[root@bj-oldboy-muban 16:29:03 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
或者
[root@bj-oldboy-muban 16:29:03 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
CentOS 7
[root@bj-oldboy-muban 16:29:03 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
[root@bj-oldboy-muban 16:29:03 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@bj-oldboy-muban 16:57:19 ~]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误"
正在尝试其它镜像。
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
元数据缓存已建立
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nO6yZYPs-1654492271975)(image/image_GwfjydbiC1.png)]
非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置:
e.g.
[root@bj-oldboy-muban 16:49:32 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@bj-oldboy-muban 17:00:09 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@bj-oldboy-muban 17:00:09 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@bj-oldboy-muban 17:00:09 ~]# yum clean all && yum makecache
[root@bj-oldboy-muban 17:00:09 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@bj-oldboy-muban 17:00:09 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.aliyuncs.com/repo/Centos-vault-8.5.2111.repo
[root@bj-oldboy-muban 17:00:09 ~]# sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/CentOS-Base.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
[root@bj-oldboy-muban 17:00:09 ~]# yum clean all && yum makecache
建议先备份 /etc/yum.repos.d/CentOS-Base.repo
[root@bj-oldboy-muban 15:51:51 ~]# cp CentOS-Base.repo CentOS-Base.repo.bak
然后编辑 /etc/yum.repos.d/
中的相应文件,在 mirrorlist=
开头行前面加 #
注释掉;并将 baseurl=
开头行取消注释(如果被注释的话)。 对于 CentOS 7 ,请把该行内的域名(例如mirror.centos.org
)替换为 mirrors.tuna.tsinghua.edu.cn
。 对于 CentOS 8 ,请把 mirror.centos.org/$contentdir
替换为 mirrors.tuna.tsinghua.edu.cn/centos
。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mVhK0mw1-1654492271975)(image/image_9OBa0ml-5z.png)]
# 对于 CentOS 7
[root@bj-oldboy-muban 15:41:19 ~]#sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
# 对于 CentOS 8
[root@bj-oldboy-muban 15:41:19 ~]#sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
~~注意其中的~~~~~~~~通配符,如果只需要替换一些文件中的源,请自行增删。~~
~~注意,如果需要启用其中一些 repo,需要将其中的 ~~~~~~~~ 改为 ~~~~~~~~。~~
[root@bj-oldboy-muban 15:42:33 ~]# sudo yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/7): extras/7/x86_64/primary_db | 247 kB 00:00:00
(2/7): extras/7/x86_64/filelists_db | 277 kB 00:00:00
(3/7): extras/7/x86_64/other_db | 148 kB 00:00:00
(4/7): base/7/x86_64/other_db | 2.6 MB 00:00:01
(5/7): updates/7/x86_64/filelists_db | 8.7 MB 00:00:06
(6/7): updates/7/x86_64/other_db | 1.0 MB 00:00:01
(7/7): updates/7/x86_64/primary_db | 16 MB 00:00:16
元数据缓存已建立
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fvQF3vg2-1654492271976)(image/image_dI8yq_h_7x.png)]
[root@bj-oldboy-muban 17:09:42 ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
[root@bj-oldboy-muban 17:09:42 ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
[root@bj-oldboy-muban 17:09:42 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@bj-oldboy-muban 17:09:42 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@bj-oldboy-muban 17:09:42 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@bj-oldboy-muban 17:09:42 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@bj-oldboy-muban 17:09:42 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-archive-6.repo
[root@bj-oldboy-muban 09:55:13 ~]# yum install net-tools lrzsz telnet bash-completion -y 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com epel | 4.7 kB 00:00:00 (1/3): epel/x86_64/group_gz | 96 kB 00:00:00 (2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:02 (3/3): epel/x86_64/primary_db | 7.0 MB 00:00:15 软件包 net-tools-2.0-0.25.20131004git.el7.x86_64 已安装并且是最新版本 软件包 lrzsz-0.12.20-36.el7.x86_64 已安装并且是最新版本 正在解决依赖关系 --> 正在检查事务 ---> 软件包 bash-completion.noarch.1.2.1-8.el7 将被 安装 ---> 软件包 telnet.x86_64.1.0.17-66.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================== Package 架构 版本 源 大小 ======================================================================================================================== 正在安装: bash-completion noarch 1:2.1-8.el7 base 87 k telnet x86_64 1:0.17-66.el7 updates 64 k 事务概要 ======================================================================================================================== 安装 2 软件包 总下载量:151 k 安装大小:376 k Downloading packages: (1/2): bash-completion-2.1-8.el7.noarch.rpm | 87 kB 00:00:00 (2/2): telnet-0.17-66.el7.x86_64.rpm | 64 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------ 总计 335 kB/s | 151 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : 1:bash-completion-2.1-8.el7.noarch 1/2 正在安装 : 1:telnet-0.17-66.el7.x86_64 2/2 验证中 : 1:telnet-0.17-66.el7.x86_64 1/2 验证中 : 1:bash-completion-2.1-8.el7.noarch 2/2 已安装: bash-completion.noarch 1:2.1-8.el7 telnet.x86_64 1:0.17-66.el7 完毕!
[root@bj-oldboy-muban 09:14:14 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.6.132.40 netmask 255.255.255.0 broadcast 10.6.132.255 inet6 fe80::13c1:3f9d:f07f:b133 prefixlen 64 scopeid 0x20<link> ether 00:50:56:8a:05:e9 txqueuelen 1000 (Ethernet) RX packets 1269560 bytes 124822292 (119.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 39680 bytes 3885966 (3.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 56 bytes 4888 (4.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56 bytes 4888 (4.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@bj-oldboy-muban 09:54:46 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.6.132.1 0.0.0.0 UG 100 0 0 eth0 10.6.132.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
e.g.
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Djo78A0u-1654492271977)(image/image_5uM0iSDuAO.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z6yJDfjm-1654492271977)(image/image_nrdVRvPxi1.png)]
e.g.
[root@bj-oldboy-muban 11:03:09 ~]# wget https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white-d0c9fe2af5.png --2022-05-23 11:04:09-- https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white-d0c9fe2af5.png 正在解析主机 dss0.bdstatic.com (dss0.bdstatic.com)... 42.81.84.33, 240e:b1:8805:202::7cec:6821 正在连接 dss0.bdstatic.com (dss0.bdstatic.com)|42.81.84.33|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:8853 (8.6K) [image/png] 正在保存至: “logo_white-d0c9fe2af5.png” 100%[==============================================================================>] 8,853 --.-K/s 用时 0s 2022-05-23 11:04:09 (109 MB/s) - 已保存 “logo_white-d0c9fe2af5.png” [8853/8853]) [root@bj-oldboy-muban 11:04:09 ~]# ll 总用量 24 -rw-------. 1 root root 1508 3月 15 16:35 anaconda-ks.cfg -rw-r--r--. 1 root root 8853 5月 12 2020 logo_white-d0c9fe2af5.png -rw-r--r--. 1 root root 124 5月 19 15:59 test.sh -rw-r--r--. 1 root root 53 5月 19 15:50 test.txt
e.g.
[root@bj-oldboy-muban 11:06:25 ~]# telnet 10.6.132.40 22
Trying 10.6.132.40...
Connected to 10.6.132.40.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
5)telnetbash-completion 可以使用tab键不全服务的名称信息
e.g.
[root@bj-oldboy-muban 11:12:26 ~]# systemctl sta
start status
[root@bj-oldboy-muban 11:12:26 ~]# systemctl status fi
final.target firewalld.service
[root@bj-oldboy-muban 11:12:26 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@bj-oldboy-muban 11:16:52 ~]# timedatectl
Local time: 一 2022-05-23 11:17:03 CST # 本地时间信息
Universal time: 一 2022-05-23 03:17:03 UTC # 格林尼治时间
RTC time: 一 2022-05-23 03:17:03 # 系统BIOS硬件时间
Time zone: Asia/Shanghai (CST, +0800) # 时区信息
NTP enabled: yes # 是否开启网络时间同步服务
NTP synchronized: yes # 是否进行了网络时间同步操作
RTC in local TZ: no
DST active: n/a
[root@bj-oldboy-muban 11:36:29 ~]# timedatectl list-timezones Asia/Shanghai Asia/Singapore Asia/Srednekolymsk Asia/Taipei Asia/Tashkent Asia/Tbilisi Asia/Tehran Asia/Thimphu Asia/Tokyo Asia/Tomsk Asia/Ulaanbaatar Asia/Urumqi Asia/Ust-Nera Asia/Vientiane Asia/Vladivostok Asia/Yakutsk Asia/Yangon Asia/Yekaterinburg Asia/Yerevan Atlantic/Azores Atlantic/Bermuda Atlantic/Canary Atlantic/Cape_Verde Atlantic/Faroe Atlantic/Madeira Atlantic/Reykjavik Atlantic/South_Georgia Atlantic/St_Helena /Shanghai
[root@bj-oldboy-muban 11:39:35 ~]# timedatectl set-timezone Asia/Shanghai
[root@bj-oldboy-muban 13:16:28 ~]# timedatectl --help timedatectl [OPTIONS...] COMMAND ... Query or change system time and date settings. -h --help Show this help message --version Show package version --no-pager Do not pipe output into a pager --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --adjust-system-clock Adjust system clock when changing local RTC mode Commands: status Show current time settings set-time TIME Set system time set-timezone ZONE Set system time zone list-timezones Show known time zones set-local-rtc BOOL Control whether RTC is in local time set-ntp BOOL #布尔类型数据,0代表关,1代表开 Control whether NTP is enabled [root@bj-oldboy-muban 13:16:34 ~]# timedatectl set-ntp 1 #开启网络时间同步
[root@bj-oldboy-muban 13:16:34 ~]# yum install -y chrony 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 chrony.x86_64.0.3.2-2.el7 将被 升级 ---> 软件包 chrony.x86_64.0.3.4-1.el7 将被 更新 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================== Package 架构 版本 源 大小 ======================================================================================================================== 正在更新: chrony x86_64 3.4-1.el7 base 251 k 事务概要 ======================================================================================================================== 升级 1 软件包 总下载量:251 k Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. chrony-3.4-1.el7.x86_64.rpm | 251 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在更新 : chrony-3.4-1.el7.x86_64 1/2 清理 : chrony-3.2-2.el7.x86_64 2/2 验证中 : chrony-3.4-1.el7.x86_64 1/2 验证中 : chrony-3.2-2.el7.x86_64 2/2 更新完毕: chrony.x86_64 0:3.4-1.el7 完毕! [root@bj-oldboy-muban 13:30:05 ~]# cat /etc/chrony.conf # These servers were defined in the installation: server 0.centos.pool.ntp.org iburst #NTP服务器地址/域名,默认为官方地址,也可以手动修改 为指定的地址/域名,但一般默认即可。 server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking [root@bj-oldboy-muban 13:41:57 ~]# systemctl start chronyd #启动网络时间同步服务 [root@bj-oldboy-muban 13:42:11 ~]# systemctl status chronyd ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since 一 2022-05-23 13:30:05 CST; 12min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 5555 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 5551 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 5553 (chronyd) CGroup: /system.slice/chronyd.service └─5553 /usr/sbin/chronyd 5月 23 13:30:05 bj-oldboy-muban systemd[1]: Starting NTP client/server... 5月 23 13:30:05 bj-oldboy-muban chronyd[5553]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVD...EBUG) 5月 23 13:30:05 bj-oldboy-muban chronyd[5553]: Frequency 212.708 +/- 4.604 ppm read from /var/lib/chrony/drift 5月 23 13:30:05 bj-oldboy-muban systemd[1]: Started NTP client/server. 5月 23 13:30:12 bj-oldboy-muban chronyd[5553]: Selected source 5.79.108.34 5月 23 13:31:26 bj-oldboy-muban chronyd[5553]: Source 193.182.111.142 replaced with 202.118.1.130 5月 23 13:35:36 bj-oldboy-muban chronyd[5553]: Selected source 202.118.1.130 Hint: Some lines were ellipsized, use -l to show in full.
手动修改日期
[root@bj-oldboy-muban 15:53:03 ~]# timedatectl set-time 2022-05-20
[root@bj-oldboy-muban 00:00:00 ~]# timedatectl
Local time: 五 2022-05-20 00:00:01 CST
Universal time: 四 2022-05-19 16:00:01 UTC
RTC time: 四 2022-05-19 16:00:01
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
手动修改时间
[root@bj-oldboy-muban 00:00:01 ~]# timedatectl set-time 15:00:00
[root@bj-oldboy-muban 15:00:00 ~]# timedatectl
Local time: 一 2022-05-23 15:00:01 CST
Universal time: 一 2022-05-23 07:00:01 UTC
RTC time: 一 2022-05-23 07:00:02
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
手动修改日期及时间
[root@bj-oldboy-muban 16:02:57 ~]# timedatectl set-time "2022-05-20 15:00:00"
[root@bj-oldboy-muban 15:00:00 ~]# timedatectl
Local time: 五 2022-05-20 15:00:04 CST
Universal time: 五 2022-05-20 07:00:04 UTC
RTC time: 五 2022-05-20 07:00:04
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
手动同步时间
[root@bj-oldboy-muban 15:00:01 ~]# yum install -y ntpdate 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本 无须任何处理 [root@bj-oldboy-muban 15:58:37 ~]# ntpdate time.windows.com 23 May 15:59:09 ntpdate[5759]: adjust time server 52.231.114.183 offset 0.010921 sec [root@bj-oldboy-muban 15:59:09 ~]# timedatectl Local time: 一 2022-05-23 15:59:27 CST Universal time: 一 2022-05-23 07:59:27 UTC RTC time: 一 2022-05-23 07:04:13 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: n/a
作用:避免乱码,实现中文信息显示
字符编码环境变量:LANG
** 查看环境变量配置信息:echo $变量**
[root@bj-oldboy-muban 16:12:31 ~]# echo $LANG
en_US.utf8
[root@bj-oldboy-muban 16:16:04 ~]# localectl list-locales aa_DJ aa_DJ.iso88591 aa_DJ.utf8 aa_ER aa_ER.utf8 aa_ER.utf8@saaho aa_ER@saaho aa_ET aa_ET.utf8 af_ZA af_ZA.iso88591 af_ZA.utf8 am_ET am_ET.utf8 an_ES an_ES.iso885915 an_ES.utf8 ar_AE ar_AE.iso88596 ar_AE.utf8 ar_BH ar_BH.iso88596 ar_BH.utf8 ar_DZ ar_DZ.iso88596 ar_DZ.utf8 ar_EG ar_EG.iso88596 ...skipping... zh_CN zh_CN.gb18030 zh_CN.gb2312 zh_CN.gbk zh_CN.utf8 zh_HK zh_HK.big5hkscs zh_HK.utf8 zh_SG zh_SG.gb2312 zh_SG.gbk zh_SG.utf8 zh_TW zh_TW.big5 zh_TW.euctw zh_TW.utf8 zu_ZA zu_ZA.iso88591 zu_ZA.utf8 ~ ~ ~ ~ ~ ~ ~ ~ ~ /zh_CN
[root@bj-oldboy-muban 16:22:51 ~]# LANG=zh_CN.utf8
[root@bj-oldboy-muban 16:23:29 ~]# echo $LANG
zh_CN.utf8
[root@bj-oldboy-muban 16:24:31 ~]# vim /etc/locale.conf
LANG="zh_CN.UTF-8"
[root@bj-oldboy-muban 16:28:40 ~]# localectl set-locale LANG=zh_CN.utf8
使用sed命令将79行内容“GSSAPIAuthentication yes”改为“GSSAPIAuthentication no”,将115行内容“#UseDNS yes”为“UseDNS no”
[root@bj-oldboy-muban 16:46:21 ~]# sed -i '79s#yes#no#g' /etc/ssh/sshd_config #不输入-i只是模拟修改并输出修改后的内容,先模拟输入,确认无误后,再加入-i(insert)才能保存修改。79为行号,可以修改指定行的内容 [root@bj-oldboy-muban 16:58:39 ~]# sed -i 's@#UseDNS yes@UseDNS no@g' /etc/ssh/sshd_config [root@bj-oldboy-muban 16:59:26 ~]# cat -n /etc/ssh/sshd_config 1 # $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $ 2 3 # This is the sshd server system-wide configuration file. See 4 # sshd_config(5) for more information. 5 6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin 7 8 # The strategy used for options in the default sshd_config shipped with 9 # OpenSSH is to specify options with their default value where 10 # possible, but leave them commented. Uncommented options override the 11 # default value. 12 13 # If you want to change the port on a SELinux system, you have to tell 14 # SELinux about this change. 15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER 16 # 17 #Port 22 18 #AddressFamily any 19 #ListenAddress 0.0.0.0 20 #ListenAddress :: 21 22 HostKey /etc/ssh/ssh_host_rsa_key 23 #HostKey /etc/ssh/ssh_host_dsa_key 24 HostKey /etc/ssh/ssh_host_ecdsa_key 25 HostKey /etc/ssh/ssh_host_ed25519_key 26 27 # Ciphers and keying 28 #RekeyLimit default none 29 30 # Logging 31 #SyslogFacility AUTH 32 SyslogFacility AUTHPRIV 33 #LogLevel INFO 34 35 # Authentication: 36 37 #LoginGraceTime 2m 38 #PermitRootLogin yes 39 #StrictModes yes 40 #MaxAuthTries 6 41 #MaxSessions 10 42 43 #PubkeyAuthentication yes 44 45 # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 46 # but this is overridden so installations will only check .ssh/authorized_keys 47 AuthorizedKeysFile .ssh/authorized_keys 48 49 #AuthorizedPrincipalsFile none 50 51 #AuthorizedKeysCommand none 52 #AuthorizedKeysCommandUser nobody 53 54 # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts 55 #HostbasedAuthentication no 56 # Change to yes if you don't trust ~/.ssh/known_hosts for 57 # HostbasedAuthentication 58 #IgnoreUserKnownHosts no 59 # Don't read the user's ~/.rhosts and ~/.shosts files 60 #IgnoreRhosts yes 61 62 # To disable tunneled clear text passwords, change to no here! 63 #PasswordAuthentication yes 64 #PermitEmptyPasswords no 65 PasswordAuthentication yes 66 67 # Change to no to disable s/key passwords 68 #ChallengeResponseAuthentication yes 69 ChallengeResponseAuthentication no 70 71 # Kerberos options 72 #KerberosAuthentication no 73 #KerberosOrLocalPasswd yes 74 #KerberosTicketCleanup yes 75 #KerberosGetAFSToken no 76 #KerberosUseKuserok yes 77 78 # GSSAPI options 79 GSSAPIAuthentication no 80 GSSAPICleanupCredentials no 81 #GSSAPIStrictAcceptorCheck yes 82 #GSSAPIKeyExchange no 83 #GSSAPIEnablek5users no 84 85 # Set this to 'yes' to enable PAM authentication, account processing, 86 # and session processing. If this is enabled, PAM authentication will 87 # be allowed through the ChallengeResponseAuthentication and 88 # PasswordAuthentication. Depending on your PAM configuration, 89 # PAM authentication via ChallengeResponseAuthentication may bypass 90 # the setting of "PermitRootLogin without-password". 91 # If you just want the PAM account and session checks to run without 92 # PAM authentication, then enable this but set PasswordAuthentication 93 # and ChallengeResponseAuthentication to 'no'. 94 # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several 95 # problems. 96 UsePAM yes 97 98 #AllowAgentForwarding yes 99 #AllowTcpForwarding yes 100 #GatewayPorts no 101 X11Forwarding yes 102 #X11DisplayOffset 10 103 #X11UseLocalhost yes 104 #PermitTTY yes 105 #PrintMotd yes 106 #PrintLastLog yes 107 #TCPKeepAlive yes 108 #UseLogin no 109 #UsePrivilegeSeparation sandbox 110 #PermitUserEnvironment no 111 #Compression delayed 112 #ClientAliveInterval 0 113 #ClientAliveCountMax 3 114 #ShowPatchLevel no 115 UseDNS no
挂载:给磁盘开了一个门,可以利用这个门将数据存储到磁盘中
让目录与磁盘分区建立关系的过程,就是挂载过程,挂载过程中目录称为挂载点
卸载:将磁盘设备上的门拆除掉,解除设备文件与目录之间的关系
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9UdwJmwe-1654492271978)(image/image_H_oI2hc8CE.png)]
mount /dev/sdb3(设备文件信息) /oldboy(挂载点目录)
umount /oldboy(挂载点目录信息)
[root@oldboy ~]# ll /dev/cdrom
lrwxrwxrwx. 1 root root 3 5月 17 08:55 /dev/cdrom -> sr0
[root@oldboy ~]# mkdir /oldgirl [root@oldboy ~]# mount /dev/cdrom /oldgirl mount: /dev/sr0 写保护,将以只读方式挂载 [root@oldboy ~]# ll /oldgirl/ 总用量 678 -rw-rw-r--. 1 root root 14 5月 2 2018 CentOS_BuildTag drwxr-xr-x. 3 root root 2048 5月 4 2018 EFI -rw-rw-r--. 1 root root 227 8月 30 2017 EULA -rw-rw-r--. 1 root root 18009 12月 10 2015 GPL drwxr-xr-x. 3 root root 2048 5月 4 2018 images drwxr-xr-x. 2 root root 2048 5月 4 2018 isolinux drwxr-xr-x. 2 root root 2048 5月 4 2018 LiveOS drwxrwxr-x. 2 root root 655360 5月 4 2018 Packages drwxrwxr-x. 2 root root 4096 5月 4 2018 repodata -rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 5月 4 2018 TRANS.TBL
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZXLLFkNp-1654492271979)(image/image_YNWOzzHVIK.png)]
[root@bj-oldboy-muban 13:17:53 ~]# tree -L 1 / / ├── bin -> usr/bin #存放系统命令文件(二进制文件 bin=binnary=二进制)目录 -> 代表软连接,相当于快捷方式 cd /bin(快捷方式) = cd /usr/bin 若命令文件丢失,可以拷贝同版本的其他Linux系统里的命令文件到/bin下使用 ├── sbin -> usr/sbin #存放系统命令文件(二进制文件 sbin=super binnary)目录 此目录中大部分命令只能由root使用,如shutdown ├── boot #存放系统启动引导文件信息,没有特殊需求不要动里面的文件 ├── dev #device 存放系统设备文件信息 ├── etc #存放系统或服务配置文件信息 ├── home #存放用户家目录信息 普通用户可以在家目录里“为所欲为” ├── root #存放管理员用户家目录 ├── var #存储可变的文件数据信息,比如日志文件 variable 可变的 ├── mnt #作为临时挂载点目录 ├── opt #存储第三方软件程序的目录 ├── usr #存储第三方软件程序的目录 ├── proc #存储系统硬件信息/系统内核配置信息 系统高阶优化时使用 此目录中存储的数据信息都在内存中,编辑文件重启系统后恢复原样 ├── tmp #类似Windows系统回收站/进行数据临时存储 比如可将想要删除的数据剪切到/tmp中,若过几天后系统及服务依然没有异常,则可以删除几天前剪切到/tmp目录中想要删除的文件 ├── lib -> usr/lib #系统或软件服务程序库文件存储目录(32位——识别内存容量最大4G) 库文件:开发软件程序需要依赖库文件 安装的某些软件需要调用库文件,所以不能动 ├── lib64 -> usr/lib64 #系统或软件服务程序库文件存储目录(64位——识别内存容量最大128G) ├── media ├── run ├── srv ├── sys
路径信息:/etc/sysconfig/network-scripts/ifcfg-eth0
内容信息:
TYPE=Ethernet #设置网络类型(如以太网Ethernet、快速以太网FastEthernet、FDDI光纤网络等) PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none #是否自动获取IP地址 none/static(静态IP) dhcp(自动获取) DEFROUTE=yes #是否激活静态默认路由条目 如果没有激活则主机无法访问外网 IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 #网卡名称 UUID=e730adf1-fded-4146-979d-14cb1cf8ec7a #系统硬件标识信息 DEVICE=eth0 #网卡名称 ONBOOT=yes #是否激活网卡状态 IPADDR=10.6.132.40 #IP地址 PREFIX=24 #子网掩码 GATEWAY=10.6.132.1 #网关地址 DNS1=10.6.3.254 #DNS地址 IPV6_PRIVACY=no
[root@bj-oldboy-muban 15:33:37 bin]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 UUID=e730adf1-fded-4146-979d-14cb1cf8ec7a DEVICE=eth0 ONBOOT=yes IPADDR=10.6.132.40 PREFIX=24 GATEWAY=10.6.132.1 DNS1=10.6.3.254 IPV6_PRIVACY=no
[root@bj-oldboy-muban 16:17:01 bin]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@bj-oldboy-muban 16:20:00 bin]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos_test/root rd.lvm.lv=centos_test/swap biosdevname=0 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@bj-oldboy-muban 16:26:36 ~]# grub2 -mkconfig -o /boot/grub2/grub.cfg
[root@bj-oldboy-muban 16:27:40 ~]# reboot
路径信息:/etc/resolv.conf
内容信息:
# Generated by NetworkManager
nameserver 10.6.3.254
作用:影响系统域名访问
路径信息:/etc/hosts
内容信息:
10.0.0.2 BJ-oldboy-db #IP地址 域名信息
[root@bj-oldboy-muban 11:44:05 ~]# curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
[root@bj-oldboy-muban 10:34:22 ~]# systemctl start firewalld #开启防火墙服务
[root@bj-oldboy-muban 10:34:22 ~]# systemctl stop firewalld #关闭防火墙服务(临时)
[root@bj-oldboy-muban 10:34:22 ~]# systemctl disable firewalld #永久关闭防火墙服务
[root@bj-oldboy-muban 10:34:22 ~]# systemctl enable firewalld #永久开启防火墙服务
[root@bj-oldboy-muban 10:34:22 ~]# systemctl is-active firewalld #查看防火墙是否开启
active #active代表开启
[root@bj-oldboy-muban 10:34:22 ~]# systemctl is-active firewalld #查看防火墙是否开启
unknown #unkown代表关闭
[root@bj-oldboy-muban 10:34:22 ~]# systemctl is-enabled firewalld #查看防火墙是否开启
enabled #enabled代表永久开启
[root@bj-oldboy-muban 10:34:22 ~]# systemctl is-enabled firewalld #查看防火墙是否开启
disabled #disabled代表永久关闭
临时关闭:
[root@bj-oldboy-muban 11:03:19 ~]# setenforce 0 #关闭selinux服务,0代表关闭,1代表开启
[root@bj-oldboy-muban 11:03:19 ~]# getenforce #查看selinux服务状态
Enforcing #Enforcing代表开启
[root@bj-oldboy-muban 11:03:19 ~]# getenforce #查看selinux服务状态
Permissive #Permissive代表关闭
永久关闭:
[root@bj-oldboy-muban 11:27:21 ~]# sed -i "7s#enforcing#disabled#g" /etc/selinux/config
[root@bj-oldboy-muban 11:28:00 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
路径信息:/etc/fstab
内容信息:
[root@bj-oldboy-muban 13:24:46 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 15 16:30:31 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_test-root / xfs defaults 0 0
UUID=3ccf3999-fe50-43ae-9a7c-7485bd34be19 /boot xfs defaults 0 0
/dev/mapper/centos_test-swap swap swap defaults 0 0
第一列表示进行挂载时存储设备文件信息,可以使用设备UUID信息替代
第二列表示进行挂载时指定的挂载点目录
第三列表示信息文件系统类型(数据存储到磁盘的方式)
NTFS:可以粘贴存储容量的数据
FAT32:只能粘贴存储小于4G的单个文件/目录
Linux 推荐使用xfs, 因为效率高,早期Linux为了保证数据安全性,使用ext3/ext4,但效率低
第四列表示挂载参数配置信息
[root@bj-oldboy-muban 13:24:51 ~]# mount -o ro /dev/sdb /mnt #ro代表readonly,只读权限
[root@bj-oldboy-muban 13:24:51 ~]# mount -o rw /dev/sdb /mnt #rw代表read write,读写权限
defaults默认参数就含有rw,读写权限
第五列表示是否开启数据自动保存机制
1代表开启,0代表关闭。由于开启后写入数据时,会在数据写入内存的同时在磁盘lost/目录中存放一份(以防设备突然断电导致数据丢失),导致磁盘空间的浪费,所以不建议开启。
第六列表示是否开启磁盘自检机制
不建议开启,有需求的话手动执行磁盘扫描,因为扫描检查磁盘过程会对磁盘造成损坏
[root@bj-oldboy-muban 13:59:28 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 15 16:30:31 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_test-root / xfs defaults 0 0
UUID=3ccf3999-fe50-43ae-9a7c-7485bd34be19 /boot xfs defaults 0 0
/dev/mapper/centos_test-swap swap swap defaults 0 0
/dev/sdb /mnt xfs defaults 0 0
[root@bj-oldboy-muban 13:59:28 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 15 16:30:31 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_test-root / xfs defaults 0 0
UUID=3ccf3999-fe50-43ae-9a7c-7485bd34be19 /boot xfs defaults 0 0
/dev/mapper/centos_test-swap swap swap defaults 0 0
/dev/cdroom /mnt iso9660 defaults 0 0
路径信息:/etc/rc.local →/etc/rc.d/rc.local
内容信息:
[root@bj-oldboy-muban 14:57:15 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
若要使/etc/rc.local 文件功能生效,需要执行:
[root@bj-oldboy-muban 14:58:42 ~]# chmod +x /etc/rc.d/rc.local
e.g.
系统开机后自动备份网卡文件、dns解析文件及fstab文件
[root@bj-oldboy-muban 15:41:56 ~]# vim /etc/rc.d/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local Date_info=$(date "+%F") #将命令date “+%F”的执行结果复制给变量Date_info需将命令写在$()内 cp /etc/sysconfig/network-scripts/ifcfg-eth0 /backup/ifcfg-eth0_${Date_info} cp /etc/hosts /backup/hosts_${Date_info} cp /etc/resolv.conf /backup/resolv.conf_${Date_info} cp /etc/fstab /backup/fastab_${Date_info} :wq [root@bj-oldboy-muban 15:44:47 ~]# reboot Connection closing...Socket close. Connection closed by foreign host. Disconnected from remote host(test.com_10.6.132.40) at 15:46:07. Type `help' to learn how to use Xshell prompt. [F:\~]$ Reconnecting in 3 seconds. Press any key to exit local shell. ... Connecting to 10.6.132.40:22... ...............Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Wed May 25 15:41:37 2022 from 10.6.136.196 [root@bj-oldboy-muban 15:46:25 ~]# ll /backup/ 总用量 16 -rw-r--r-- 1 root root 475 5月 25 15:46 fastab_2022-05-25 -rw-r--r-- 1 root root 158 5月 25 15:46 hosts_2022-05-25 -rw-r--r-- 1 root root 358 5月 25 15:46 ifcfg-eth0_2022-05-25 -rw-r--r-- 1 root root 52 5月 25 15:46 resolv.conf_2022-05-25
系统运行级别:系统启动后加载的服务
0 关机级别 init 0
1 单用户级别:系统正常启动,但不会运行网络服务。用于修复系统、破解系统密码 init 1
2 多用户级别:不支持网络服务 init 2
3 多用户级别:支持网络服务(常用)init 3
[root@bj-oldboy-muban 15:46:30 ~]# runlevel
N 3 #N代表之前运行的级别,但由于之前没有用过其他级别,故显示N
4 预留未设置
5 系统图形化界面 init 5
6 重启级别 init 6
永久修改系统默认运行级别:
CentOS6:修改第26行id:后的数字为相应的运行级别
vim /etc/inittab
26 id:3:initdefault:
CentOS7:使用systemctl set-default命令
[root@bj-oldboy-muban 16:55:27 ~]# ll /usr/lib/systemd/system/runlevel*target #查看系统运行级别的target
lrwxrwxrwx. 1 root root 15 3月 15 16:31 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 3月 15 16:31 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 3月 15 16:31 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 3月 15 16:31 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 3月 15 16:31 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 3月 15 16:31 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 3月 15 16:31 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[root@bj-oldboy-muban 16:56:01 ~]# systemctl get-default #查看系统默认运行级别
multi-user.target
[root@bj-oldboy-muban 16:57:12 ~]# systemctl set-default graphical.target #永久设置系统默认运行级别
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Fky6pr5j-1654492271980)(image/image_wP_f4S5mAl.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1EzknerQ-1654492271980)(image/image_cWblSUnOfW.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oiE7DQbY-1654492271981)(image/image_dPfOM6HJSz.png)]
sh-4.2# mount -o remount,rw /
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6n2Mrlzb-1654492271981)(image/image_6fL3ByrntC.png)]
sh-4.2#passwd
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-19hlgYc2-1654492271982)(image/image_eucJJ1rsve.png)]
sh-4.2#touch /.autorelabel
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fQR8o8gP-1654492271982)(image/image_MzxNl4-qNJ.png)]
sh-4.2#exec /sbin/init
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ulnL07Uy-1654492271982)(image/image_hrjrVhtFhW.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0DXY79Dg-1654492271983)(image/image_uYn-nDA8Yp.png)]
参考博文:
史上最简单的CentOS7破解密码方法,有图有真相 - 我就#是我 - 博客园 (cnblogs.com)
/etc/motd 配置在用户登录系统之后显示的提示信息
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-diM6K6t3-1654492271983)(image/image_h461K-FMwx.png)]
[root@bj-oldboy-muban 17:16:04 ~]# vim /etc/motd
#运维人员操作规范
1.所有数据编写修改前进行备份
2.所有服务启动后进行测试检查
3.使用root用户权限需要申请
4.所有重要文件修改后要保存到备份服务器上
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BPF9MSLH-1654492271984)(image/image_P33P58fMu7.png)]
/etc/issue 配置在用户登录系统之前显示的提示信息
[root@bj-oldboy-muban 17:24:45 ~]# vim /etc/issue
oldboylinux
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C7ocyHzc-1654492271984)(image/image_XgUMOa56aA.png)]
设置变量:可以让变量永久生效
/etc/profile与/etc/bashrc 全局生效。这两个文件作用相同,修改任意一个即可
~/.bashrc与~/.bash_profile 局部生效,只对指定用户(根据家目录判断)生效,其他用户不生效。这两个文件作用相同,修改任意一个即可
注意:局部设置优先级高于全局设置
[root@bj-oldboy-muban 14:03:14 ~]# source /etc/profile
或者
[root@bj-oldboy-muban 14:06:50 ~]# . /etc/profile
设置别名:可以让复杂命令简单化
/etc/profile与/etc/bashrc /.bashrc与/.bash_profile 都可以使别名全局生效
注意:别名名称尽量不要和已有命令名称冲突
e.g.
[root@bj-oldboy-muban 14:07:04 ~]# alias ifnet0='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@bj-oldboy-muban 16:11:31 ~]# vim /etc/profile umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge User_color='\[\e[34;1m\]' Hostname_color='\[\e[32;1m\]' Time_color='\[\e[33;1m\]' Path_color='\[\e[31;1m\]' End_color='\[\e[0m\]' #PS1='[\[\e[34;1m\]\u\[\e[0m\]@\[\e[32;1m\]\h\[\e[0m\] \[\e[33;1m\]\t\[\e[0m\] \[\e[31;1m\]\W\[\e[0m\]]\$' PS1="[${User_color}\u${End_color}@${Hostname_color}\h${End_color} ${Time_color}\t${End_color} ${Path_color}\W${End_color }]\\$ " alias ifnet0='cat /etc/sysconfig/network-scripts/ifcfg-eth0' "/etc/profile" 86L, 2247C 已写入 [root@bj-oldboy-muban 16:11:59 ~]# . /etc/profile [root@bj-oldboy-muban 16:12:51 ~]# ifnet0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 UUID=e730adf1-fded-4146-979d-14cb1cf8ec7a DEVICE=eth0 ONBOOT=yes IPADDR=10.6.132.40 PREFIX=24 GATEWAY=10.6.132.1 DNS1=10.6.3.254 IPV6_PRIVACY=no
[root@bj-oldboy-muban 16:13:12 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ifnet0='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@bj-oldboy-muban 16:18:53 ~]# unalias cp
[root@bj-oldboy-muban 16:24:28 ~]# /bin/cp /etc/hosts /tmp/
[root@bj-oldboy-muban 16:57:31 ~]# \cp /etc/hosts /tmp/
e.g.将rm命令设置一个别名,使其删除的信息移动到临时目录
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PY9m27gm-1654492271985)(image/image_9Hx8vmUNLp.png)]
[root@bj-oldboy-muban 17:07:03 ~]# vim ~/.bashrc # .bashrc # User specific aliases and functions #alias rm='rm -i' #注释别名局部配置文件中关于rm别名的设置 alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi [root@bj-oldboy-muban 17:16:54 ~]# vim /etc/profile umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge User_color='\[\e[34;1m\]' Hostname_color='\[\e[32;1m\]' Time_color='\[\e[33;1m\]' Path_color='\[\e[31;1m\]' End_color='\[\e[0m\]' #PS1='[\[\e[34;1m\]\u\[\e[0m\]@\[\e[32;1m\]\h\[\e[0m\] \[\e[33;1m\]\t\[\e[0m\] \[\e[31;1m\]\W\[\e[0m\]]\$' PS1="[${User_color}\u${End_color}@${Hostname_color}\h${End_color} ${Time_color}\t${End_color} ${Path_color}\W${End_color }]\\$ " alias ifnet0='cat /etc/sysconfig/network-scripts/ifcfg-eth0' alias rm='mv -t /tmp' 将rm别名设置在别名全局配置文件中 [root@bj-oldboy-muban 17:05:11 ~]# rm /root/test.txt [root@bj-oldboy-muban 17:05:34 ~]# ll /tmp/ 总用量 4 drwx------ 3 root root 17 5月 26 13:32 systemd-private-fda420ce1a08461e82514bbde0cf1918-chronyd.service-EG3f85 -rw-r--r-- 1 root root 37 5月 26 16:52 test.txt drwx------. 2 root root 6 5月 19 13:52 vmware-root [root@bj-oldboy-muban 17:06:37 ~]# ll /root/ 总用量 8 -rw-------. 1 root root 1508 3月 15 16:35 anaconda-ks.cfg -rw-r--r--. 1 root root 124 5月 19 15:59 test.sh
rm -rf oldboy/.写上一些隐藏文件名称开头字符再加上通配符*进行删除
e.g.
[root@bj-oldboy-muban 13:21:44 ~]# mkdir -p oldboy/oldgirl [root@bj-oldboy-muban 13:22:39 ~]# touch oldboy/.oldboy{01..03} [root@bj-oldboy-muban 13:23:31 ~]# touch oldboy/oldgirl/.oldgirl{01..03} [root@bj-oldboy-muban 13:23:50 ~]# ll -a oldboy/ 总用量 8 drwxr-xr-x 3 root root 72 5月 28 13:23 . dr-xr-x---. 4 root root 4096 5月 28 13:22 .. -rw-r--r-- 1 root root 0 5月 28 13:23 .oldboy01 -rw-r--r-- 1 root root 0 5月 28 13:23 .oldboy02 -rw-r--r-- 1 root root 0 5月 28 13:23 .oldboy03 drwxr-xr-x 2 root root 60 5月 28 13:23 oldgirl [root@bj-oldboy-muban 13:23:55 ~]# ll -a oldboy/oldgirl/ 总用量 0 drwxr-xr-x 2 root root 60 5月 28 13:23 . drwxr-xr-x 3 root root 72 5月 28 13:23 .. -rw-r--r-- 1 root root 0 5月 28 13:23 .oldgirl01 -rw-r--r-- 1 root root 0 5月 28 13:23 .oldgirl02 -rw-r--r-- 1 root root 0 5月 28 13:23 .oldgirl03 [root@bj-oldboy-muban 13:31:08 oldboy]# rm -rf /root/oldboy/.o* [root@bj-oldboy-muban 13:31:28 oldboy]# ll -a /root/oldboy/ 总用量 8 drwxr-xr-x 3 root root 21 5月 28 13:31 . dr-xr-x---. 4 root root 4096 5月 28 13:22 .. drwxr-xr-x 2 root root 60 5月 28 13:23 oldgirl [root@bj-oldboy-muban 13:31:34 oldboy]# rm -rf /root/oldboy/oldgirl/.o* [root@bj-oldboy-muban 13:32:06 oldboy]# ll -a /root/oldboy/oldgirl/ 总用量 0 drwxr-xr-x 2 root root 6 5月 28 13:32 . drwxr-xr-x 3 root root 21 5月 28 13:31 ..
grep -E “信息1|信息2|信息3” 文件
同时过滤多个信息
[root@bj-oldboy-muban 10:54:42 ~]# cat test.txt
22:30:33 error oldboy123
22:31:23 info oldboy123
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
[root@bj-oldboy-muban 10:56:21 ~]# grep -E "error|Fails" test.txt
22:30:33 error oldboy123
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
grep -i “信息” 文件
忽略大小写过滤文件信息
[root@bj-oldboy-muban 10:54:42 ~]# cat test.txt
22:30:33 error oldboy123
22:31:23 info oldboy123
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
[root@bj-oldboy-muban 10:56:25 ~]# grep -Ei "error|fails" test.txt
22:30:33 error oldboy123
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
grep -Ei “关键字.*(信息|信息)” 文件
根据关键字同时再过滤多个信息需要用()将要过滤的信息括起来,这些信息需要使用|分隔开,使用grep时需要用.*来匹配任意字符
[root@bj-oldboy-muban 10:54:42 ~]# cat test.txt
22:30:33 error oldboy123
22:31:23 info oldboy123
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
[root@bj-oldboy-muban 10:58:14 ~]# grep -Ei "22:.*(error|fails)" test.txt #查看22点含有error或者fails的错误日志
22:30:33 error oldboy123
22:31:34 Fails oldboy123
grep -B n 文件
但现实情况中很多时候报错的原因是在报错信息的上一行,则需要grep -B n来过滤信息(B是Before,n表示以上几行)
[root@bj-oldboy-muban 11:09:20 ~]# cat test.txt
22:30:30 network server down
22:30:33 error oldboy123
22:31:23 info oldboy123
22:31:30 ssh server unactive
22:31:34 Fails oldboy123
23:32:30 error oldgirl456
[root@bj-oldboy-muban 11:16:01 ~]# grep -B 1 -Ei "22:.*(error|fails)" test.txt
22:30:30 network server down
22:30:33 error oldboy123
--
22:31:30 ssh server unactive
22:31:34 Fails oldboy123
grep -A n 文件
现实情况中有时候报错的原因会在报错信息下一行显示,则需要grep -A n来过滤信息(B是After,n表示以下几行)
[root@bj-oldboy-muban 11:21:18 ~]# cat test.txt
22:30:33 error oldboy123
22:30:30 network server down
22:31:23 info oldboy123
22:31:34 Fails oldboy123
22:31:30 ssh server unactive
23:32:30 error oldgirl456
[root@bj-oldboy-muban 11:21:22 ~]# grep -A 1 -Ei "22:.*(error|fails)" test.txt
22:30:33 error oldboy123
22:30:30 network server down
--
22:31:34 Fails oldboy123
22:31:30 ssh server unactive
grep -C n 文件
现实情况中还有一些时候报错的原因在报错信息上下行都显示,则需要grep -C n来过滤信息(C是Center,n表示上下几行)
[root@bj-oldboy-muban 11:23:47 ~]# cat test.txt 22:30:20 ip address 10.0.0.300 22:30:33 error oldboy123 22:30:30 network server down 22:31:23 info oldboy123 22:31:25 ssh config info xxx 22:31:34 Fails oldboy123 22:31:30 ssh server unactive 23:32:30 error oldgirl456 [root@bj-oldboy-muban 11:23:55 ~]# grep -C 1 -Ei "22:.*(error|fails)" test.txt 22:30:20 ip address 10.0.0.300 22:30:33 error oldboy123 22:30:30 network server down -- 22:31:25 ssh config info xxx 22:31:34 Fails oldboy123 22:31:30 ssh server unactive
grep -r 目录/*
根据指定目录遍历所有文件查找相应数据内容
[root@bj-oldboy-muban 11:31:23 ~]# cat test.sh #!/bin/bash Info=123 echo oldboy$Info.com echo oldgirledu.cn echo oldbaby$Info.net echo olddogedu.gov echo ${Info}heqing.cn [root@bj-oldboy-muban 11:31:28 ~]# cat test.txt 22:30:20 ip address 10.0.0.300 22:30:33 error oldboy123 22:30:30 network server down 22:31:23 info oldboy123 22:31:25 ssh config info xxx 22:31:34 Fails oldboy123 22:31:30 ssh server unactive 23:32:30 error oldgirl456 [root@bj-oldboy-muban 11:31:46 ~]# grep -r oldbaby ~/* /root/test.sh:echo oldbaby$Info.net
[root@bj-oldboy-muban 17:21:46 ~]# tail -f /var/log/messages
May 27 13:39:18 bj-oldboy-muban systemd-logind: Removed session 33.
May 27 13:53:42 bj-oldboy-muban chronyd[811]: Selected source 120.25.115.20
May 27 14:01:01 bj-oldboy-muban systemd: Started Session 34 of user root.
May 27 14:01:01 bj-oldboy-muban systemd: Starting Session 34 of user root.
May 27 15:01:01 bj-oldboy-muban systemd: Started Session 35 of user root.
May 27 15:01:01 bj-oldboy-muban systemd: Starting Session 35 of user root.
May 27 16:01:01 bj-oldboy-muban systemd: Started Session 36 of user root.
May 27 16:01:01 bj-oldboy-muban systemd: Starting Session 36 of user root.
May 27 17:01:01 bj-oldboy-muban systemd: Started Session 37 of user root.
May 27 17:01:01 bj-oldboy-muban systemd: Starting Session 37 of user root.
[root@bj-oldboy-muban 13:24:15 ~]# cat /var/log/secure
May 27 13:03:34 bj-oldboy-muban sshd[3423]: Accepted password for root from 10.6.136.196 port 60149 ssh2
May 27 13:03:34 bj-oldboy-muban sshd[3423]: pam_unix(sshd:session): session opened for user root by (uid=0)
[root@bj-oldboy-muban 13:29:41 ~]# cat /var/log/secure
May 27 13:29:41 bj-oldboy-muban sshd[3853]: error: Received disconnect from 10.6.136.196 port 54465:0: [preauth]
May 27 13:29:41 bj-oldboy-muban sshd[3824]: pam_systemd(sshd:session): Failed to release session: Interrupted system call
May 27 13:29:41 bj-oldboy-muban sshd[3824]: pam_unix(sshd:session): session closed for user root
[root@bj-oldboy-muban 13:39:32 ~]# tail -f /var/log/secure
May 27 13:40:11 bj-oldboy-muban sshd[3895]: Failed password for root from 10.6.136.196 port 58174 ssh2
grep -c
[root@bj-oldboy-muban 13:42:13 ~]# grep -c "Failed password .* root" /var/log/secure
7
[root@bj-oldboy-muban 13:43:00 ~]# cat /proc/cpuinfo processor : 0 #CPU核心数 需要grep -c vendor_id : GenuineIntel cpu family : 6 model : 85 model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz #CPU型号 stepping : 4 microcode : 0x2000050 cpu MHz : 2394.375 cache size : 14080 KB physical id : 0 #CPU颗数 需要grep -c 但physical id相同时,则要取消计算重复的数目 siblings : 1 core id : 0 cpu cores : 1 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 22 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec ibpb ibrs stibp arat pku ospke spec_ctrl intel_stibp arch_capabilities bogomips : 4788.75 clflush size : 64 cache_alignment : 64 address sizes : 43 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 85 model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz stepping : 4 microcode : 0x2000050 cpu MHz : 2394.375 cache size : 14080 KB physical id : 2 siblings : 1 core id : 0 cpu cores : 1 apicid : 2 initial apicid : 2 fpu : yes fpu_exception : yes cpuid level : 22 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec ibpb ibrs stibp arat pku ospke spec_ctrl intel_stibp arch_capabilities bogomips : 4788.75 clflush size : 64 cache_alignment : 64 address sizes : 43 bits physical, 48 bits virtual power management:
[root@bj-oldboy-muban 15:46:58 ~]# grep "physical id" /proc/cpuinfo
physical id : 0
physical id : 2
[root@bj-oldboy-muban 15:35:30 ~]# grep -c "physical id" /proc/cpuinfo
2
#统计CPU颗数时,要确认physical id要统计不相同的,相同的只计数一次,如两行physical id都是0,则代表CPU颗数是1。
[root@bj-oldboy-muban 15:42:36 ~]# grep -c "processor" /proc/cpuinfo
2
[root@bj-oldboy-muban 15:49:29 ~]# cat /proc/meminfo MemTotal: 3881272 kB #服务器总内存容量 MemFree: 3325368 kB #服务器空闲内存容量 MemAvailable: 3509288 kB #服务器可用内存容量 Buffers: 2108 kB #缓冲区占用的内存容量 Cached: 381784 kB #缓存区占用的内存容量 SwapCached: 0 kB #系统占用交换分区的空间,内存占用满时才会占用交换分区的空间 Active: 321360 kB Inactive: 107080 kB Active(anon): 45096 kB Inactive(anon): 8524 kB Active(file): 276264 kB Inactive(file): 98556 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 6291452 kB SwapFree: 6291452 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 44624 kB Mapped: 25836 kB Shmem: 9072 kB Slab: 46496 kB SReclaimable: 27684 kB SUnreclaim: 18812 kB KernelStack: 1952 kB PageTables: 4520 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 8232088 kB Committed_AS: 244080 kB VmallocTotal: 34359738367 kB VmallocUsed: 151892 kB VmallocChunk: 34359341052 kB HardwareCorrupted: 0 kB AnonHugePages: 6144 kB CmaTotal: 0 kB CmaFree: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 71552 kB DirectMap2M: 3074048 kB DirectMap1G: 3145728 kB
[root@bj-oldboy-muban 16:20:59 ~]# cat /proc/loadavg
0.00 0.01 0.05 1/123 4016 #0.00 每分钟平均负载 0.01 每5分钟平均负载 0.05 每15分钟平均负载
负载值要控制在小于服务器总核心数
[root@bj-oldboy-muban 16:30:38 ~]# cat /proc/mounts rootfs / rootfs rw 0 0 sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 devtmpfs /dev devtmpfs rw,nosuid,size=1928436k,nr_inodes=482109,mode=755 0 0 securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0 tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0 cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0 pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0 cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0 cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0 cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0 cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0 cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0 cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0 cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0 cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0 configfs /sys/kernel/config configfs rw,relatime 0 0 /dev/mapper/centos_test-root / xfs rw,relatime,attr2,inode64,noquota 0 0 systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=9025 0 0 debugfs /sys/kernel/debug debugfs rw,relatime 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0 mqueue /dev/mqueue mqueue rw,relatime 0 0 /dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0 tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=388128k,mode=700 0 0
i install 进行软件安装
v verbose显示安装过程
h hash 显示哈希标记,通过比对哈希标记确认安装包一致 (和 -v 一起使用效果更好)
e.g.
[root@bj-oldboy-muban 15:39:09 Packages]# rpm -ivh tomcat-7.0.76-6.el7.noarch.rpm
获取源码包:
[root@bj-oldboy-muban 15:43:01 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz --2022-05-28 16:12:28-- http://nginx.org/download/nginx-1.18.0.tar.gz 正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ... 正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:1039530 (1015K) [application/octet-stream] 正在保存至: “nginx-1.18.0.tar.gz” 100%[==============================================================================>] 1,039,530 10.5KB/s 用时 85s 2022-05-28 16:13:54 (11.9 KB/s) - 已保存 “nginx-1.18.0.tar.gz” [1039530/1039530]) [root@bj-oldboy-muban 16:13:54 ~]# ll 总用量 1028 -rw-------. 1 root root 1508 3月 15 16:35 anaconda-ks.cfg -rw-r--r-- 1 root root 1039530 4月 21 2020 nginx-1.18.0.tar.gz drwxr-xr-x 3 root root 34 5月 28 14:30 oldboy -rw-r--r--. 1 root root 124 5月 19 15:59 test.sh -rw-r--r-- 1 root root 255 5月 27 11:23 test.txt
./configure --prefix=PATH 修改程序安装路径
--with-xxx 软件可以支持的功能
--without-xxx 取消默认安装的功能
[root@bj-oldboy-muban 16:29:32 ~]# tar xf nginx-1.18.0.tar.gz [root@bj-oldboy-muban 16:29:45 ~]# ll 总用量 1028 -rw-------. 1 root root 1508 3月 15 16:35 anaconda-ks.cfg drwxr-xr-x 8 test01 test01 158 4月 21 2020 nginx-1.18.0 -rw-r--r-- 1 root root 1039530 4月 21 2020 nginx-1.18.0.tar.gz drwxr-xr-x 3 root root 34 5月 28 14:30 oldboy -rw-r--r--. 1 root root 124 5月 19 15:59 test.sh -rw-r--r-- 1 root root 255 5月 27 11:23 test.txt [root@bj-oldboy-muban 16:29:48 ~]# cd nginx-1.18.0/ [root@bj-oldboy-muban 16:34:23 nginx-1.18.0]# ll 总用量 760 drwxr-xr-x 6 test01 test01 326 5月 28 16:29 auto -rw-r--r-- 1 test01 test01 302863 4月 21 2020 CHANGES -rw-r--r-- 1 test01 test01 462213 4月 21 2020 CHANGES.ru drwxr-xr-x 2 test01 test01 168 5月 28 16:29 conf -rwxr-xr-x 1 test01 test01 2502 4月 21 2020 configure drwxr-xr-x 4 test01 test01 72 5月 28 16:29 contrib drwxr-xr-x 2 test01 test01 40 5月 28 16:29 html -rw-r--r-- 1 test01 test01 1397 4月 21 2020 LICENSE drwxr-xr-x 2 test01 test01 21 5月 28 16:29 man -rw-r--r-- 1 test01 test01 49 4月 21 2020 README drwxr-xr-x 9 test01 test01 91 4月 21 2020 src
[root@bj-oldboy-muban 16:48:05 nginx-1.18.0]# yum install -y pcre-devel 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:02 (2/2): epel/x86_64/primary_db | 7.0 MB 00:00:15 正在解决依赖关系 --> 正在检查事务 ---> 软件包 pcre-devel.x86_64.0.8.32-17.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================== Package 架构 版本 源 大小 ======================================================================================================================== 正在安装: pcre-devel x86_64 8.32-17.el7 base 480 k 事务概要 ======================================================================================================================== 安装 1 软件包 总下载量:480 k 安装大小:1.4 M Downloading packages: pcre-devel-8.32-17.el7.x86_64.rpm | 480 kB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : pcre-devel-8.32-17.el7.x86_64 1/1 验证中 : pcre-devel-8.32-17.el7.x86_64 1/1 已安装: pcre-devel.x86_64 0:8.32-17.el7 完毕!
[root@bj-oldboy-muban 16:49:38 nginx-1.18.0]# yum install -y openssl-devel 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 openssl-devel.x86_64.1.1.0.2k-25.el7_9 将被 安装 --> 正在处理依赖关系 openssl-libs(x86-64) = 1:1.0.2k-25.el7_9,它被软件包 1:openssl-devel-1.0.2k-25.el7_9.x86_64 需要 --> 正在处理依赖关系 krb5-devel(x86-64),它被软件包 1:openssl-devel-1.0.2k-25.el7_9.x86_64 需要 --> 正在检查事务 ---> 软件包 krb5-devel.x86_64.0.1.15.1-51.el7_9 将被 安装 ---> 软件包 libss.x86_64.0.1.42.9-11.el7 将被 升级 ---> 软件包 libss.x86_64.0.1.42.9-19.el7 将被 更新 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================== Package 架构 版本 源 大小 ======================================================================================================================== 正在安装: openssl-devel x86_64 1:1.0.2k-25.el7_9 updates 1.5 M 为依赖而安装: keyutils-libs-devel x86_64 1.5.8-3.el7 base 37 k krb5-devel x86_64 1.15.1-51.el7_9 updates 273 k libcom_err-devel x86_64 1.42.9-19.el7 base 32 k libkadm5 x86_64 1.15.1-51.el7_9 updates 179 k libselinux-devel x86_64 2.5-15.el7 base 187 k libsepol-devel x86_64 2.5-10.el7 base 77 k libverto-devel x86_64 0.2.5-4.el7 base 12 k 为依赖而更新: e2fsprogs x86_64 1.42.9-19.el7 base 701 k e2fsprogs-libs x86_64 1.42.9-19.el7 base 168 k krb5-libs x86_64 1.15.1-51.el7_9 updates 1.2 M 事务概要 ======================================================================================================================== 安装 1 软件包 (+ 7 依赖软件包) 升级 ( 11 依赖软件包) 总下载量:6.5 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/19): e2fsprogs-libs-1.42.9-19.el7.x86_64.rpm | 168 kB 00:00:00 (2/19): libcom_err-1.42.9-19.el7.x86_64.rpm | 42 kB 00:00:00 (3/19): krb5-devel-1.15.1-51.el7_9.x86_64.rpm | 273 kB 00:00:00 | 162 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------ 总计 188 kB/s | 6.5 MB 00:00:35 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在更新 : libcom_err-1.42.9-19.el7.x86_64 1/30 正在更新 : libsepol-2.5-10.el7.x86_64 2/30 正在更新 : libselinux-2.5-15.el7.x86_64 3/30 正在更新 : 1:openssl-libs-1.0.2k-25.el7_9.x86_64 已安装: openssl-devel.x86_64 1:1.0.2k-25.el7_9 作为依赖被安装: keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-51.el7_9 libcom_err-devel.x86_64 0:1.42.9-19.el7 libkadm5.x86_64 0:1.15.1-51.el7_9 libselinux-devel.x86_64 0:2.5-15.el7 libsepol-devel.x86_64 0:2.5-10.el7 libverto-devel.x86_64 0:0.2.5-4.el7 作为依赖被升级: e2fsprogs.x86_64 0:1.42.9-19.el7 e2fsprogs-libs.x86_64 0:1.42.9-19.el7 krb5-libs.x86_64 0:1.15.1-51.el7_9 libcom_err.x86_64 0:1.42.9-19.el7 libselinux.x86_64 0:2.5-15.el7 libselinux-python.x86_64 0:2.5-15.el7 libselinux-utils.x86_64 0:2.5-15.el7 libsepol.x86_64 0:2.5-10.el7 libss.x86_64 0:1.42.9-19.el7 openssl.x86_64 1:1.0.2k-25.el7_9 openssl-libs.x86_64 1:1.0.2k-25.el7_9 完毕!
[root@bj-oldboy-muban 16:50:59 nginx-1.18.0]# ./configure --prefix=/application/nginx --with-http_ssl_module --with-http_stub_status_module checking for OS + Linux 3.10.0-862.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for gcc builtin 64 bit byteswap ... found checking for unistd.h ... found checking for inttypes.h ... found checking for limits.h ... found checking for sys/filio.h ... not found checking for sys/param.h ... found checking for sys/mount.h ... found checking for sys/statvfs.h ... found checking for crypt.h ... found checking for Linux specific features checking for epoll ... found checking for EPOLLRDHUP ... found checking for EPOLLEXCLUSIVE ... not found checking for O_PATH ... found checking for sendfile() ... found checking for sendfile64() ... found checking for sys/prctl.h ... found checking for sched_setaffinity() ... found checking for SO_SETFIB ... not found checking for SO_REUSEPORT ... found checking for SO_ACCEPTFILTER ... not found checking for SO_BINDANY ... not found checking for IP_TRANSPARENT ... found checking for IP_BINDANY ... not found checking for IP_BIND_ADDRESS_NO_PORT ... not found checking for IP_RECVDSTADDR ... not found checking for IP_SENDSRCADDR ... not found checking for IP_PKTINFO ... found checking for IPV6_RECVPKTINFO ... found checking for TCP_DEFER_ACCEPT ... found checking for TCP_KEEPIDLE ... found checking for TCP_FASTOPEN ... found checking for TCP_INFO ... found checking for accept4() ... found checking for eventfd() ... found checking for int size ... 4 bytes checking for long size ... 8 bytes checking for long long size ... 8 bytes checking for void * size ... 8 bytes checking for uint32_t ... found checking for uint64_t ... found checking for sig_atomic_t ... found checking for sig_atomic_t size ... 4 bytes checking for socklen_t ... found checking for in_addr_t ... found checking for in_port_t ... found checking for rlim_t ... found checking for uintptr_t ... uintptr_t found checking for system byte ordering ... little endian checking for size_t size ... 8 bytes checking for off_t size ... 8 bytes checking for time_t size ... 8 bytes checking for AF_INET6 ... found checking for setproctitle() ... not found checking for pread() ... found checking for pwrite() ... found checking for pwritev() ... found checking for sys_nerr ... found checking for localtime_r() ... found checking for clock_gettime(CLOCK_MONOTONIC) ... found checking for posix_memalign() ... found checking for memalign() ... found checking for mmap(MAP_ANON|MAP_SHARED) ... found checking for mmap("/dev/zero", MAP_SHARED) ... found checking for System V shared memory ... found checking for POSIX semaphores ... not found checking for POSIX semaphores in libpthread ... found checking for struct msghdr.msg_control ... found checking for ioctl(FIONBIO) ... found checking for ioctl(FIONREAD) ... found checking for struct tm.tm_gmtoff ... found checking for struct dirent.d_namlen ... not found checking for struct dirent.d_type ... found checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... found checking for zlib library ... found creating objs/Makefile Configuration summary + using system PCRE library + using system OpenSSL library + using system zlib library nginx path prefix: "/application/nginx" nginx binary file: "/application/nginx/sbin/nginx" nginx modules path: "/application/nginx/modules" nginx configuration prefix: "/application/nginx/conf" nginx configuration file: "/application/nginx/conf/nginx.conf" nginx pid file: "/application/nginx/logs/nginx.pid" nginx error log file: "/application/nginx/logs/error.log" nginx http access log file: "/application/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
make
[root@bj-oldboy-muban 16:52:08 nginx-1.18.0]# make make -f objs/Makefile make[1]: 进入目录“/root/nginx-1.18.0” cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/nginx.o \ src/core/nginx.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_log.o \ src/core/ngx_log.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_palloc.o \ src/core/ngx_palloc.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_array.o \ src/core/ngx_array.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_list.o \ src/core/ngx_list.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_hash.o \ objs/src/os/unix/ngx_linux_init.o \ objs/src/event/modules/ngx_epoll_module.o \ objs/src/os/unix/ngx_linux_sendfile_chain.o \ objs/src/event/ngx_event_openssl.o \ objs/src/event/ngx_event_openssl_stapling.o \ objs/src/core/ngx_regex.o \ objs/src/http/ngx_http.o \ objs/src/http/ngx_http_core_module.o \ objs/src/http/ngx_http_special_response.o \ objs/src/http/ngx_http_request.o \ objs/src/http/ngx_http_parse.o \ objs/src/http/modules/ngx_http_log_module.o \ objs/src/http/ngx_http_request_body.o \ objs/src/http/ngx_http_variables.o \ objs/src/http/ngx_http_script.o \ objs/src/http/ngx_http_upstream.o \ objs/src/http/ngx_http_upstream_round_robin.o \ objs/src/http/ngx_http_file_cache.o \ objs/src/http/ngx_http_write_filter_module.o \ objs/src/http/ngx_http_header_filter_module.o \ objs/src/http/modules/ngx_http_chunked_filter_module.o \ objs/src/http/modules/ngx_http_range_filter_module.o \ objs/src/http/modules/ngx_http_gzip_filter_module.o \ objs/src/http/ngx_http_postpone_filter_module.o \ objs/src/http/modules/ngx_http_ssi_filter_module.o \ objs/src/http/modules/ngx_http_charset_filter_module.o \ objs/src/http/modules/ngx_http_userid_filter_module.o \ objs/src/http/modules/ngx_http_headers_filter_module.o \ objs/src/http/ngx_http_copy_filter_module.o \ objs/src/http/modules/ngx_http_not_modified_filter_module.o \ objs/src/http/modules/ngx_http_static_module.o \ objs/src/http/modules/ngx_http_autoindex_module.o \ objs/src/http/modules/ngx_http_index_module.o \ objs/src/http/modules/ngx_http_mirror_module.o \ objs/src/http/modules/ngx_http_try_files_module.o \ objs/src/http/modules/ngx_http_auth_basic_module.o \ objs/src/http/modules/ngx_http_access_module.o \ objs/src/http/modules/ngx_http_limit_conn_module.o \ objs/src/http/modules/ngx_http_limit_req_module.o \ objs/src/http/modules/ngx_http_geo_module.o \ objs/src/http/modules/ngx_http_map_module.o \ objs/src/http/modules/ngx_http_split_clients_module.o \ objs/src/http/modules/ngx_http_referer_module.o \ objs/src/http/modules/ngx_http_rewrite_module.o \ objs/src/http/modules/ngx_http_ssl_module.o \ objs/src/http/modules/ngx_http_proxy_module.o \ objs/src/http/modules/ngx_http_fastcgi_module.o \ objs/src/http/modules/ngx_http_uwsgi_module.o \ objs/src/http/modules/ngx_http_scgi_module.o \ objs/src/http/modules/ngx_http_memcached_module.o \ objs/src/http/modules/ngx_http_empty_gif_module.o \ objs/src/http/modules/ngx_http_browser_module.o \ objs/src/http/modules/ngx_http_upstream_hash_module.o \ objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \ objs/src/http/modules/ngx_http_upstream_least_conn_module.o \ objs/src/http/modules/ngx_http_upstream_random_module.o \ objs/src/http/modules/ngx_http_upstream_keepalive_module.o \ objs/src/http/modules/ngx_http_upstream_zone_module.o \ objs/src/http/modules/ngx_http_stub_status_module.o \ objs/ngx_modules.o \ -ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \ -Wl,-E sed -e "s|%%PREFIX%%|/application/nginx|" \ -e "s|%%PID_PATH%%|/application/nginx/logs/nginx.pid|" \ -e "s|%%CONF_PATH%%|/application/nginx/conf/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/application/nginx/logs/error.log|" \ < man/nginx.8 > objs/nginx.8 make[1]: 离开目录“/root/nginx-1.18.0”
make install
[root@bj-oldboy-muban 17:14:49 nginx-1.18.0]# make install make -f objs/Makefile install make[1]: 进入目录“/root/nginx-1.18.0” test -d '/application/nginx' || mkdir -p '/application/nginx' test -d '/application/nginx/sbin' \ || mkdir -p '/application/nginx/sbin' test ! -f '/application/nginx/sbin/nginx' \ || mv '/application/nginx/sbin/nginx' \ '/application/nginx/sbin/nginx.old' cp objs/nginx '/application/nginx/sbin/nginx' test -d '/application/nginx/conf' \ || mkdir -p '/application/nginx/conf' cp conf/koi-win '/application/nginx/conf' cp conf/koi-utf '/application/nginx/conf' cp conf/win-utf '/application/nginx/conf' test -f '/application/nginx/conf/mime.types' \ || cp conf/mime.types '/application/nginx/conf' cp conf/mime.types '/application/nginx/conf/mime.types.default' test -f '/application/nginx/conf/fastcgi_params' \ || cp conf/fastcgi_params '/application/nginx/conf' cp conf/fastcgi_params \ '/application/nginx/conf/fastcgi_params.default' test -f '/application/nginx/conf/fastcgi.conf' \ || cp conf/fastcgi.conf '/application/nginx/conf' cp conf/fastcgi.conf '/application/nginx/conf/fastcgi.conf.default' test -f '/application/nginx/conf/uwsgi_params' \ || cp conf/uwsgi_params '/application/nginx/conf' cp conf/uwsgi_params \ '/application/nginx/conf/uwsgi_params.default' test -f '/application/nginx/conf/scgi_params' \ || cp conf/scgi_params '/application/nginx/conf' cp conf/scgi_params \ '/application/nginx/conf/scgi_params.default' test -f '/application/nginx/conf/nginx.conf' \ || cp conf/nginx.conf '/application/nginx/conf/nginx.conf' cp conf/nginx.conf '/application/nginx/conf/nginx.conf.default' test -d '/application/nginx/logs' \ || mkdir -p '/application/nginx/logs' test -d '/application/nginx/logs' \ || mkdir -p '/application/nginx/logs' test -d '/application/nginx/html' \ || cp -R html '/application/nginx' test -d '/application/nginx/logs' \ || mkdir -p '/application/nginx/logs' make[1]: 离开目录“/root/nginx-1.18.0”
在GitHub下载二进制包
GitHub: Where the world builds software · GitHub
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vgWDbyHZ-1654492271986)(image/image_1fxmFs1nsV.png)]
将下载的二进制包上传到Linux系统中
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aB8XYwxW-1654492271986)(image/image_YsBglFq5m1.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zrHS3UkH-1654492271986)(image/image_XdMuh5TFTl.png)]
[root@bj-oldboy-muban 13:22:15 ~]# unzip sersync-master.zip Archive: sersync-master.zip e6e4cda2583a73a5581d7015255838b5e68673c6 creating: sersync-master/ inflating: sersync-master/.gitattributes inflating: sersync-master/.gitignore inflating: sersync-master/README.md inflating: sersync-master/inotify-tools-3.14.tar.gz extracting: sersync-master/rsync-3.1.1.tar.gz inflating: sersync-master/sersync2.5.4_64bit_binary_stable_final.tar.gz [root@bj-oldboy-muban 13:24:43 ~]# cd sersync-master/ [root@bj-oldboy-muban 13:24:55 sersync-master]# ll 总用量 1948 -rw-r--r-- 1 root root 358772 8月 14 2015 inotify-tools-3.14.tar.gz -rw-r--r-- 1 root root 10838 8月 14 2015 README.md -rw-r--r-- 1 root root 890124 8月 14 2015 rsync-3.1.1.tar.gz -rw-r--r-- 1 root root 727290 8月 14 2015 sersync2.5.4_64bit_binary_stable_final.tar.gz [root@bj-oldboy-muban 13:25:03 sersync-master]# tar -xf sersync2.5.4_64bit_binary_stable_final.tar.gz [root@bj-oldboy-muban 13:25:34 sersync-master]# cd GNU-Linux-x86/ [root@bj-oldboy-muban 13:25:40 GNU-Linux-x86]# ll 总用量 1772 -rwxr-xr-x 1 root root 2214 10月 26 2011 confxml.xml -rwxr-xr-x 1 root root 1810128 10月 26 2011 sersync2 [root@bj-oldboy-muban 13:25:43 GNU-Linux-x86]# cd .. [root@bj-oldboy-muban 13:26:31 sersync-master]# mv GNU-Linux-x86/ /usr/local/sersync [root@bj-oldboy-muban 13:31:49 sersync-master]# cd /usr/local/sersync/ [root@bj-oldboy-muban 13:31:57 sersync]# ll 总用量 1772 -rwxr-xr-x 1 root root 2214 10月 26 2011 confxml.xml -rwxr-xr-x 1 root root 1810128 10月 26 2011 sersync2 [root@bj-oldboy-muban 13:32:00 sersync]# ./sersync2 set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command param daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads) please according your cpu ,use -n param to adjust the cpu rate run the sersync: watch path is: /opt/tongbu
[root@bj-oldboy-muban 16:43:09 ~]# ll -i /etc/hosts
33554980 - rw-r--r--. 1 root root 158 5月 19 15:26 /etc/hosts
① ② ③ ④ ⑤ ⑥ ⑦ ⑧
① 文件属性中的inode信息(inode=index node,索引节点,可以更快的定位数据的存储位置,类似书籍的目录)
② 文件类型信息:- 普通文件,d 目录文件,l 软链接文件
③ 文件权限设置:r 可读,w 可写,x 执行,- 没有权限
注:文件权限付余给3个人:文件拥有者(属主),文件拥有用户组-属组,文件其他用户(权限最小)
④ 文件硬链接数
⑤ 文件的所属用户信息
⑥ 文件的所属组信息
⑦ 文件大小信息
⑧ 文件修改时间
即将学习61课程
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。