admin管理员组

文章数量:1630201

stu

linux学习

1:centos7查看版本信息

	登陆root帐户,输入 cat  /etc/redhat-release,即可显示系统版本
	
	输入 uname  -r ,可以查询内核版本
	
	输入 df  -h,可以查看各分区的使用情况。其中,从左到右各列的内容依次是:
       文件系统、总大小、已使用大小、剩余大小、使用率、挂载点。
	   
	输入du  -sh,则可以查看当前文件夹所占空间。它的功能等同于 du . -sh。而输入 du 目录名 -sh,则可以查看指定目录的大小。

2:ntp安装

3:centos7查看已启动的服务列表

4:centos7仓库导入公钥

5:centos系统添加/删除用户和用户组的例子

6:centos7退出登录

7:centos7忘记root密码

方法一

1.重启开机按e

2.编辑修改两处:ro改为rw,必须在LANG=en_US.UFT-8后面添加init=/bin/sh

3.按Ctrl+X重启,并修改密码

4.由于selinux开启着的需要执行以下命令更新系统信息,否则重启之后密码未生效

touch /.autorelabel

5.重启系统

方法二

1.重启开机按e

2.编辑修改LANG=en_US.UFT-8后面添加rd.break

3.按Ctrl+X重启

4.mount -o remount,rw /sysroot

5.chroot  /sysroot

6.修改密码

7.由于selinux开启着的需要执行以下命令更新系统信息,否则重启之后密码未生效

touch /.autorelabel

8.重启系统

8: 中文man

虽然在CentOS操作系统中具有多语言包,但其man手册是英文的,对于新手来说能够使用中文man手册将加快学习速度。

工具/原料

>Linux操作系统:CentOS 6.6

>软件:manpages-zh-1.5.1.tar.gz

>方法/步骤

1:将安装包下载到本地

wget http://pkgs.fedoraproject/repo/pkgs/man-pages-zh-CN/manpages-zh-1.5.1.tar.gz/13275fd039de8788b15151c896150bc4/manpages-zh-1.5.1.tar.gz


2:打开系统终端,输入:tar xf manpages-zh-1.5.1.tar.gz进行解压缩

3: cd manpages-zh-1.5.1             #进入安装目录

4: ./configure --disable-zhtw      #安装配置

5:  make && make install            #安装

6:设置环境变量:vim /etc/profile.d/cman.sh

  输入内容:alias cman='man -M /usr/local/share/man/zh_CN'
  
  保存退出

7:source /etc/profile.d/cman.sh      #重新执行别名文件

CentOS系统安装中文man手册

8:测试,输入命令:cman ls

  #注意事项:
  
  #中文帮助手册的使用命令是cman,目前只翻译部分不是所有的帮助都是中文
  
  #如果想使用英文帮助,可以使用命令man

9:centos7根目录扩容及增加swap

Last login: Fri Aug 18 15:12:01 2017 from 61.155.49.162

[root@localhost ~]# ll

total 4
-rw-------. 1 root root 1248 Jul 11 22:00 anaconda-ks.cfg

[root@localhost ~]# df -lhT

Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       6.2G  1.4G  4.9G  22% /
devtmpfs            devtmpfs  909M     0  909M   0% /dev
tmpfs               tmpfs     920M     0  920M   0% /dev/shm
tmpfs               tmpfs     920M   17M  904M   2% /run
tmpfs               tmpfs     920M     0  920M   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  166M  849M  17% /boot
tmpfs               tmpfs     184M     0  184M   0% /run/user/0
Last login: Fri Aug 18 15:42:03 2017 from 61.155.49.162

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 34.4 GB, 34359738368 bytes, 67108864 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 /dev/sda: 8589 MB, 8589934592 bytes, 16777216 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: 0x000031df

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   8e  Linux LVM

Disk /dev/mapper/cl-root: 6652 MB, 6652166144 bytes, 12992512 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 /dev/mapper/cl-swap: 859 MB, 859832320 bytes, 1679360 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

[root@localhost ~]# parted /dev/sdb

GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel  
align-check  disk_toggle  mklabel      mktable      print        rescue       select       toggle       version      
disk_set     help         mkpart       name         quit         rm           set          unit         
(parted) mklabel  msdos
(parted) mkpart p1
parted: invalid token: p1
Partition type?  primary/extended? p                                      
File system type?  [ext2]?                                                
Start?                                                                    
Start? 0                                                                  
End? 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End     Size    Type     File system  Flags
 1      512B   34.4GB  34.4GB  primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 34.4 GB, 34359738368 bytes, 67108864 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: 0x0006e17c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1    67108863    33554431+  83  Linux

Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 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: 0x000031df

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   8e  Linux LVM

Disk /dev/mapper/cl-root: 6652 MB, 6652166144 bytes, 12992512 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 /dev/mapper/cl-swap: 859 MB, 859832320 bytes, 1679360 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

[root@localhost ~]# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgs
  VG #PV #LV #SN Attr   VSize VFree
  cl   1   2   0 wz--n- 7.00g    0 

[root@localhost ~]# pvs

  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda2  cl lvm2 a--   7.00g     0 
  /dev/sdb1     lvm2 ---  32.00g 32.00g

[root@localhost ~]# vgex

vgexport  vgextend  

[root@localhost ~]# vgextend cl /dev/sdb1

  Volume group "cl" successfully extended
[root@localhost ~]# vgs
  VG #PV #LV #SN Attr   VSize  VFree 
  cl   2   2   0 wz--n- 38.99g 32.00g

[root@localhost ~]# lvextend -L +32GB /dev/cl/root 逻辑卷下/dev/cl/root增加32个G

  Insufficient free space: 8192 extents needed, but only 8191 available

[root@localhost ~]# lvextend -L +31.95GB /dev/cl/root

  Rounding size to boundary between physical extents: 31.95 GiB.
  Size of logical volume cl/root changed from 6.20 GiB (1586 extents) to 38.15 GiB (9766 extents).
  Logical volume cl/root successfully resized.

[root@localhost ~]# df -lhT

Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       6.2G  1.4G  4.9G  22% /
devtmpfs            devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs               tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs               tmpfs     3.9G  8.5M  3.9G   1% /run
tmpfs               tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  183M  832M  19% /boot
tmpfs               tmpfs     783M     0  783M   0% /run/user/0

[root@localhost ~]# xfs_growfs /dev/cl/

root  swap  

[root@localhost ~]# xfs_growfs /dev/cl/root

meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=406016 blks
		 =                       sectsz=512   attr=2, projid32bit=1
		 =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1624064, imaxpct=25
		 =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
		 =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1624064 to 10000384

[root@localhost ~]# lvs

  LV   VG Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root cl -wi-ao----  38.15g                                                    
  swap cl -wi-ao---- 820.00m                                                    

[root@localhost ~]# vgdisplay

  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       9971 / 38.95 GiB
  Free  PE / Size       11 / 44.00 MiB
  VG UUID               Qgvl8Y-8uoN-05rT-D5oj-6jOA-pB0t-xpbPqR

[root@localhost ~]# vgre

vgreduce  vgremove  vgrename  

[root@localhost ~]# lvresize -L -8GB /dev/cl/root

  WARNING: Reducing active and open logical volume to 30.15 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce cl/root? [y/n]: y
  Size of logical volume cl/root changed from 38.15 GiB (9766 extents) to 30.15 GiB (7718 extents).
  Logical volume cl/root successfully resized.

[root@localhost ~]# vgdisplay

  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       7923 / 30.95 GiB
  Free  PE / Size       2059 / 8.04 GiB
  VG UUID               Qgvl8Y-8uoN-05rT-D5oj-6jOA-pB0t-xpbPqR

[root@localhost ~]# vgextend -L +8GB /dev/cl/

root  swap  

[root@localhost ~]# vgextend -L +8GB /dev/cl/swap

vgextend: invalid option -- 'L'
  Error during parsing of command line.

[root@localhost ~]# vgextend -l +8GB /dev/cl/swap

vgextend: invalid option -- 'l'
  Error during parsing of command line.

[root@localhost ~]# lvextend -L +8GB /dev/cl/swap

  Size of logical volume cl/swap changed from 820.00 MiB (205 extents) to 8.80 GiB (2253 extents).
  Logical volume cl/swap successfully resized.

[root@localhost ~]# lvdisplay

  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                C7O7Xc-S60j-OHix-38Ko-BbfD-ZILN-rSMKXr
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-07-11 21:55:40 +0800
  LV Status              available
  # open                 2
  LV Size                8.80 GiB
  Current LE             2253
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                fh27Ps-QqJv-7CEe-Gt4n-aC2E-jP2j-TKlyCx
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-07-11 21:55:40 +0800
  LV Status              available
  # open                 1
  LV Size                30.15 GiB
  Current LE             7718
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@localhost ~]# df -lhT

Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        39G  1.4G   37G   4% /
devtmpfs            devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs               tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs               tmpfs     3.9G  8.5M  3.9G   1% /run
tmpfs               tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  183M  832M  19% /boot
tmpfs               tmpfs     783M     0  783M   0% /run/user/0

[root@localhost ~]# free -m

			  total        used        free      shared  buff/cache   available
Mem:           7822         167        7380           8         275        7381
Swap:           819           0         819

[root@localhost ~]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 11 21:55:42 2017
#
# 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/cl-root     /                       xfs     defaults        0 0
UUID=4475fa42-8f2f-4371-ada0-95d370318466 /boot                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
                                                                                                            
~                                                                                                                                            
                                                                                                       
~                                                                                                                                            
"/etc/fstab" 11L, 465C

[1]+  Stopped                 vi /etc/fstab

[root@localhost ~]# free –h

			  total        used        free      shared  buff/cache   available
Mem:        8010268      171068     7557208        8680      281992     7558364
Swap:        839676           0      839676

[root@localhost ~]# xfs_growfs /dev/cl/swap

xfs_growfs: /dev/cl/swap is not a mounted XFS filesystem

[root@localhost ~]# df -lhT

Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        39G  1.4G   37G   4% /
devtmpfs            devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs               tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs               tmpfs     3.9G  8.5M  3.9G   1% /run
tmpfs               tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  183M  832M  19% /boot
tmpfs               tmpfs     783M     0  783M   0% /run/user/0

[root@localhost ~]# lvdisplay

  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                C7O7Xc-S60j-OHix-38Ko-BbfD-ZILN-rSMKXr
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-07-11 21:55:40 +0800
  LV Status              available
  # open                 2
  LV Size                8.80 GiB
  Current LE             2253
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                fh27Ps-QqJv-7CEe-Gt4n-aC2E-jP2j-TKlyCx
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-07-11 21:55:40 +0800
  LV Status              available
  # open                 1
  LV Size                30.15 GiB
  Current LE             7718
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@localhost ~]# swapoff -v /dev/cl/swap

swapoff /dev/cl/swap

[root@localhost ~]# mkswap /dev/cl/swap

mkswap: /dev/cl/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 9228284 KiB
no label, UUID=a6ae2aa2-cf8e-4f33-8c74-943ae38846e9
[root@localhost ~]# swapon -va 
swapon /dev/mapper/cl-swap
swapon: /dev/mapper/cl-swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/cl-swap: pagesize=4096, swapsize=9449766912, devsize=9449766912

[root@localhost ~]# free

			  total        used        free      shared  buff/cache   available
Mem:        8010268      179852     7534032        8680      296384     7546784
Swap:       9228284           0     9228284

[root@localhost ~]# free -m

			  total        used        free      shared  buff/cache   available
Mem:           7822         175        7357           8         289        7370
Swap:          9011           0        9011

[root@localhost ~]# free -g

			  total        used        free      shared  buff/cache   available
Mem:              7           0           7           0           0           7
Swap:             8           0           8

[root@localhost ~]# free -G

free: invalid option -- 'G'

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega          show output in megabytes
 -g, --giga          show output in gigabytes
	 --tera          show output in terabytes
 -h, --human         show human-readable output
	 --si            use powers of 1000 not 1024
 -l, --lohi          show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds
 -c N, --count N     repeat printing N times, then exit
 -w, --wide          wide output

	 --help     display this help and exit
 -V, --version  output version information and exit

For more details see free(1).

[root@localhost ~]# free -g

			  total        used        free      shared  buff/cache   available
Mem:              7           0           7           0           0           7
Swap:             8           0           8
[root@localhost ~]# 

10.CentOS下测试硬盘坏道

硬盘状态测试工具:smartctl、Badblocks、hdparm 
感觉用smartctl挺快的,也能快速看到硬盘是否健康,命令如下:
[root@qy ~]#yum install smartmontools -y
启动SMART
# smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda
[root@qy ~]# smartctl -a /dev/sda
smartctl 5.42 2011-10-20 r3458[i686-linux-2.6.18-194.el5PAE] (local build)
Copyright (C) 2002-11 by Bruce Allen,http://smartmontools.sourceforge
 
Vendor:               SEAGATE
Product:              ST3146356SS    
Revision:             HS09
User Capacity:        146,815,733,760 bytes [146 GB]
Logical block size:   512 bytes
Logical Unit id:      0x5000c50004fa837f
Serial number:        3QN0EL91
Device type:          disk
Transport protocol:   SAS
Local Time is:        Fri Oct 31 10:45:58 2014 CST
Device supports SMART and is Enabled
Temperature Warning Disabled or NotSupported
SMART Health Status: OK   #版本的不通这里显示的也不一样。
 
Current Drive Temperature:     30 C
Drive Trip Temperature:        68 C
Elements in grown defect list: 0  #才是出坏道,俗称成长坏道。
Vendor (Seagate) cache information
 Blocks sent to initiator = 3752023409
 Blocks received from initiator = 3916316860
 Blocks read from cache and sent to initiator = 4025399956
 Number of read and write commands whose size <= segment size =3339079605
 Number of read and write commands whose size > segment size = 2746
Vendor (Seagate/Hitachi) factoryinformation
 number of hours powered up = 34120.02
 number of minutes until next internal SMART test = 1
 
Error counter log:
		  Errors Corrected by          Total   Correction     Gigabytes    Total
			   ECC          rereads/    errors  algorithm      processed    uncorrected
		  fast | delayed   rewrites  corrected invocations   [10^9 bytes]  errors
read:  248894024        0         0 248894024   248894024      85241.186           0
write:         0        0         0         0          0     30998.996           0
verify:  340001        0        0    340001     340001        141.757           0
 
Non-medium errorcount:       51  #非介质错误。意思是说不是盘的问题,一般是电缆、传输、校验问题,可以忽略的。
No self-tests have been logged
Long (extended) Self Test duration: 1740seconds [29.0 minutes]
 
可以用命令直接查看硬盘的好坏:
[root@qy ~]# smartctl -H /dev/sda
smartctl 5.42 2011-10-20 r3458[i686-linux-2.6.18-194.el5PAE] (local build)
Copyright (C) 2002-11 by Bruce Allen,http://smartmontools.sourceforge
 
SMART Health Status: OK
 
[root@localhost ~]# smartctl -H /dev/sda
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-358.el6.x86_64] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge
 
=== START OF READ SMART DATA SECTION ===
SMART STATUS RETURN: incomplete response, ATA output registers missing
SMART overall-health self-assessment test result: PASSED
Warning: This result is based on an Attribute check.
 
OK和PASSED都属于磁盘是正常的。
 
Badblocks工具测试正常,无坏道信息:
 
badblocks命令可以检查磁盘装置中损坏的区块。执行该指令时须指定所要检查的磁盘装置,及此装置的磁盘区块数。
 
badblocks -s//显示进度  -v//显示执行详细情况   /dev/sda1
badblocks -s//显示进度 -w//以写去检测 -v//显示执行详细情况 /dev/sda2
注意,不能以写的方式检测已经挂载的硬盘
 
[root@qy ~]# badblocks -s -v /dev/sda
Checking blocks 0 to 143374740
Checking for bad blocks (read-only test):done                               
Passcompleted, 0 bad blocks found.
此磁盘通过测试,没有坏道(坏块)。您可以放心使用。
磁盘有坏道了……
但是,如果您检测过程中再某一个区块停滞不前,而后报告中提示有坏块,那么杯具了……您的磁盘有坏道了。
不论是什么类型的坏道,均建议您首先进行数据备份!把重要数据进行备份然后再尝试修复。如果您有重要数据却无法读取(磁盘出现异常),那么请立即停止使用此磁盘并找专业人员进行修复。
 
使用hdparm测试   
测试硬盘读写速度
# hdparm -Tt /dev/sda
/dev/sda:
Timing cached reads:   
1918 MB in  2.00 seconds = 959.62 MB/sec
Timing buffered disk reads:  184 MB in  3.00 seconds =  61.26 MB/sec
hdparm可检测,显示与设定IDE或SCSI硬盘的参数。
语法:
hdparm [-CfghiIqtTvyYZ][-a <快取分区>][-A <0或1>][-c <I/O模式>][-d <0或1>][-k <0或1>][-K <0或1>][-m <分区数>][-n <0或1>][-p <PIO模式>][-P <分区数>][-r <0或1>][-S <时间>][-u <0或1>][-W <0或1>][-X <传输模式>] [设备]
-a<快取分区> 设定读取文件时,预先存入块区的分区数,若不加上<快取分区>选项,则显示目前的设定。 -A<0或1> 启动或关闭读取文件时的快取功能。-c<I/O模式> 设定IDE32位I/O模式。 -C 检测IDE硬盘的电源管理模式。-d<0或1> 设定磁盘的DMA模式。-f 将内存缓冲区的数据写入硬盘,并清楚缓冲区。 -g 显示硬盘的磁轨,磁头,磁区等参数。-h 显示帮助。-i 显示硬盘的硬件规格信息,这些信息是在开机时由硬盘本身所提供。 -I 直接读取硬盘所提供的硬件规格信息。-k<0或1> 重设硬盘时,保留-dmu参数的设定。 -K<0或1> 重设硬盘时,保留-APSWXZ参数的设定。-m<磁区数> 设定硬盘多重分区存取的分区数。 -n<0或1> 忽略硬盘写入时所发生的错误。-p<PIO模式> 设定硬盘的PIO模式。 -P<磁区数> 设定硬盘内部快取的分区数。-q 在执行后续的参数时,不在屏幕上显示任何信息。 -r<0或1> 设定硬盘的读写模式。-S<时间> 设定硬盘进入省电模式前的等待时间。-t 评估硬盘的读取效率。 -T 平谷硬盘快取的读取效率。-u<0或1> 在硬盘存取时,允许其他中断要求同时执行。-v 显示硬盘的相关设定。 -W<0或1> 设定硬盘的写入快取。-X<传输模式>  设定硬盘的传输模式。-y 使IDE硬盘进入省电模式。 -Y 使IDE硬盘进入睡眠模式。-Z 关闭某些Seagate硬盘的自动省电功能。
 
 
可以使用sg_vpd命令查看硬盘转速,sg_vpd命令是sg3_utils其中一个工具.

下载地址:http://sg.danny.cz/sg/sg3_utils.html

VPD:Vital Product Data

[root@qy sg3_utils-1.39]# sg_vpd /dev/sda

 

关于smart检测硬盘命令补充:
smartctl -a <device> 检查该设备是否已经打开SMART技术。 smartctl -s on <device> 如果没有打开SMART技术,使用该命令打开SMART技术。 smartctl -t short <device> 后台检测硬盘,消耗时间短; smartctl -t long <device> 后台检测硬盘,消耗时间长; smartctl -C -t short <device> 前台检测硬盘,消耗时间短; smartctl -C -t long <device> 前台检测硬盘,消耗时间长。其实就是利用硬盘SMART的自检程序。 smartctl -X <device> 中断后台检测硬盘。 smartctl -l selftest <device> 显示硬盘检测日志。 smartctl -l error <device> 显示硬盘错误汇总。
 
首先通过dmesg工具,确认一下硬盘的设备符号。例如一个IDE硬盘连接到Primary IDE 总线上的Slave位置,硬盘设备符号是/dev/hdb,hdb中的h代表IDE,如果显示为sdb,则代表SATA和SCSI,最后一个字幕b代表Primary总线,第二块硬盘即Slave位置,确认硬盘是否打开了SMART支持:
# smartctl -i /dev/sda
smartctl 5.40 2010-10-16 r3189 [i386-redhat-linux-gnu] (local build)
Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge
=== START OF INFORMATION SECTION ===
Device Model:     HITACHI HTS543225L9SA00
Serial Number:    090131FB2F32YLG28JEA
Firmware Version: FBEZC48C
User Capacity:    250,059,350,016 bytes
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   8
ATA Standard is:  ATA-8-ACS revision 3f
Local Time is:    Wed May 25 10:10:39 2011 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled                          //表示启用了smart支持
如果看到SMART support is: Disabled表示SMART未启用,执行如下命令,启动SMART
# smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda
smartctl 5.40 2010-10-16 r3189 [i386-redhat-linux-gnu] (local build)
Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge
=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.
SMART Attribute Autosave Enabled.
SMART Automatic Offline Testing Enabled every four hours.
现在硬盘的SMART功能已经被打开,执行如下命令查看硬盘的健康状况
# smartctl -H /dev/sda
smartctl 5.40 2010-10-16 r3189 [i386-redhat-linux-gnu] (local build)
Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
请注意result后边的结果:PASSED,这表示硬盘健康状态良好;如果这里显示Failure,那么最好立刻给服务器更换硬盘。SMART只能报告磁盘已经不再健康,但是报警后还能继续运行多久是不确定的。通常,SMART报警参数是有预留的,磁盘报警后,不会当场坏掉,一般能坚持一段时间,有的硬盘SMART报警后还继续跑了好几年,有的硬盘SMART报错后几天就坏了。但是一旦出现报警,侥幸心里是万万不能的……
#smartctl -A   /dev/sda  查看硬盘的详细信息
#smartctl -s on  /dev/sda  如果没有打开SMART技术,使用该命令打开SMART技术。
#smartctl -t short  /dev/sda  后台检测硬盘,消耗时间短;
#smartctl -t long  /dev/sda   后台检测硬盘,消耗时间长;
#smartctl -C -t  /dev/sda   short前台检测硬盘,消耗时间短;
#smartctl -C -t  /dev/sda   long前台检测硬盘,消耗时间长。其实就是利用硬盘SMART的自检程序。
#smartctl -X   /dev/sda      中断后台检测硬盘。
#smartctl -l selftest  /dev/sda  显示硬盘检测日志。
#smartctl -l error   /dev/sda    显示硬盘错误汇总。
如果需要定期登录到服务器上运行smartctl比较麻烦时,linux还提供了系统进程smartd,编辑配置文件:1    vi  /etc/smartd.conf
这个配置文件中大部分可能是注释掉的说明,只需要写入和当前硬盘相关的配置即可:
/dev/sda -H  -m  test@test123123  //监控磁盘的健康状态,当SMART中报告PASSED的时候不理睬。一旦出现Failure,立刻用邮件通知用户指定的邮箱
 /dev/sda -a -m  admin@example,root@localhost  //监控磁盘的所有属性,当SMART中报告PASSED的时候不理睬。一旦出现Failure,立刻用邮件通知用户指定的邮箱 
 /dev/twa0 -d 3ware,0 -a -s L/../../7/00 //监控3ware 9000控制器上的第一个ATA磁盘的所有属性,在每个礼拜天的00:00--01:00进行长格式的自我检测
 /dev/sg2 -d areca,1 -a  -s L/../(01|15)/./22 //监控Areca Raid控制器上的第一个SATA磁盘的所有属性,在每个礼拜月的第1天和第15天的22:00--23:00进行长格式的自我检测
 -s (O/../.././(00|06|12|18)|S/../.././01|L/../../6/03) //在每天的00:00,06:00,12:00,18:00进行离线的自检,并在每天的01:00-02:00进行短格式的自检,并在每个礼拜6的03:00-04:00进行长格式的自检 
配置好smartd.conf后需执行
/etc/init.d/smartd restart 即可生效
其他和smartd.conf相关的配置可参见:
http://smartmontools.sourceforge/man/smartd.conf.5.html

11.Linux source命令

Linux source命令:

通常用法:source filepath 或 . filepath

功能:使当前shell读入路径为filepath的shell文件并依次执行文件中的所有语句,通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。例如,当我们修改了/etc/profile文件,并想让它立刻生效,而不用重新登录,就可以使用source命令,如source /etc/profile。

source命令(从 C Shell 而来)是bash shell的内置命令;点命令(.),就是个点符号(从Bourne Shell而来)是source的另一名称。这从用法中也能看出来。

 

source filepath 与 sh filepath 、./filepath的区别:

当shell脚本具有可执行权限时,用sh filepath与./filepath是没有区别的。./filepath是因为当前目录没有在PATH中,所有"."是用来表示当前目录的。

sh filepath 会重新建立一个子shell,在子shell中执行脚本里面的语句,该子shell继承父shell的环境变量,但子shell是新建的,其改变的变量不会被带回父shell,除非使用export。

source filename其实只是简单地读取脚本里面的语句依次在当前shell里面执行,没有建立新的子shell。那么脚本里面所有新建、改变变量的语句都会保存在当前shell里面。

 

举例说明:

新建一个test.sh脚本,内容为:A=1;

修改其可执行权限:chmod +x test.sh;

运行sh test.sh后,echo $A,显示为空,因为A=1并未传回给当前shell;

运行./test.sh后,也是一样的效果;

运行source test.sh 或者 . test.sh,然后echo $A,则会显示1,说明A=1的变量在当前shell中;

12.windows server 2008解决无法PING通问题

windows server 2008解决无法PING通问题

今天安装服务器(server 2008),配置完IP地址后,发现局域网其它电脑无法PING通服务器,测线仪测试链路都正常,网线接别的电脑也正常,以为是网卡问题,于是ping了自己的IP,发现能PING通,怀疑应该是2008策略问题,果然找到解决方法。

方法/步骤

右键电脑,找到【管理】

在服务器管理里找到【配置】项

在高级安全windows防火墙里,找到【入站规则】,找到【文件和打印机共享(回显请求-ICMPv4-in)】双击。此时图片状态默认是没选中的


找到【文件和打印机共享(回显请求-ICMPv4-in)】右击……选择【启用规则】就OK了!为避免以后不方便查找网络问题,此项尽量开启比较好。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jA3RkULs-1571969576958)(https://github/vekrio/stu/blob/master/20170718/photo/1b4c510fd9f9d72a52d03f23d72a2834349bbb53.jpg?raw=true)]

13.虚拟机centos7安装 mariadb并修改默认密码设置远程访问

centos7默认MySQL是maridb

注意:mariadb与mysql root权限不同




本机连接虚拟机mariadb(本机连接虚拟机mysql,远程连接设置)
centos查看ip


这里为了防止失败,我首先检查mysql和mariadb没有安装

 

[root@localhost usr]# ps aux|grep mysql     #检测mysql服务
root       2180  0.0  0.0 112664   972 pts/0    S+   17:46   0:00 grep --color=auto mysql
[root@localhost usr]# whereis mysql     #是否有mysql残留文件
[root@localhost usr]#
mysql:[root@localhost usr]# whereis mariadb             #查找是否有mariadb如果有就会显示文件夹先卸掉
mysql:[root@localhost usr]#
[root@localhost usr]# ps aux|grep mariadb               #是否有安装mariadb服务出现下面一行就是没有安装
root       2201  0.0  0.0 112664   980 pts/0    S+   17:48   0:00 grep --color=auto mariadb
[root@localhost usr]# yum install mariadb mariadb-server         #这是安装mariadb和mariadb服务
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu
 * extras: mirrors.yun-idc
 * updates: mirrors.sina
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.47-1.el7_2 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.47-1.el7_2,它被软件包 1:mariadb-5.5.47-1.el7_2.x86_64 需要
---> 软件包 mariadb-server.x86_64.1.5.5.47-1.el7_2 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.47-1.el7_2 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================
 Package                            架构                       版本                                  源                           大小
=======================================================================================================================================
正在安装:
 mariadb                            x86_64                     1:5.5.47-1.el7_2                      updates                     8.9 M
 mariadb-server                     x86_64                     1:5.5.47-1.el7_2                      updates                      11 M
为依赖而安装:
 mariadb-libs                       x86_64                     1:5.5.47-1.el7_2                      updates                     755 k

事务概要
====================&

本文标签: README