内容
Raid 级别及应用场景
磁盘分区格式化挂载,及永久挂载
增加swap及tmpfs
磁盘空间不足inode和block
磁盘空间不足之文件未被删除
系统优化
一、Raid 级别及应用场景
| Raid类型 | 最少盘数 | 安全冗余 | 可用容量 | 性能 | 使用场景 | 举例说明 |
|---|---|---|---|---|---|---|
| Raid0 | 1 | 最低 | 所用硬盘之和 | 读写最快 | 不求安全,之只求速度 | 数据从库、存储从库。 |
| Raid1 | 只能有2块 | 100% | 50% | 写入速度慢,读OK | 只追求安全性,对速度没要求 | 系统盘,监控 |
| Raid5 | 3 | 最多损坏1块 | 损失1块硬盘的容量 | 写入性能不好,读取OK | 对于安全有要求,对于速度要求不高 | 普通数据库,存储访问linag量不高 |
| Raid10 | 4 | 可以损坏一半 | 损失所有硬盘的一半容量 | 读写很快 | 数据安全和性能都要 | 高并发或高访问量数据主库存储 |
PD(Physical Disk):物理磁盘
VD (virtual disk):虚拟磁盘,一般做完Raid 以后系统就识别为VD
二、磁盘分区格式化挂载,及永久挂载
1、磁盘分区(fdisk、parted)
| 分区用到的命令 | 功能 |
|---|---|
| fdisk | 支持2T以内的磁盘分区 |
| parted | 支持大于2T的磁盘分区 |
fdisk -l 查看系统中所有的磁盘及分区相关信息
以下示例
fdisk -l /dev/sdc 查看指定磁盘情况
[root@localhost ~]# fdisk -l /dev/sdc
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xa0bbcbbb
Device Boot Start End Blocks Id System
/dev/sdc1 2048 41943039 20970496 83 Linux
[root@localhost ~]#
Device :设备名称
Boot :Boot下方有*号,表示此分区为引导分区
Start :开始扇区
End :结束扇区
Blocks :容量(以字节为单位)
Id :文件系统ID(Linux中是以ID来识别分区的,标准分区用户83表示,82表示swap分区,5表示扩展分区,fd表示RAID)
System :磁盘系统类型
使用fdisk 对磁盘进行分区
# fdisk /dev/sdb //给磁盘sdb分区
Command (m for help): [选项]
选项:
n 新建分区
d 删除分区
t 修改分区ID
p 显示分区表
l 显示系统中文件系统的ID
w 保存
q 退出
m 帮助
a 设置可引导标志
b 编辑bsk磁盘标签
c 设置DOS系统兼容性标记
o 建立空白的DOS分区表
s 建立空白的SUN磁盘标签
u 更改显示
v 验证分区表
x 附加功能
真实的用对磁盘做分区处理
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p #查看当前磁盘分区情况
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00099058
Device Boot Start End Blocks Id System
Command (m for help): n #创建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #选择主分区
Partition number (1-4, default 1): 1 #第一个分区
First sector (2048-41943039, default 2048): #开始扇区,回车表示从上一个扇区开始。
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): #结束扇区,回车表示到最后一个扇区结束。
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p #查看当前磁盘分区情况
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00099058
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]#
2、磁盘格式化(mkfs...)
命令使用方法 mkfs.ext3 /dev/sbc1
mkfs mkfs.cramfs mkfs.ext3 mkfs.minix
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.xfs
对/dev/sdc做格式化
[root@localhost ~]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkfs #C 7 中的文件系统如下
mkfs mkfs.cramfs mkfs.ext3 mkfs.minix
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.xfs
3、挂载分区(mount)
1.3.1 临时挂载
[root@localhost /]# mount /dev/sdc1 /xiaoxi
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 12G 8.5G 58% /
devtmpfs 481M 0 481M 0% /dev
tmpfs 492M 0 492M 0% /dev/shm
tmpfs 492M 7.5M 484M 2% /run
tmpfs 492M 0 492M 0% /sys/fs/cgroup
tmpfs 500M 0 500M 0% /mem
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 99M 0 99M 0% /run/user/0
/dev/sdb1 20G 33M 20G 1% /data
/dev/sdc1 20G 33M 20G 1% /xiaoxi #挂载位置
[root@localhost /]#
1.3.2 永久挂载
- 编辑/etc/fstab文件
- 执行mount -a 命令
- 检查挂载情况 df
编写 /etc/fstab 格式及每列含义
/etc/fstab每列含义
[root@localhost /]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Apr 12 21:49:43 2019
#
# 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
#
UUID=913120af-26d4-4d10-bfa3-ad698a9b0fb8 / xfs defaults 0 0
UUID=d7199976-4543-4308-81b7-a9c783f6fabc /boot xfs defaults 0 0
UUID=0195d767-3038-4bdb-953c-fbf29897a44e swap swap defaults 0 0
/dev/sdb1 /data xfs defaults 0 0
/dev/sdc1 /xiaoxi xfs defaults 0 0
[root@localhost ~]# umount /dev/sdc1
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 20753408 11914100 8839308 58% /
devtmpfs 491944 0 491944 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7652 495160 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
tmpfs 512000 0 512000 0% /mem
/dev/sda1 201380 107028 94352 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
/dev/sdb1 20960256 32992 20927264 1% /data
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 20753408 11914100 8839308 58% /
devtmpfs 491944 0 491944 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7652 495160 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
tmpfs 512000 0 512000 0% /mem
/dev/sda1 201380 107028 94352 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
/dev/sdb1 20960256 32992 20927264 1% /data
/dev/sdc1 20960256 32992 20927264 1% /xiaoxi
[root@localhost ~]#
小结磁盘分区格式和挂载
1、对磁盘做分区使用命令 fdisk 、parted
2、格式化分区(刷入文件系统)使用命令(mkfs)
3、挂载分区 (临时、永久)使用命令 mount
三、增加swap及tmpfs
查看swap和内存情况 free -h
3.1增加SWAP
第一步:创建指定大小的文件 (dd)
/dev/null 黑洞
/dev/zero 输出
/dev/urandom 用于生成随机数
dd if=/dev/zero of=/tmp/500file bs=1M count=500
if=/dev/zero ==输入文件
of=/tmp/500file == 输出文件
bs=1M ==每次填充多大
count=500 ==填充500次
第二步:将文件刷为swap文件系统(mkswap )
mkswap /tmp/500file
第三步:使创建的swap文件生效挂载(生效:swapon、失效:swapoff)**
**swapon /tmp/500file 临时生效**
**永挂载:编辑/etc/fstab :/tmp/500file swap swap defaults 0 0**
完整演示
[root@localhost /]# dd if=/dev/zero of=/tmp/500file bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 3.7824 s, 139 MB/s
[root@localhost /]# mkswap /tmp/500file
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=2fd5df0a-3ba0-4e13-b73f-1e5daf9c775e
[root@localhost /]# swapon /tmp/500file
swapon: /tmp/500file: insecure permissions 0644, 0600 suggested.
[root@localhost /]# vim /etc/fstab #将(/etc/fstab :/tmp/500file swap swap defaults 0 0 )
3.2 特殊的文件系统 tmpfs(一般用来存放软件的缓存,重启这个目录里的数据就会丢失,但是读写速度快,充当内存使用)
(1)、创建一个目录 mkdir
(2)、指定类型挂载 mount -t tmpfs -o size=500m tmpfs /mem (临时挂载)
编辑 /etc/fstab 写入:tmpfs /mem tmpfs size=500m 0 0 (永久挂载)
(3)、测试写入速度 dd if=/dev/zero of=/mem/test bs=1M count=500
演示:
[root@localhost ~]# mkdir /test
[root@localhost ~]# mount -t tmpfs -o size=500m tmpfs /test
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 20753408 12426140 8327268 60% /
devtmpfs 491944 0 491944 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7684 495128 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
/dev/sda1 201380 107028 94352 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
/dev/sdb1 20960256 32992 20927264 1% /data
/dev/sdc1 20960256 32992 20927264 1% /xiaoxi
tmpfs 512000 0 512000 0% /test
[root@localhost ~]#
系统优化
1.基础
(1)关闭SElinux和firewalld
[root@oldboyedu-muban ~]# vi /etc/selinux/config
[root@oldboyedu-muban ~]# setenforce 0
[root@oldboyedu-muban ~]# systemctl stop firewalld
[root@oldboyedu-muban ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
(2) 网络管理服务
systemctl stop NetworkManager
systemctl disable NetworkManager
(3) sudo权限
[root@oldboyedu-muban ~]# grep oldboy /etc/sudoers
oldboy ALL=(ALL) NOPASSWD: ALL
(4) 情况泄漏系统版本信息的文件
[root@oldboyedu-muban ~]# >/etc/issue
[root@oldboyedu-muban ~]# >/etc/issue.net
2.服务
(1) sshd
[root@oldboyedu-muban ~]# ll /etc/ssh/sshd_config
-rw-------. 1 root root 3907 Apr 11 2018 /etc/ssh/sshd_config
79 GSSAPIAuthentication no
115 UseDNS no #是否把用户输入ip地址 解析为 对应的域名
[root@oldboyedu-muban ~]# egrep -n '^(GSSAPIA|UseDNS)' /etc/ssh/sshd_config
79:GSSAPIAuthentication no
115:UseDNS no
[root@oldboyedu-muban ~]# systemctl restart sshd
(2)yum源: 修改系统默认的yum源 增加epel源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
(3) 修改yum源+时钟同步
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc
cat >/var/spool/cron/root <<'EOF'
#sync time by lidao at 20190101
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
EOF
(4)文件描述符
ulimit -n65535
echo '* - nofile 65535 ' >>/etc/security/limits.conf
5.系统环境变量配置
export PS1="[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\] \[\e[31;1m\]\w\[\e[0m\]]\\$ "
export TMOUT=300 #timeout linux不进行任何操作 300s之后自动登出
export HISTFILE=1000 #history 命令最多记录几条
export HISTFILESIZE=1000 #history 历史记录的文件里面最多记录几条
export HISTCONTROL=ignorespace #控制history 命令如何记录 历史命令
[故障集合]Linux必备故障及原因50个
https://www.jianshu.com/p/99ec5bb4183f








网友评论