分区:
Windows:
C:只装系统,D盘只装程序,E盘存常用数据,F盘存不常用数据
Linux:最少需要几个分区可以安装上系统?1个
/boot:500M
Swap:内存比较大的时候,只要是内存的1/4
/home:
/var:
/:
文件系统:
Ext4:适合小文件
Xfs:适合大文件
定义命令行提示符的变量:
[root@node1 ~]# PS1='\u@\h \t\$ '
root@node1 19:09:10# PS1='[\u@\h \W]\$ '
查看内核版本uname -r
命令执行顺序:
函数>别名>内部命令>外部命令
[root@node1 ~]# lh() { #函数
> ls -lh $*
> }
[root@node1 ~]# lh
[root@node1 ~]# alias lld='ls -ld' #别名
[root@node1 ~]# lld /root
内部命令是系统与生俱来的功能,不用有文件与之对应
[root@node1 ~]# enable # 查看所有的内部命令
[root@node1 ~]# type lh # 判断类型
外部命令需要有命令文件与之对应
主机名在RHEL6中存放在/etc/sysconfig/network
[root@node3 demo]# tr 'a-z' 'A-Z' 将小写转大写,按ctrl+d结束
将文件内容由小写转成大写后打印在屏幕上的两种方法
[root@node3 demo]# cat ~/.bashrc | tr 'a-z' 'A-Z'
[root@node3 demo]# tr 'a-z' 'A-Z' < ~/.bashrc #输入重定向
Here-document:<< 作用就是设置结束标志
[root@node3 demo]# tr 'a-z' 'A-Z' << abc
Find查找文件
1、通过名字查找
[root@node3 demo]# find /boot -name 'vmlinuz*'
2、通过大小查找
[root@node3 demo]# find /boot -size +3M
[root@node3 demo]# find /boot -size +3M -exec ls -lh {} \;
3、查找3天内改过的文件
[root@node3 demo]# find /tmp -mtime -3
编写脚本useradd.sh,直接运行将创建5个用户,也可以通过位置参数$1给定创建用户的数目。用户名是user1/user2/user3/......,用户默认初始密码是123456。用户初次登陆的时候要求立即修改密码。
#!/bin/bash
if [ -z "$1" ]; then
number=5
else
number=$1
fi
counter=0
while [ $counter -lt $number ]
do
let n++
user=user${n}
id $user &> /dev/null
if [ $? -ne 0 ]; then
useradd $user
echo 123456 | passwd --stdin $user &> /dev/null
chage -d0 $user
let counter++
echo -e "create $user ......\t\t\t\033[32;1m[DONE]\033[0m"
fi
done
计划任务
Cron:周期性地执行任务
# crontab -e
01 * * * * command 每个小时的01分
01 20 * * * command 每天20:01
01 20 1 * * command 每月1号20:01
01 20 1 8 * command 每年8月1号20:01
01 20 * * 1 command 每周一的20:01
*/5 8-18 * * 1,3,5 command 每周一三五从8点到18点,每隔5分钟
权限
-rw-------. 1 root root 1838 1月 30 12:17 anaconda-ks.cfg
第一个字符是文件类型,-表示文件,d表示目录,l表示软链接,b表示块设备,c表示字符设备
接下来每三个字符分成一组,分别代表属主u、属组g、其他人o权限。权限分别是读r->4,写w->2,执行x->1。
附加权限
SUID:程序以属主的身份运行。
程序在执行期间是有身份的!
[bob@node1 ~]$ ls /root 失败,因为ls以bob身份执行
[root@node1 ~]# chmod u+s /usr/bin/ls
[bob@node1 ~]$ ls /root 成功,因为ls以root身份执行
[bob@node1 ~]$ touch a.txt
[root@node1 ~]# chmod u+s /usr/bin/touch
[bob@node1 ~]$ touch b.txt
[bob@node1 ~]$ ll 发现b.txt属主是root
SGID:创建的文件/目录继承所在目录的属组
[root@node1 ~]# mkdir /tmp/demo
[root@node1 ~]# chgrp bob /tmp/demo
[root@node1 ~]# ll -d /tmp/demo
[root@node1 ~]# cp /etc/passwd /tmp/demo
[root@node1 ~]# ll /tmp/demo/
-rw-r--r--. 1 root root 2154 7月 11 19:33 passwd
[root@node1 ~]# chmod g+s /tmp/demo/
[root@node1 ~]# cp /etc/hosts /tmp/demo/
[root@node1 ~]# ll /tmp/demo/
-rw-r--r--. 1 root bob 158 7月 11 19:34 hosts
Sticky bit粘滞位:用户只能修改、删除自己的文件
[root@node1 ~]# ll -d /tmp/ /var/tmp/ 在权限最后一位上是t
ACL:访问控制列表。实现权限的精确控制。
LVM:逻辑卷管理。它是动态管理存储空间的方式。首先,将磁盘或分区转换成物理卷PV,再将1到多个PV组合成卷组VG,然后从VG上划分逻辑卷LV。LV就可以像分区一样,进行格式化、挂载。如果LV的空间不够了,还可以实现LV的在线扩容。
nW1H:What/When/Where/Who/How。是什么?是干什么的?怎么干的?
VLAN:虚拟局域网。它用来实现广播控制。当一个二层网络变得非常大的时候,广播规模也会变得非常大,使得每个主机节点可用带宽下降严重。可以根据部门创建VLAN,再将端口加入到VLAN中。为了实现不同交换机上的相同VLAN可以通信,需要配置中继TRUNK;为了实现不同VLAN之间进行通信,需要配置三层交换。
SELinux:安全增强的Linux
1、工作模式:enabled / permissive / disabled
Enabled一旦出现违规,拒绝访问服务
Permissive宽松模式,出现违规,不限制,只记录日志
Disabled禁用
2、更改工作模式
(1)永久修改:/etc/selinux/config
(2)临时:setenforce 0 | 1
3、修改SELINUX上下文环境值(标签)。相当于是文件的锁
[root@localhost ~]# echo 'hello nsd1802' > index.html
[root@localhost ~]# mv index.html /var/www/html/
[root@localhost ~]# sealert -b 根据提示进行排错
[root@localhost ~]# restorecon -Rv /var/www/html/
4、布尔值。功能开关
[root@localhost ~]# yum install -y vsftpd
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
anon_upload_enable=YES
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# mkdir -m 777 /var/ftp/incoming
[root@localhost ~]# yum install -y ftp
[root@localhost ~]# ftp 127.0.0.1
ftp> cd incoming 切换服务器目录
ftp> lcd /etc 切换本地目录
ftp> put hosts 失败
[root@localhost ~]# sealert -b
[root@localhost ~]# chcon -t public_content_rw_t /var/ftp/incoming/
[root@localhost ~]# getsebool -a | grep ftp
[root@localhost ~]# setsebool -P allow_ftpd_anon_write 1
5、端口号
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
Listen 8010
[root@localhost ~]# systemctl restart httpd 失败
[root@localhost ~]# semanage port -a -t http_port_t -p tcp 8010
[root@localhost ~]# systemctl restart httpd