[oceanshadow@localhost ~]$ find /home -type f -name "*.py" #根据文件名查找
/home/oceanshadow/qq.py
/home/oceanshadow/yy.py
#此处r权限:4 w权限:2 x权限:1 ;
[oceanshadow@localhost ~]$ find /home -perm 644 -type f -name "*.py" #644代表:-rw-r-r-,文件所属者具有rw权限,所属组和其他用户具有r权限
/home/oceanshadow/yy.py
[oceanshadow@localhost ~]$ find /home -user root -type f -name "*.py"
/home/oceanshadow/qq.py
/home/oceanshadow/yy.py
find /home -type f -name "*.py" -exec wc -l {} \;
; #可执行多条命令
\ #转义符,转义;使这条命令结束
{} #把find命令匹配到的每一次结果传递给{}
-exec #对传递到结构,执行wc -l命令
[oceanshadow@localhost ~]$ find /home -type f -name "*.py" -exec wc -l {} \; #找到.py文件并统计行数
387 /home/oceanshadow/yy.py
370 /home/oceanshadow/qq.py
[oceanshadow@localhost ~]$ find /home -type f -name "*.py" -exec cp -a {} /home/oceanshadow/file \; #将找到的结果,复制到file目录下
[oceanshadow@localhost ~]$ ll file/
total 8
-rwxr-xr-x. 1 oceanshadow oceanshadow 2830 May 23 17:27 qq.py
-rw-r--r--. 1 oceanshadow oceanshadow 2929 May 24 15:12 yy.py
[oceanshadow@localhost ~]$ find /home -type f -name "*.py" -mtime -2 -exec ls -lrt {} \; #查询2天以内修改过的.py文件
-rw-r--r--. 1 oceanshadow oceanshadow 2929 May 24 15:12 /home/oceanshadow/yy.py
-rw-r--r--. 1 oceanshadow oceanshadow 2929 May 24 15:12 /home/oceanshadow/file/yy.py
-rwxr-xr-x. 1 oceanshadow oceanshadow 2830 May 23 17:27 /home/oceanshadow/file/qq.py
-rwxr-xr-x. 1 root root 2830 May 23 17:27 /home/oceanshadow/qq.py
重点介绍firewalld防火墙。
查看firewalld服务状态
开启、重启、关闭firewalld服务
查看防火墙状态
查看防火墙开放端口规则
开放80端口
关闭80端口
加载生效的开放端口
查询指定端口是否开放
验证80端口是否开放
安装配置Nginx:Nginx (engine x) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器。 本例演示 CentOS 7 下安装和配置 Nginx 的基本步骤。再开放80端口后,用Nginx监听,否则无法telnet测试。
SELinux的三种工作模式:(vi /etc/selinux/config可查看)
安装Nginx操作实例
[root@localhost oceanshadow] cat /etc/redhat-release #查看当前环境
CentOS Linux release 7.5.1804 (Core)
[root@localhost oceanshadow] sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm #Nginx不在默认的 yum 源中,使用官网的yum源。
Updating / installing...
1:nginx-release-centos-7-0.el7.ngx ################################# [100%]
[root@localhost oceanshadow] sudo yum repolist #查看yum 源,nginx repo已安装
nginx | 2.9 kB 00:00:00
nginx/x86_64/primary_db | 54 kB 00:00:02
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,070
extras/7/x86_64 CentOS-7 - Extras 397
nginx/x86_64 nginx repo 188
updates/7/x86_64 CentOS-7 - Updates 671
repolist: 11,326
[root@localhost oceanshadow] sudo yum install nginx #安装nginux
Loaded plugins: fastestmirror, langpacks
----------------------------------------------------------------------
Verifying : 1:nginx-1.18.0-1.el7.ngx.x86_64 1/1
Installed:
nginx.x86_64 1:1.18.0-1.el7.ngx
Complete!
[root@localhost oceanshadow] sudo systemctl enable nginx #设置开机启动nginux
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost oceanshadow] sudo systemctl start nginx #开启nginx服务
[root@localhost oceanshadow] netstat -tunlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26634/nginx: master
udp 0 0 0.0.0.0:68 0.0.0.0:* 68006/dhclient
[root@localhost oceanshadow] sudo systemctl stop nginx #停止nginx服务
[root@localhost oceanshadow] sudo systemctl restart nginx #重启
[root@localhost oceanshadow] sudo systemctl reload nginx #重新加载
防火墙及telnet操作实例:
nginx默认监听80端口,在开启防火墙并监听80端口状态下,通过telnet访问ip:80,在关闭防火墙状态下可以直接telnet ip。
[oceanshadow@localhost ~]$ systemctl status firewalld.service #查看firewalld服务状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-05-22 13:31:40 CST; 2 days ago
Docs: man:firewalld(1)
Main PID: 698 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─698 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
[root@localhost oceanshadow] firewall-cmd --state #查看防火墙状态
running
[root@localhost oceanshadow] firewall-cmd --query-port=80/tcp #查询80端口是否开放
no
[root@localhost oceanshadow] firewall-cmd --permanent --add-port=80/tcp #永久开放80端口
success
[root@localhost oceanshadow] firewall-cmd --permanent --list-ports #查看防火墙端口开放规则
80/tcp
[root@localhost oceanshadow] firewall-cmd --reload #加载生效的端口
success
[root@localhost oceanshadow] firewall-cmd --remove-port=80/tcp #关闭80端口
success
[oceanshadow@localhost ~]$ telnet 192.168.1.106 80 #telnet开着防火墙,监听并开放80端口的主机192.168.1.106:80
Trying 192.168.1.106...
Connected to 192.168.1.106.
Escape character is '^]'.
#将本机yy.py文件拷贝到192.168.1.106的/home目录下
[oceanshadow@localhost ~]$ scp /home/oceanshadow/yy.py root@192.168.1.106:/home/
#将远程主机的yy.py 文件拷贝到本地/Download文件夹下
[oceanshadow@localhost ~]$ scp root@192.168.1.106:/home/yy.py /home/oceanshadow/Downloads/
#将远程主机的oceanshadow文件夹 拷贝到本地/Download文件夹下
[oceanshadow@localhost ~]$ scp -r root@192.168.1.106:/home/oceanshadow /home/oceanshadow/Downloads/
查看进程状态后,当杀死主进程,子进程处于僵尸状态时,手动杀死子进程 kill -9 PID
[oceanshadow@localhost ~]$ ps -ef | more #查看所有进程及父进程ID,暂时显示1页
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 May22 ? 00:00:14 /usr/lib/systemd/systemd --switched-ro
ot --system --deserialize 22
root 2 0 0 May22 ? 00:00:00 [kthreadd]
root 3 2 0 May22 ? 00:00:03 [ksoftirqd/0]
root 5 2 0 May22 ? 00:00:00 [kworker/0:0H]
root 7 2 0 May22 ? 00:00:01 [migration/0]
root 8 2 0 May22 ? 00:00:00 [rcu_bh]
root 9 2 0 May22 ? 00:03:07 [rcu_sched]
root 10 2 0 May22 ? 00:00:00 [lru-add-drain]
root 11 2 0 May22 ? 00:00:01 [watchdog/0]
root 12 2 0 May22 ? 00:00:00 [watchdog/1]
root 13 2 0 May22 ? 00:00:34 [migration/1]
root 14 2 0 May22 ? 00:00:12 [ksoftirqd/1]
root 16 2 0 May22 ? 00:00:00 [kworker/1:0H]
root 17 2 0 May22 ? 00:00:00 [watchdog/2]
root 18 2 0 May22 ? 00:00:01 [migration/2]
root 19 2 0 May22 ? 00:00:03 [ksoftirqd/2]
root 21 2 0 May22 ? 00:00:00 [kworker/2:0H]
root 22 2 0 May22 ? 00:00:00 [watchdog/3]
root 23 2 0 May22 ? 00:00:34 [migration/3]
root 24 2 0 May22 ? 00:00:12 [ksoftirqd/3]
root 26 2 0 May22 ? 00:00:00 [kworker/3:0H]
root 28 2 0 May22 ? 00:00:00 [kdevtmpfs]
--More--
UID:用户ID
PID:进程ID
PPID:父进程号
C:CPU的占用率
STIME:进程的启动时间
TTY:TTY终端
TIME:进程执行起到现在占用CPU的时间
CMD:启动这个进程的命令
[oceanshadow@localhost ~]$ ps -aux | more #查看所有进程及状态,暂时显示1页
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 193908 6652 ? Ss May22 0:14 /usr/lib/systemd/syste
md --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S May22 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S May22 0:03 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< May22 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S May22 0:01 [migration/0]
root 8 0.0 0.0 0 0 ? S May22 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S May22 3:07 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< May22 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S May22 0:01 [watchdog/0]
root 12 0.0 0.0 0 0 ? S May22 0:00 [watchdog/1]
root 13 0.0 0.0 0 0 ? S May22 0:34 [migration/1]
root 14 0.0 0.0 0 0 ? S May22 0:12 [ksoftirqd/1]
root 16 0.0 0.0 0 0 ? S< May22 0:00 [kworker/1:0H]
root 17 0.0 0.0 0 0 ? S May22 0:00 [watchdog/2]
root 18 0.0 0.0 0 0 ? S May22 0:01 [migration/2]
root 19 0.0 0.0 0 0 ? S May22 0:03 [ksoftirqd/2]
root 21 0.0 0.0 0 0 ? S< May22 0:00 [kworker/2:0H]
root 22 0.0 0.0 0 0 ? S May22 0:00 [watchdog/3]
root 23 0.0 0.0 0 0 ? S May22 0:34 [migration/3]
root 24 0.0 0.0 0 0 ? S May22 0:12 [ksoftirqd/3]
root 26 0.0 0.0 0 0 ? S< May22 0:00 [kworker/3:0H]
root 28 0.0 0.0 0 0 ? S May22 0:00 [kdevtmpfs]
--More--
%MEM :内存使用率
VSZ:如果一个程序完全驻留到内存中,需要使用多少内存空间
RSS:进程当前占用了多少内存
STAT:表示当前的进程状态(S:处于休眠状态,D:不可中断状态,Z:僵尸进程,X:死掉的进程)
[oceanshadow@localhost ~]$ ps -ef |grep nginx #查看特定程序进程
oceansh+ 118852 95071 0 12:13 pts/1 00:00:00 grep --color=auto nginx
注意:不加-d选项,默认为制表符,不是空格
[oceanshadow@localhost ~]$ cat /etc/passwd #查看paswd文件
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sssd:x:998:996:User for sssd:/:/sbin/nologin
libstoragemgmt:x:997:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
oceanshadow:x:1000:1000:Centos 7:/home/oceanshadow:/bin/bash
yy:x:2222:0::/home/yy:/bin/bash
[oceanshadow@localhost ~]$ cut -d ':' -f 1 /etc/passwd #以:作为分割符,获取第1列
[oceanshadow@localhost ~]$ cut -d ':' -f 1,3 /etc/passwd #以:作为分割符,获取第1,3列
[oceanshadow@localhost ~]$ cut -d ':' -f 1-3 /etc/passwd #以:作为分割符,获取第1~3列
[oceanshadow@localhost ~]$ cut -d ':' -f 2- /etc/passwd #以:作为分割符,获取最后1列
[oceanshadow@localhost ~]$ cut -c 2-9 /etc/passwd #获取2~9个字符
[oceanshadow@localhost ~]$ cat /etc/passwd | grep '/bin/bash' | cut -d ':' -f 1 #获取所有可登录用户的名称
root
oceanshadow
yy
[oceanshadow@localhost ~]$ cat /etc/passwd | grep '/bin/bash' | cut -d ':' -f 1 | grep -v root #获取所有可登录非root用户的名称
oceanshadow
yy
[oceanshadow@localhost ~]$ printf '%s\t%s\t%s\n' 1 2 3
1 2 3
[oceanshadow@localhost ~]$ cat /etc/passwd | awk 'BEGIN {FS=":"} {print $1}' #打印passwd第一列,此处无条件二,BEGIN:在cat数据没有读进awk之前进行实例化,加入条件,$1代表第1列
[oceanshadow@localhost ~]$ df -h | awk '{print $1}'#打印磁盘容量信息的第一列
Filesystem
/dev/sda3
devtmpfs
tmpfs
tmpfs
tmpfs
/dev/sda1
tmpfs
tmpfs
/dev/sr0
[oceanshadow@localhost ~]$ df -h | awk 'NR==4 {print $1}' #打印第4行第1列
tmpfs
[oceanshadow@localhost ~]$ df -h | awk '(NR>=6 && NR<=8) {print $1}' #打印6~8行,第1列
tmpfs
/dev/sda1
tmpfs
[oceanshadow@localhost ~]$ df -h | awk '(NR>=6 && NR<=8) {print $NF}'#打印6~8行,最后1列
/sys/fs/cgroup
/boot
/run/user/1000
[oceanshadow@localhost ~]$ awk -F":" '{print $1}' /etc/passwd #等同于cat /etc/passwd | awk 'BEGIN {FS=":"} {print $1}'
[oceanshadow@localhost ~]$ df -h | awk '(NR>=6 && NR<=8) {print $1,$2}' #打印6-8行,1和2列
tmpfs 1.9G
/dev/sda1 297M
tmpfs 378M
[oceanshadow@localhost ~]$ df -h | grep -v Filesystem | awk 'BEGIN {print "系统使用文件 情况:" } {printf $1} {printf "\t文件系统使用效率:"} {print $5} END {print "处理完毕"} '
系统使用文件 情况:
/dev/sda3 文件系统使用效率:15%
devtmpfs 文件系统使用效率:0%
tmpfs 文件系统使用效率:0%
tmpfs 文件系统使用效率:2%
tmpfs 文件系统使用效率:0%
/dev/sda1 文件系统使用效率:50%
tmpfs 文件系统使用效率:1%
tmpfs 文件系统使用效率:1%
/dev/sr0 文件系统使用效率:100%
处理完毕
[oceanshadow@localhost ~]$ df -h | sed -n '2p' #打印第二行
/dev/sda3 36G 5.4G 31G 15% /
[oceanshadow@localhost ~]$ df -h | sed '2d' #打印没有第二行的数据
[oceanshadow@localhost ~]$ df -h | sed '2a 1234567890' #在第二行后面插入数据
[oceanshadow@localhost ~]$ df -h | sed '2i 1234567890' #在第二行后面插入数据
[oceanshadow@localhost ~]$ df -h | sed '2c 1234567890' #在第二行后面插入数据
[oceanshadow@localhost ~]$ df -h | sed 's/user/yy/g' #把user替换成yy
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 5.4G 31G 15% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 21M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 148M 150M 50% /boot
tmpfs 378M 44K 378M 1% /run/yy/1000
tmpfs 378M 8.0K 378M 1% /run/yy/42
/dev/sr0 56M 56M 0 100% /run/media/oceanshadow/VMware Tools
[oceanshadow@localhost ~]$ sed -i 's/user/yy/g' df.txt #修改yy.py把user替换成yy
[oceanshadow@localhost ~]$ sed -n '/tmpfs/p' df.txt #非精确搜索
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 21M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 378M 44K 378M 1% /run/yy/1000
tmpfs 378M 8.0K 378M 1% /run/yy/42
[oceanshadow@localhost ~]$ grep -w 'tmpfs' df.txt #精确匹配搜索
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 21M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 378M 44K 378M 1% /run/yy/1000
tmpfs 378M 8.0K 378M 1% /run/yy/42
[oceanshadow@localhost ~]$ sed -e 's/yy/qq/g' -e 's/tmpfs/tmp/g' df.txt #执行多条修改命令
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 5.4G 31G 15% /
devtmp 1.9G 0 1.9G 0% /dev
tmp 1.9G 0 1.9G 0% /dev/shm
tmp 1.9G 21M 1.9G 2% /run
tmp 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 148M 150M 50% /boot
tmp 378M 44K 378M 1% /run/qq/1000
tmp 378M 8.0K 378M 1% /run/qq/42
/dev/sr0 56M 56M 0 100% /run/media/oceanshadow/VMware Tools