YUM源、磁盘基础知识 CDN概念

第1章 YUM

1.1 什么是yum

Yellowdog Updater, Modified

一个基于RPM包管理的字符前端软件包管理器。能够从指定的服务器自动下载RPM包并且安装,可以处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

简单来说就是软件仓库--yum/仓库,类似于电脑管家之类。

1.2 查看系统中有什么yum

yum repolist 目录可以列出服务器中使用的什么yum源。

[root@znix ~]# yum repolist

Loaded plugins: fastestmirror, security

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

repo id   repo name                                         status

base      CentOS-6 - Base - mirrors.aliyun.com               6,706

epel      Extra Packages for Enterprise Linux 6 - x86_64    12,395

extras    CentOS-6 - Extras - mirrors.aliyun.com                45

updates   CentOS-6 - Updates - mirrors.aliyun.com              611

repolist: 19,757

系统的yum源默认是从世界各地下载软件,优先选择自己离得最近的源下载,不稳定

1.3 指定一个国内的yum源地址 aliyun

修改为阿里云的yum

1.3.1 操作前备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

 

1.3.2 下载新的CentOS-Base.repo /etc/yum.repos.d/

CentOS 5

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

1.3.3 生成本地缓存

缓存无处不在

yum makecache

1.4 增加一个epel

1.4.1 epel源时干什么的

epel---增加和扩展yum仓库

里面包含了许多基本源里没有的软件。

1.4.2 添加上一个aliyunepel

安装自己的系统版本选择epel源。

epel(RHEL 7)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

epel(RHEL 6)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

epel(RHEL 5)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo

1.5 安装htopsl 程序

htop 是一个类似与top的软件,但是更好看

sl  是一个小软件,哈哈。

[root@znix ~]# yum install htop sl -y

1.6 清除yum缓存   

清除本地的yum缓存。

yum clean all

1.7 查看系统yum源信息时可能出现的错误

1.7.1 可能出现的错误

[root@oldboy-40 ~]# yum repolist

Loaded plugins: fastestmirror, security

Loading mirror speeds from cached hostfile

repolist: 0

[root@znix ~]# ls -l /etc/yum.repos.d

total 40

-rw-r--r--  1 root root 2572 Jul  2  2014 CentOS-Base.repo

/etc/yum.repos.d目录下的 .repo文件的内容没有或被删除都可以导致找不到yum源。

会出现以上的错误。

1.7.2 yum 常见错误

[root@znix ~]# yum install tree

Loaded plugins: fastestmirror, security

Existing lock /var/run/yum.pid: another copy is running as pid 5219.

Another app is currently holding the yum lock; waiting for it to exit...

  The other application is: yum

    Memory :  23 M RSS (859 MB VSZ)

    Started: Fri Sep 15 08:46:52 2017 - 00:12 ago

    State  : Sleeping, pid: 5219

    状态   pid 5219

    正在运行的yumpid

1.7.3 解决办法

1)可以等待该yum程序执行完毕,就可以进行安装

2)可以将这个pid进程结束进程,使用kill命令。

    [root@znix ~]# ps -ef |grep 5219

root       5219   5095 44 08:52 pts/1    00:00:21 /usr/bin/python /usr/bin/yum makecache

root       5232   5146  0 08:53 pts/2    00:00:00 grep --color=auto 5219

第2章 磁盘的基础知识

2.1 磁盘知识体系

2.2 如何查询内存的使用情况

free  -h 参数,在旧版本的系统中没有这个参数,可以使用-m,以M为单位显示。

[root@clsn ~]# free -h

             total       used       free     shared    buffers     cached

Mem:          1.8G       887M       974M       228K       221M       302M

-/+ buffers/cache:       363M       1.5G     👈这才是真正剩余的内存

Swap:         767M         0B       767M

free + buffers + cached 才是真正剩余的内存

2.2.1 为什么内存会少

1linux把你使用过的命令、程序、文件、临时存放在系统的缓存区(buffercache的地方)

2)方便下次使用,提高系统的速度。

3)使用其他的命令的时候 这个区域会被清理/覆盖

4)可以从这个网站上了解更多: http://www.linuxatemyram.com/

2.2.2 内存相关的文件

[root@znix ~]# find / -name "*drop_caches*"

/proc/sys/vm/drop_caches

危险的文件

清空这个文件,释放所有内存

2.3 硬盘外部结构

       转速 5400/7200/10000/15000 rpm

       接口 sata  sas  scsi pci-e

       缓存 缓存无处不在

2.4 磁盘的接口类型

SATA          个人数据,存放不重要数据的

SCSI          稳定,接口不一样

SAS           企业默认的接口

PCI-E         价格高

m.2nvme    笔记本使用

2.5 磁盘的选择

1线上(用户正在使用的环境 给用户提供服务)的业务,用SAS磁盘

2线下(自己人用的环境 )的业务,SATA磁盘,磁带库,使用光盘存放数据。

3线上高并发、小容量(很多人都想看的图片)的业务,固态硬盘SSD

4)成本思想:根据数据的访问热度,智能分析分层存储。SATA+SSD

2.5.1 根据数据的访问热度,智能分析分层存储

一台服务器里面分为冷门数据和热门数据:

热门数据:把用户经常使用的图片 存放在ssd里面

冷门数据: 不经常使用的放在 sata 中。

2.6 企业案例】千万不要用SATA磁盘来做在线高并发服务的数据存储或数据库业务,这是有血的教训的。某公司采用SATA做数据库的存储盘,结果导致数据库连续宕机一个月。

解决办法:

重新买5台,把磁盘从SATARAID5)换成SASRAID10)。6个月内没事。

2.7 CDN 内容分发网络

2.7.1 什么是CDN

1.     缓存用户数据

2.     根据用户所在位置,让用户访问最近的位置

3.     提高用户的访问速度

第3章 磁盘的内部结构

3.1 磁盘相关的名词

磁盘--disk

磁头--head   读取与写入数据

磁道--track   相当与一个呼啦圈

                       以磁盘中心(主轴),环形区域

扇区--sector

                        磁盘上面最小的单位

                       一个扇区512字节

柱面--cylinder

磁盘的读写是按照柱面进行

单元块--units

3.2 计算磁盘的容量

3.2.1 计算的公式

磁盘的大小=磁盘中的柱面大小*柱面的数量

一个柱面的大小=一个磁道的大小*磁头数(盘面数)

一个磁道的大小=扇区的数量*扇区的大小

3.2.2 查看磁盘的信息

[root@znix ~]# fdisk -l

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

255 磁头   63 扇区           1305 柱面

Units = cylinders of 16065 * 512 = 8225280 bytes

单元块 一个柱面的大小

Sector size (logical/physical): 512 bytes / 512 bytes

3.2.3 需要什么条件可以算出磁盘大小?

1.每个磁道上面有多少个扇区

2.磁盘有多少个磁头

3.柱面的数量

3.3 linux里面如何计算

3.3.1 bc命令

bc 命令可以进行交互式命令,前面经过管道传输后可以进行非交互计算。

[root@znix ~]# echo 1+2

1+2

[root@znix ~]# echo 1+2|bc

3

bc默认取值整数

3.3.2 awk 'BEGIN{pirnt }' 方法

awk的方法可以显示小数位。

[root@znix ~]# awk 'BEGIN{print 1/3}'

0.333333

3.4 计算机中的单位

1字节为1B

1KB=1024B

1MB=1024KB=1024^2B

1GB=1024MB=1024^3B

1TB=1024GB=1024^4B

3.5 为什么500G的磁盘 实际可用的容量不到500G

硬盘厂商计算按照1000为单位

计算机中是以1024为单位

第4章 回顾

4.1 如何让一个脚本或服务开机自动运行

4.1.1 方法一:/etc/rc.local

修改/etc/rc.local文件,将要执行的内容放到里面即可。

4.1.2 方法二:通过chkconfig管理

能够让chkconfig管理的条件:

              1、脚本放在/etc/init.d

              2、脚本要有执行权限

              3、要有chkconfig要求的格式

[root@znix ~]# head /etc/init.d/iptables

#!/bin/sh

#

# iptables  Start iptables firewall

#

# chkconfig: 2345 08 92

    必须有的格式

使用chkconfig --add 添加上管理脚本即可。

posted @ 2017-10-09 10:05  惨绿少年  阅读(8769)  评论(0编辑  收藏  举报