Linux基础命令(四)

 

作业一:
1) 开启Linux系统前添加一块大小为15G的SCSI硬盘

[root@bogon ~]# fdisk -l

Disk /dev/sda: 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: 0x0002d1bd

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

Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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-root: 18.2 GB, 18249416704 bytes, 35643392 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: 2147 MB, 2147483648 bytes, 4194304 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

2) 开启系统,右击桌面,打开终端

没图形。

3) 为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划分1个逻辑分区,大小为5G

Command (m for help): p

Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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: 0x0cddc761

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    31457279    10484736    5  Extended
/dev/sdb5        10489856    20975615     5242880   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

  

4) 格式化主分区为ext3系统

[root@bogon ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

5) 将逻辑分区设置为交换分区

[root@bogon ~]# mkswap /dev/sdb5
Setting up swapspace version 1, size = 5242876 KiB
no label, UUID=3d0072cf-8902-44c3-b13b-6c4373a130a5

6) 启用上一步的交换分区

[root@bogon ~]# swapon -a /dev/sdb5

7) 查看交换分区的状态

[root@bogon ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       2097148 0       -1
/dev/sdb5                               partition       5242876 0       -2

作业二:free命令查看内存

[root@bogon ~]# free
              total        used        free      shared  buff/cache   available
Mem:         999936      147480      675052        7064      177404      680612
Swap:       7340024           0     7340024

整理buffer与cache的作用

Cache:缓存区,是高速缓存,是位于CPU和主内存之间的容量较小但速度很快的存储器,因为CPU的速度远远高于主内存的速度,CPU从内存中读取数据需等待很长的时间,而  Cache保存着CPU刚用过的数据或循环使用的部分数据,这时从Cache中读取数据会更快,减少了CPU等待的时间,提高了系统的性能。

Cache并不是缓存文件的,而是缓存块的(块是I/O读写最小的单元);Cache一般会用在I/O请求上,如果多个进程要访问某个文件,可以把此文件读入Cache中,这样下一个进程获取CPU控制权并访问此文件直接从Cache读取,提高系统性能。

Buffer:缓冲区,用于存储速度不同步的设备或优先级不同的设备之间传输数据;通过buffer可以减少进程间通信需要等待的时间,当存储速度快的设备与存储速度慢的设备进行通信时,存储慢的数据先把数据存放到buffer,达到一定程度存储快的设备再读取buffer的数据,在此期间存储快的设备CPU可以干其他的事情。

Buffer:一般是用在写入磁盘的,例如:某个进程要求多个字段被读入,当所有要求的字段被读入之前已经读入的字段会先放到buffer中。

计算真实的内存使用率

used/total=内存使用率
147480/9999936=0.1474894393241167

作业三:dd命令测试硬盘速度

[root@bogon ~]# dd if=/dev/zero of=/luchuangao.txt bs=2M count=2
2+0 records in
2+0 records out
4194304 bytes (4.2 MB) copied, 0.015345 s, 273 MB/s

作业四:查找一个名为firewall的进程,并且将其强制杀死

[root@bogon ~]# ps aux | grep firewall
root        626  0.0  2.6 327200 26332 ?        Ssl  15:27   0:01 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
root       2376  0.0  0.0 112648   960 pts/0    R+   16:01   0:00 grep --color=auto firewall
[root@bogon ~]# pkill -9 firewall

作业五:rpm命令

1) 挂载光盘文件到/media目录

[root@bogon ~]# mount /dev/cdrom /media/
mount: /dev/sr0 is write-protected, mounting read-only

2) 进去/media目录下的Packages目录

[root@bogon ~]# cd /media/Packages/

3) 查看系统已安装的所有rpm包

[root@bogon Packages]# rpm -qa 

4) 查看系统是否安装dhcp软件包

[root@bogon ~]# rpm -qa | grep dhcp
dhcp-libs-4.2.5-47.el7.centos.x86_64
dhcp-common-4.2.5-47.el7.centos.x86_64

5) 安装dhcp软件包

[root@bogon ~]# yum install dhcp -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-47.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                            Arch                                 Version                                              Repository                          Size
=======================================================================================================================================================================
Installing:
 dhcp                               x86_64                               12:4.2.5-47.el7.centos                               base                               511 k

Transaction Summary
=======================================================================================================================================================================
Install  1 Package

Total download size: 511 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-47.el7.centos.x86_64.rpm                                                                                                             | 511 kB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-47.el7.centos.x86_64                                                                                                                  1/1 
  Verifying  : 12:dhcp-4.2.5-47.el7.centos.x86_64                                                                                                                  1/1 

Installed:
  dhcp.x86_64 12:4.2.5-47.el7.centos                                                                                                                                   

Complete!

6) 查看dhcp软件包的信息

[root@bogon ~]# rpm -qi dhcp
Name        : dhcp
Epoch       : 12
Version     : 4.2.5
Release     : 47.el7.centos
Architecture: x86_64
Install Date: Fri 17 Mar 2017 03:58:04 PM CST
Group       : System Environment/Daemons
Size        : 1452668
License     : ISC
Signature   : RSA/SHA256, Mon 21 Nov 2016 01:32:14 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : dhcp-4.2.5-47.el7.centos.src.rpm
Build Date  : Tue 15 Nov 2016 01:54:04 AM CST
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://isc.org/products/DHCP/
Summary     : Dynamic host configuration protocol software
Description :
DHCP (Dynamic Host Configuration Protocol) is a protocol which allows
individual devices on an IP network to get their own network
configuration information (IP address, subnetmask, broadcast address,
etc.) from a DHCP server. The overall purpose of DHCP is to make it
easier to administer a large network.

To use DHCP on your network, install a DHCP service (or relay agent),
and on clients run a DHCP client daemon.  The dhcp package provides
the ISC DHCP service and relay agent.

7) 查看dhcp软件包中所包含的所有文件

[root@bogon ~]# rpm -ql dhcp
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/lib/systemd/system/dhcrelay.service
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.2.5
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
/usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example
/usr/share/doc/dhcp-4.2.5/ldap
/usr/share/doc/dhcp-4.2.5/ldap/README.ldap
/usr/share/doc/dhcp-4.2.5/ldap/dhcp.schema
/usr/share/doc/dhcp-4.2.5/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/usr/share/systemtap/tapset/dhcpd.stp
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

8) 查看/bin/ls文件是由哪个软件包产生

[root@bogon ~]# rpm -qf /bin/ls
coreutils-8.22-18.el7.x86_64

9) 卸载dhcp软件包

[root@bogon ~]# yum erase dhcp -y
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-47.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                           Arch                                Version                                                Repository                          Size
=======================================================================================================================================================================
Removing:
 dhcp                              x86_64                              12:4.2.5-47.el7.centos                                 @base                              1.4 M

Transaction Summary
=======================================================================================================================================================================
Remove  1 Package

Installed size: 1.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 12:dhcp-4.2.5-47.el7.centos.x86_64                                                                                                                  1/1 
  Verifying  : 12:dhcp-4.2.5-47.el7.centos.x86_64                                                                                                                  1/1 

Removed:
  dhcp.x86_64 12:4.2.5-47.el7.centos                                                                                                                                   

Complete!

作业六:yum命令

 1) 自定义yum仓库:createrepo

[root@bogon ~]# yum install createrepo -y
[root@bogon ~]# mkdir /luchuangao
[root@bogon ~]# cp /rpm_bak/base/packages/httpd-2.4.6-45.el7.centos.x86_64.rpm /luchuangao/
[root@bogon ~]# createrepo /luchuangao/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

2) 自定义repo文件

[root@bogon yum.repos.d]# cat httpd.repo 
[local]
name=local repo
baseurl=file:///luchuangao
enabled=1
gpgcheck=0
[root@bogon yum.repos.d]# 

3) 使用yum命令安装httpd软件包

[root@bogon ~]# yum install httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
 Package           Arch               Version                           Repository         Size
================================================================================================
Installing:
 httpd             x86_64             2.4.6-45.el7.centos               local             2.7 M

Transaction Summary
================================================================================================
Install  1 Package

Total download size: 2.7 M
Installed size: 9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-2.4.6-45.el7.centos.x86_64                                             1/1 
  Verifying  : httpd-2.4.6-45.el7.centos.x86_64                                             1/1 

Installed:
  httpd.x86_64 0:2.4.6-45.el7.centos                                                            

Complete!
[root@bogon ~]# 

4) 卸载httpd软件包:yum –y remove 软件名

[root@bogon ~]# yum remove httpd -y
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
 Package           Arch               Version                          Repository          Size
================================================================================================
Removing:
 httpd             x86_64             2.4.6-45.el7.centos              @local             9.4 M

Transaction Summary
================================================================================================
Remove  1 Package

Installed size: 9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : httpd-2.4.6-45.el7.centos.x86_64                                             1/1 
  Verifying  : httpd-2.4.6-45.el7.centos.x86_64                                             1/1 

Removed:
  httpd.x86_64 0:2.4.6-45.el7.centos                                                            

Complete!
[root@bogon ~]# 

5) 使用yum安装组件'KDE 桌面':yum –y groupinstall 组件名

[root@bogon ~]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Installed Groups:
   Development Tools
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[root@bogon ~]# 

 

[root@bogon ~]# yum groupinstall "KDE Plasma Workspaces" -y

6) 掌握使用yum删除组件‘KDE 桌面’:yum –y groupremove 组件名

[root@bogon ~]# yum groupremove "KDE Plasma Workspaces" -y 

7) 掌握清除yum缓存:yum clean all

[root@bogon ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: httpd local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@bogon ~]# 

8) 使用yum查找软件包:yum search 软件包名

[root@bogon ~]# yum search vsftpd
Loaded plugins: fastestmirror, langpacks
httpd                                                                    | 2.9 kB  00:00:00     
local                                                                    | 3.6 kB  00:00:00     
(1/3): httpd/primary_db                                                  | 3.3 kB  00:00:00     
(2/3): local/group_gz                                                    | 155 kB  00:00:00     
(3/3): local/primary_db                                                  | 3.0 MB  00:00:00     
Determining fastest mirrors
===================================== N/S matched: vsftpd ======================================
vsftpd.x86_64 : Very Secure Ftp Daemon

  Name and summary matches only, use "search all" for everything.

 作业六:源码安装python

[root@bogon ~]# yum install zlib-devel -y
[root@bogon ~]# tar -xf Python-3.6.0
[root@bogon ~]# cd Python-3.6.0
[root@bogon Python-3.6.0]# ./configure --prefix=/usr/local/python3.6
[root@bogon Python-3.6.0]# make && make install
[root@bogon ~]# echo 'PATH=/usr/local/python3.6/bin:$PATH' >>/etc/profile
[root@bogon ~]# tail -1 /etc/profile
PATH=/usr/local/python3.6/bin:$PATH
[root@bogon ~]# source /etc/profile

 

[root@bogon ~]# python3.6
Python 3.6.0 (default, Mar 17 2017, 16:47:55) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[root@bogon ~]# 

 

参考链接:http://www.cnblogs.com/linhaifeng/articles/6045600.html#_label16

补充:

ls命令执行过程

ls--------->shell---------->PATH---------->/usr/bin/ls--------->alias

 杀死后台进程

[root@bogon shell]# jobs
[1]+  Running                 ./test.sh &
[root@bogon shell]# kill -9 %1
[root@bogon shell]# 
[1]+  Killed                  ./test.sh

 

posted @ 2017-03-17 16:04  luchuangao  阅读(337)  评论(0编辑  收藏  举报