linux培训笔记2

linux的编辑器:
1、gedit & (必须在图形界面打开) 1.file 1.file~
2、emcas
3、vi、vim

vim编辑器的安装。默认已经安装了vi
# rpm -qa |grep vim
vim-common-7.2.411-1.8.el6.x86_64
vim-minimal-7.2.411-1.8.el6.x86_64 (vi软件包)
vim-enhanced-7.2.411-1.8.el6.x86_64 (vim软件包)
#

vim的配置文件。
/etc/vimrc (rc结尾的,都是初始化文件) vim的参数添加到此文件中。
~/.viminfo (vim历史记录等信息)


vim的工作模式:
命令模式(默认模式):处理文档
编辑模式:录入文档
末行模式:处理文档,与命令模式的功能相似,但会强大一些。


各模式之间的切换:
命令--编辑(i/I o/O a/A)
命令--末行(: / ?)
末行|编辑---命令(esc健)


vim的功能命令:
新建文件:
# vim 1.txt

打开文件:
# vim /etc/hosts

# vim
:e /etc/hosts

读文件:
# vim 1.txt
:r /etc/hosts 将/etc/hosts文件读到1.txt文件中
:2r !ls -l /root 将ls -l /root命令的结果,读到1.txt文件中的第2行。

保存文件:(另存为)
:w /root/1.txt
:w /root/2.txt
:1,10w /root/3.txt
:10w /root/4.txt

保存退出:
:wq
:wq!
ZZ
:x
:x!

不保存退出
:q
:q!


复制:
yy 复制光标所在行
nyy 复制光标及以下的连续n-1行
y$ 复制光标到行尾的内容
y0 复制光标到行首的内容
:1,10 co $
:1 co 10

总结:vim末行模式命令的语法。
:[addr1],[addr2] <command> [addr3]|[options]
e edit
r read
w write
co copy
mo move
d delete

粘贴
p 粘贴到光标所在行的下一行。(vim的特点,小写对下一行操作)
P(大) 粘贴中 上

剪切,移动
:1,10 mo $ 将第1~10行的内容,剪切到第最后一行。

删除
:1d
:1,10 d
:/abc/d 删除包含有abc字符的行。

dd
ndd
d0 删除光标到行首
d$ 删除光标到行尾
dG 删除光标到文件末行的内容。
d1G 删除光标到第一行的内容。


替换 s :1,$ == :% 分隔符(/ # ,)
:1,$s /old/new/g 将全文的old字符替换成new字符。
:1,$s /old/new/ 将全文中每一行中的第一个old字符替换成new

:%s /^# //g 将全文中的#空格开头的删除。
:%s /\.$//g 删除点结尾的内容。

将/var/www/html替换成/srv/www/htdocs/
:%s #/var/www/html#/srv/www/htdocs#g

查找:
/char 查找char字符
?aa 查找aa字符
n或N 继续查找。

光标定位:
宏观:
H M L 定位到屏幕的上 中 下。
pgup(ctrl+b) pgdw(ctrl+f) 上下翻页
:100 定位到第100行
:$ 定位到最后一行
:1 定位到第一行。

微观:
上 下 左 右
k j h l
0 定位到行首
$ 定位到行尾

vim的选项
:set nu 显示行号
:set nonu 去除行号
:set hlsearch 显示查找的高亮度
:noh 去除高亮度
:set <tab> 查看vim支持选项
:set <回车> 查看已设置的vim选项。


实验:
编辑/root/install.log文件。

# cp install.log install.sh
# head install.sh
#!/bin/bash
mount /dev/cdrom /media/
rpm -ivh /media/Package/libgcc-4.4.6-4.el6.x86_64.rpm --force --nodeps
rpm -ivh /media/Packages/setup-2.8.14-16.el6.noarch.rpm --force --nodeps
rpm -ivh /media/Packages/ca-certificates-2010.63-3.el6_1.5.noarch.rpm --force --nodeps
rpm -ivh /media/Packages/tzdata-2012c-1.el6.noarch.rpm --force --nodeps
rpm -ivh /media/Packages/filesystem-2.4.30-3.el6.x86_64.rpm --force --nodeps
rpm -ivh /media/Packages/foomatic-db-filesystem-4.0-7.20091126.el6.noarch.rpm --force --nodeps
rpm -ivh /media/Packages/xml-common-0.6.3-32.el6.noarch.rpm --force --nodeps


文件系统:
ext2,ext3,ext4 linux的文件系统。
vfat,ntfs-3g
nfs,cifs
iso9660,udf

/bin /usr/bin /usr/local/bin /xxx/bin 普通用户可执行的文件。
/sbin /usr/sbin /usr/local/sbin /xxx/sbin 超级管理员可执行文件。
/etc /usr/etc /usr/local/etc /xxx/etc 配置文件
/lib /usr/lib /usr/local/lib 动态链接库文件
/lib64 /usr/lib64 /usr/local/lib64 64位的动态链接库文件
/boot 系统引导目录
/home 普通用户的自家目录
/root 超级管理员的自家目录
/tmp /usr/tmp 临时文件目录
/proc 当前系统运行的进程状态,硬件的配置,内核的参数。
/dev 设备文件目录
/lost+found 执行fsck命令找到的文件。
/media /mnt/ /misc /net 设备的挂载点。这是一个约定。
/opt 第三方软件下载或安装的目录。
/usr 系统最大目录,包命令,配置文件,动态链接库,程序,帮助。。。
/var 日志,用户的邮箱,ftp,www服务器的数据。
/selinux selinux的配置和状态。
/sys 系统硬件的固体的信息。

硬盘:
主分区:所有硬盘都只有最多4个主分区,(扩展分区属有于主分区中的一种)
逻辑分区:逻辑分区必须创建在扩展分区之上。在linux中最多11个逻辑分区。

磁盘分区的步骤:
1、在vmware中,添加新的硬盘,容量为1G,共添加到4块。
2、对/dev/sdb硬盘分区。fdisk /dev/sdb
3、将分区信息,写入到内核表 partprobe
4、创建文件系统。 mkfs.ext4 /dev/sdb1
5、挂载使用。 mkdir /media/sdb1; mount /dev/sdb1 /media/sdb1
6、设置开机自动运行。 vim /etc/fstab

m print this menu 显示帮助菜单
n add a new partition 创建分区
d delete a partition 删除分区
p print the partition table 显示分区
w write table to disk and exit 保存分区
q quit without saving changes 不保存分区
t change a partition's system id 改变分区的ID号
l list known partition types 显示分区的ID号。

磁盘分区:
# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF
disklabel
Building a new DOS disklabel with disk identifier 0xb7e9deb1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +200M

Command (m for help): P

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux

Command (m for help): N
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (27-130, default 27):
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 130 835380 5 Extended

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (27-130, default 27):
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-130, default 130): +400M

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 130 835380 5 Extended
/dev/sdb5 27 78 417658+ 83 Linux

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (79-130, default 79):
Using default value 79
Last cylinder, +cylinders or +size{K,M,G} (79-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7e9deb1

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 130 835380 5 Extended
/dev/sdb5 27 78 417658+ 83 Linux
/dev/sdb6 79 130 417658+ 83 Linux

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

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


# partprobe
# cat /proc/partitions
major minor #blocks name

8 64 1048576 sde
8 0 20971520 sda
8 1 204800 sda1
8 2 20765696 sda2
8 32 1048576 sdc
8 16 1048576 sdb
8 17 208813 sdb1
8 18 1 sdb2
8 21 417658 sdb5
8 22 417658 sdb6
8 48 1048576 sdd
253 0 18665472 dm-0
253 1 2097152 dm-1
#


# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
52208 inodes, 208812 blocks
10440 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801

正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# mkdir /media/sdb1
# mount /dev/sdb1 /media/sdb1/
# df -Ph
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/rootvg-LogVol01 18G 2.2G 15G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sdb1 198M 5.8M 182M 4% /media/sdb1
#

# vim /etc/fstab 在文件末尾添加以下行。
/dev/sdb1 /media/sdb1 ext4 defaults 0 0

# umount /media/sdb1/
# mount -a
# df -hP
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/rootvg-LogVol01 18G 2.2G 15G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sdb1 198M 5.8M 182M 4% /media/sdb1
#


RAID的分类:
1、软RAID,通过软件实现RAID的功能。需要消耗CPU和MEM资源。
2、ServerRAID,服务器的RAID。
3、专业的磁盘阵列。(低,中,高)
# cd /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/md/
# ls
dm-bufio.ko dm-queue-length.ko dm-snapshot.ko
dm-crypt.ko dm-raid45.ko dm-thin-pool.ko
dm-delay.ko dm-raid.ko dm-zero.ko
dm-flakey.ko dm-region-hash.ko faulty.ko
dm-log.ko dm-registry.ko linear.ko
dm-log-userspace.ko dm-replicator.ko persistent-data
dm-memcache.ko dm-repl-log-ringbuffer.ko raid0.ko
dm-mirror.ko dm-repl-slink-blockdev.ko raid10.ko
dm-mod.ko dm-round-robin.ko raid1.ko
dm-multipath.ko dm-service-time.ko raid456.ko
# ls |grep raid
dm-raid45.ko
dm-raid.ko
raid0.ko
raid10.ko
raid1.ko
raid456.ko
#

RAID0
RAID1
RAID5
RAID6

mdadm 创建RAID设备。
-C 创建RAID。
-v 显示创建的过程(linux通用参数)
-l RAID级别,-l0 -l1 -l5 -l6 -l10
-n RAID组中的硬盘数量
-x 热备盘的数量

# mdadm -Cv /dev/md0 -l1 -n2 -x1 /dev/sdc /dev/sdd /dev/sde
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: size set to 1048564K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2](S) sdd[1] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]
[===========>.........] resync = 55.3% (580160/1048564) finish=0.0min
speed=193386K/sec

unused devices: <none>
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2](S) sdd[1] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>
#


LVM的概念:
lvm逻辑卷管理。分为三层。
物理卷:由独立的分区、硬盘、卷,RAID设备组成。
卷组:由1个或多个物理卷组成。
逻辑卷:在卷组之上,可以划分1个或多个逻辑卷。在线扩容,在线缩小容量,支持快照等功能。


LVM逻辑卷的创建步骤:
1、创建物理卷 pvcreate /dev/md0
2、创建卷组 vgcreate datavg /dev/md0
3、创建逻辑卷 lvcreate -L 500M -n lun0 datavg
4、对逻辑卷进行格式化(创建文件系统) mkfs.ext4 /dev/mapper/datavg-lun0
5、挂载使用 mkdir /media/lun0;
mount /dev/mapper/datavg-lun0 /media/lun0
6、设置开机自动运行。 vim /etc/fstab


# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2](S) sdd[1] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>
# mdadm -Ds > /etc/mdadm.conf
# pvcreate /dev/md0
Writing physical volume data to disk "/dev/md0"
Physical volume "/dev/md0" successfully created
# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 lvm2 a-- 1023.99m 1023.99m
/dev/sda2 rootvg lvm2 a-- 19.80g 0
# vgcreate datavg /dev/md0
Volume group "datavg" successfully created
# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 1 0 0 wz--n- 1020.00m 1020.00m
rootvg 1 2 0 wz--n- 19.80g 0
# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 datavg lvm2 a-- 1020.00m 1020.00m
/dev/sda2 rootvg lvm2 a-- 19.80g 0
# lvcreate -n lun0 -L 500M datavg
Logical volume "lun0" created
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lun0 datavg -wi-a--- 500.00m
LogVol00 rootvg -wi-ao-- 2.00g
LogVol01 rootvg -wi-ao-- 17.80g
# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 1 1 0 wz--n- 1020.00m 520.00m
rootvg 1 2 0 wz--n- 19.80g 0
# mkfs.ext4 /dev/mapper/datavg-lun0
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# mkdir /media/lun0
# mount /dev/mapper/datavg-lun0 /media/lun0/
# df -hP
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/rootvg-LogVol01 18G 2.2G 15G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sdb1 198M 5.8M 182M 4% /media/sdb1
/dev/mapper/datavg-lun0 485M 11M 449M 3% /media/lun0
# cp /root/install.* /media/lun0/
# ls /media/lun0/
install.log.bak install.log.syslog install.sh lost+found
#


对lun0扩容。
lvextend -L +100M /dev/mapper/datavg-lun0


# lvextend -L +100M /dev/mapper/datavg-lun0
Extending logical volume lun0 to 600.00 MiB
Logical volume lun0 successfully resized
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lun0 datavg -wi-ao-- 600.00m
LogVol00 rootvg -wi-ao-- 2.00g
LogVol01 rootvg -wi-ao-- 17.80g
# df -Ph
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/rootvg-LogVol01 18G 2.2G 15G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sdb1 198M 5.8M 182M 4% /media/sdb1
/dev/mapper/datavg-lun0 485M 11M 449M 3% /media/lun0
# resize2fs /dev/mapper/datavg-lun0
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/datavg-lun0 is mounted on /media/lun0; on-line
resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/datavg-lun0 to 614400 (1k) blocks.
The filesystem on /dev/mapper/datavg-lun0 is now 614400 blocks long.

# df -Ph
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/rootvg-LogVol01 18G 2.2G 15G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 28M 157M 15% /boot
/dev/sdb1 198M 5.8M 182M 4% /media/sdb1
/dev/mapper/datavg-lun0 582M 11M 542M 2% /media/lun0
#


对卷组做扩容
# pvcreate /dev/sdb5
Writing physical volume data to disk "/dev/sdb5"
Physical volume "/dev/sdb5" successfully created
# pvcreate /dev/sdb6
Writing physical volume data to disk "/dev/sdb6"
Physical volume "/dev/sdb6" successfully created
# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 datavg lvm2 a-- 1020.00m 420.00m
/dev/sda2 rootvg lvm2 a-- 19.80g 0
/dev/sdb5 lvm2 a-- 407.87m 407.87m
/dev/sdb6 lvm2 a-- 407.87m 407.87m
# vgextend datavg /dev/sdb5 /dev/sdb6
Volume group "datavg" successfully extended
# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 datavg lvm2 a-- 1020.00m 420.00m
/dev/sda2 rootvg lvm2 a-- 19.80g 0
/dev/sdb5 datavg lvm2 a-- 404.00m 404.00m
/dev/sdb6 datavg lvm2 a-- 404.00m 404.00m
# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 3 1 0 wz--n- 1.79g 1.20g
rootvg 1 2 0 wz--n- 19.80g 0
#


模拟硬盘出错。
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2](S) sdd[1] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>

# mdadm /dev/md0 -f /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md0
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2] sdd[1](F) sdc[0]
1048564 blocks super 1.2 [2/1] [U_]
[========>............] recovery = 42.0% (441152/1048564) finish=0.0min
speed=220576K/sec

unused devices: <none>
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2] sdd[1](F) sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>
# mdadm /dev/md0 -r /dev/sdd
mdadm: hot removed /dev/sdd from /dev/md0
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sde[2] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>
# mdadm /dev/md0 -a /dev/sdd
mdadm: added /dev/sdd
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdd[3](S) sde[2] sdc[0]
1048564 blocks super 1.2 [2/2] [UU]

unused devices: <none>
# mdadm -S /dev/md0
mdadm: Cannot get exclusive access to /dev/md0:Perhaps a running process,
mounted filesystem or active volume group?
#


linux系统下的软件包。
redhat,centos,suse: rpm包
debain,ubuntu: deb包
源码软件包: .tar .tar.gz .tar.bz2 .tgz .tbz2

rpm包:
1、CPU的位数的限制。i686,i386,i586 x86_64 ppc
2、操作系统版本的限制 rhel5,rhel6 rhel6.4 rhel6.5
3、noarch,表示无CPU,操作系统的限制。

libssh2-1.2.2-7.el6_2.3.x86_64

rpm软件包的安装。
1、rpm工具。
2、yum工具。(推荐)。


yum服务器的部署
1、指定yum的安装源(本地目录/data;cdrom;http服务器;ftp服务器)
2、编写yum安装源配置文件。
# cd /etc/yum.repos.d/
# ls
rhel-source.repo
# cp rhel-source.repo mycdrom.repo
# vim mycdrom.repo
# cat mycdrom.repo
[rhel6-server]
name=Red Hat Enterprise Linux $releasever
baseurl=file:///media/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

# mkdir /media/cdrom
# mount /dev/cdrom /media/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only
# cd /media/cdrom/

# yum clean all
Loaded plugins: product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Cleaning repos: rhel6-server
Cleaning up Everything
# yum list

3、安装软件包。 -i 安装 -v 显示过程 -h "#"
# yum search tomcat
# yum install tomcat6.noarch -y

# rpm -ivh httpd-2.2.15-15.el6_2.1.x86_64.rpm
error: Failed dependencies:
apr-util-ldap is needed by httpd-2.2.15-15.el6_2.1.x86_64
httpd-tools = 2.2.15-15.el6_2.1 is needed by
httpd-2.2.15-15.el6_2.1.x86_64
# rpm -ivh httpd-2.2.15-15.el6_2.1.x86_64.rpm
httpd-tools-2.2.15-15.el6_2.1.x86_64.rpm
apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm
Preparing... ########################################### [100%]
1:apr-util-ldap ########################################### [ 33%]
2:httpd-tools ########################################### [ 67%]
3:httpd ########################################### [100%]
#


4、升级软件包
-U 升级
--force 覆盖安装
--nodeps 强制安装(不推荐)

# rpm -Uvh httpd-2.2.15-15.el6_2.1.x86_64.rpm --force
--nodeps
Preparing... ########################################### [100%]
1:httpd ########################################### [100%]
#


5、卸载软件包。
# rpm -qa |grep httpd
httpd-tools-2.2.15-15.el6_2.1.x86_64
httpd-2.2.15-15.el6_2.1.x86_64
# rpm -e httpd httpd-tools
# rpm -qa |grep httpd


6、软件包的查询。
查询系统中已安装的软件包。 rpm -qa |grep vsftpd
查看vsftpd软件包安装到哪些目录,软件包中有哪些文件。 rpm -ql vsftpd
# rpm -ql vsftpd|more
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
...省略

查看软件包什么时候安装的。rpm -qi vsftpd
# rpm -qi vsftpd
Name : vsftpd Relocations: (not relocatable)
Version : 2.2.2 Vendor: Red Hat, Inc.
Release : 11.el6 Build Date: 2012年03月02日 星期五
20时42分21秒
Install Date: 2014年10月27日 星期一 19时29分38秒 Build Host:
x86-001.build.bos.redhat.com
Group : System Environment/Daemons Source RPM:
vsftpd-2.2.2-11.el6.src.rpm
Size : 339284 License: GPLv2 with exceptions
Signature : RSA/8, 2012年05月09日 星期三 18时33分40秒, Key ID
199e2f91fd431d51
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://vsftpd.beasts.org/
Summary : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.


查询某个文件属于哪个软件包。
# whereis mpstat
mpstat: /usr/bin/mpstat /usr/share/man/man1/mpstat.1.gz
# rpm -qf /usr/bin/mpstat
sysstat-9.0.4-20.el6.x86_64
# rpm -ivh sysstat-9.0.4-20.el6.x86_64.rpm --force
Preparing... ########################################### [100%]
1:sysstat ########################################### [100%]


6、rpm包的校验。
# rpm -Vf /bin/pwd
# ls -l /bin/pwd
-rwxr-xr-x. 1 root root 31656 4月 17 2012 /bin/pwd
# chown bin.bin /bin/pwd
# rpm -Vf /bin/pwd
.....UG.. /bin/pwd
# chmod 644 /bin/pwd
# rpm -Vf /bin/pwd
.M...UG.. /bin/pwd
# touch /bin/pwd
# ls -l /bin/pwd
-rw-r--r--. 1 bin bin 31656 10月 28 20:32 /bin/pwd
# rpm -Vf /bin/pwd
.M...UGT. /bin/pwd
# echo "" >> /bin/pwd
# ls -l /bin/pwd
-rw-r--r--. 1 bin bin 31657 10月 28 20:33 /bin/pwd
# rpm -Vf /bin/pwd
prelink: /bin/pwd: prelinked file size differs
SM?..UGT. /bin/pwd
# chown root.root /bin/pwd
# chmod 755 /bin/pwd
# rpm -Vf /bin/pwd
prelink: /bin/pwd: prelinked file size differs
S.?....T. /bin/pwd
#


8、软件套件包的安装。
yum grouplist 查看光盘中的套件包名称。 ###查看
yum groupinstall "套件包名称" -y ###安装
yum groupremove "套件包名称" -y ###卸载


源码包的安装。
1、下载源码包。
2、解包和解压缩到指定目录
3、进入解包目录,查看README文件,INSTALL文件
4、根据README文件的提示安装。
4.1、配置软件包 ./configure --help
(查看./configure的选项),产生Makefile文件。
4.2、编译软件包 make ###执行Makefile文件
4.3、安装软件包 make install


安装实验:
1、安装proftpd软件包。

# tar -zxf proftpd-* -C /opt
# cd /opt/proftpd*
# vim README
# yum install gcc -y (安装gcc软件包,如果没有安装的话)
# ./configure --prefix=/usr/local/proftpd
# make
# make install

# cd /usr/local/proftpd/
# ls
bin etc include lib libexec sbin share var
# cd sbin/
# ls
ftpscrub ftpshut in.proftpd proftpd
# ./proftpd
2014-10-28 20:55:24,650 test proftpd[16796]: fatal: Group: Unknown group
'nogroup' on line 30 of '/usr/local/proftpd/etc/proftpd.conf'
# groupadd nogroup
# ./proftpd
2014-10-28 20:56:50,609 test proftpd[16804]: warning: unable to determine IP
address of 'test'
2014-10-28 20:56:50,609 test proftpd[16804]: error: no valid servers
configured
2014-10-28 20:56:50,609 test proftpd[16804]: fatal: error processing
configuration file '/usr/local/proftpd/etc/proftpd.conf'
2014-10-28 20:56:53,593 test proftpd[16807]: warning: unable to determine IP
address of 'test'
2014-10-28 20:56:53,593 test proftpd[16807]: error: no valid servers
configured
2014-10-28 20:56:53,593 test proftpd[16807]: fatal: error processing
configuration file '/usr/local/proftpd/etc/proftpd.conf'

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.4.47 test
# ./proftpd
#
# netstat -natup|grep :21
tcp 0 0 0.0.0.0:21 0.0.0.0:*
LISTEN 16813/proftpd


# tar -zxf webmin-1.680.tar.gz -C /opt/
# cd /opt/webmin-1.680/
# vim README
# ./setup.sh
***********************************************************************
* Welcome to the Webmin setup script, version 1.680 *
***********************************************************************
Webmin is a web-based interface that allows Unix-like operating
systems and common Unix services to be easily administered.

Installing Webmin in /opt/webmin-1.680 ...

***********************************************************************
Webmin uses separate directories for configuration files and log files.
Unless you want to run multiple versions of Webmin at the same time
you can just accept the defaults.

Config file directory [/etc/webmin]:
Log file directory [/var/webmin]: /var/log/webmin

***********************************************************************
Webmin is written entirely in Perl. Please enter the full path to the
Perl 5 interpreter on your system.

Full path to perl (default /usr/bin/perl):

Testing Perl ...
Perl seems to be installed ok

***********************************************************************
Operating system name: Redhat Enterprise Linux
Operating system version: 6

***********************************************************************
Webmin uses its own password protected web server to provide access
to the administration programs. The setup script needs to know :
- What port to run the web server on. There must not be another
web server already using this port.
- The login name required to access the web server.
- The password required to access the web server.
- If the webserver should use SSL (if your system supports it).
- Whether to start webmin at boot time.

Web server port (default 10000):
Login name (default admin):
Login password:
Password again:
The Perl SSLeay library is not installed. SSL not available.
Start Webmin at boot time (y/n): y
***********************************************************************
Creating web server config files..
..done

Creating access control file..
..done

Inserting path to perl into scripts..
..done

Creating start and stop scripts..
..done

Copying config files..
..done

Configuring Webmin to start at boot time..
..done

Creating uninstall script /etc/webmin/uninstall.sh ..
..done

Changing ownership and permissions ..
..done

Running postinstall scripts ..
Use of uninitialized value in -r at
/opt/webmin-1.680/webalizer/webalizer-lib.pl line 16.
Use of uninitialized value in split at /opt/webmin-1.680/acl/acl-lib.pl line
47.
..done

Enabling background status collection ..
..done

Attempting to start Webmin mini web server..
Starting Webmin server in /opt/webmin-1.680
Pre-loaded WebminCore
..done

***********************************************************************
Webmin has been installed and started successfully. Use your web
browser to go to

http://test:10000/

and login with the name and password you entered previously.


网络基础:
1、网络IP地址的配置。
方法1:直接修改/etc/sysconfifg/network-scripts/ifcfg-eth0文件.(永久IP)
方法2:执行setup命令,修改IP地址。
方法3:执行ifconfig eth0 192.168.1.1/24命令修改IP地址(临时IP)


# setup
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0c:29:34:77:bd
NM_CONTROLLED=yes ##是否收NetworkerManager服务接管,建议设为no。
ONBOOT=yes ##network服务启动时,是否激活。
TYPE=Ethernet
UUID="542a2c35-a70b-4a54-b787-2fe4f32d6130"
IPADDR=172.16.4.49
NETMASK=255.255.255.0
GATEWAY=172.16.4.1
IPV6INIT=no ##关闭IPv6
USERCTL=no ##是否允许普通用户修改IP地址

# cat /etc/resolv.conf ##DNS客户端文件
nameserver 192.168.1.1
nameserver 202.96.128.166
# cat /etc/sysconfig/network ##辅助配置文件
NETWORKING=yes ##激活IPv4
HOSTNAME=test ##主机名。


# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes ###网卡是否连接网线。yes表示连接。


# ifconfig eth0 172.16.4.49/24
# ifconfig eth0:1 192.168.100.1/24
# ifconfig eth0:1
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:34:77:BD
inet addr:192.168.100.1 Bcast:192.168.100.255

Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

# ping 192.168.100.1 -c1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
64 bytes from 192.168.100.1: icmp_seq=1 ttl=64 time=0.202 ms

--- 192.168.100.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.202/0.202/0.202/0.000 ms

# ip addr list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast

state UP qlen 1000
link/ether 00:0c:29:34:77:bd brd ff:ff:ff:ff:ff:ff
inet 172.16.4.49/24 brd 172.16.4.255 scope global eth0
inet 192.168.100.1/24 brd 192.168.100.255 scope global eth0:1
inet6 fe80::20c:29ff:fe34:77bd/64 scope link
valid_lft forever preferred_lft forever


# ifconfig eth0:1 down 停止eth0:1接口
# ifconfig eth0:1 up


route 设置路由。
1、设置网络路由:
route add -net <目标网段> gw <网关> dev <进出的网络接口>
到达202.13.13.0/24网段,通过172.16.4.1网关出去,设备接口为eth0

route add -net 202.13.13.0/24 gw 172.16.4.1 dev eth0

2、设置主机路由:
route add -host <目标主机> gw <网关> dev <进出的网络接口>
到达202.13.13.100网段,通过172.16.4.1网关出去,设备接口为eth0

route add -host 202.13.13.100/24 gw 172.16.4.1 dev eth0

3、设置默认路由:
route add default gw 172.16.4.1 dev eth0

192.168.100.100/25 192.168.100.0

# ipcalc -mbn 192.168.100.100/25
NETMASK=255.255.255.128
BROADCAST=192.168.100.127
NETWORK=192.168.100.0
# ipcalc -mbn 192.168.100.129/25
NETMASK=255.255.255.128
BROADCAST=192.168.100.255
NETWORK=192.168.100.128


网络连通性判断:
ping -c1 172.16.4.49

traceroute www.canway.net


网络端口的检查。
netstat -atnup |more -a 所有 -t tcp, -u udp, -n 不测试网络 -p 进程
# netstat -atnup|grep :21
tcp 0 0 0.0.0.0:21 0.0.0.0:*

LISTEN 18350/vsftpd
tcp 0 0 172.16.4.49:21 192.168.3.158:56401

FIN_WAIT2 -


netstat -anlp -l 监听

netstat -rn 查看路由
netstat -i 查看接口。

# watch netstat -i


/etc/hosts 主机名和IP地址的对应关系文件


远程管理Linux系统:
1、ssh服务器
2、vnc服务器
3、webmin服务器


ssh服务器的配置:
默认开启了ssh服务器,即22号端口,任何有效的用户都可以连接。
一个标准的sshd_config配置文件。

# cat /etc/ssh/sshd_config|grep -Evn "^$|^#"
13:Port 22
15:ListenAddress 172.16.4.49
21:Protocol 2
31:ServerKeyBits 1024
36:SyslogFacility AUTHPRIV
42:PermitRootLogin no
43:allowusers jake@172.16.4.0/24
67:PasswordAuthentication yes
71:ChallengeResponseAuthentication no
82:GSSAPIAuthentication no
84:GSSAPICleanupCredentials no
98:UsePAM yes
101:AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY

LC_MESSAGES
102:AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
103:AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
104:AcceptEnv XMODIFIERS
110:X11Forwarding no
123:UseDNS no
133:Subsystem sftp /usr/libexec/openssh/sftp-server
# useradd jake
# passwd jake
# /etc/init.d/sshd restart

login as: jake
jake@172.16.4.49's password:

[jake@test ~]$ su -
密码:
# ls
anaconda-ks.cfg file.txt install.sh proftpd-

1.3.5.tar.gz word
backup_etc.tar.gz install.log.bak kk1 webmin-1.680.tar.gz
dir1 install.log.syslog log winscp554setup.exe
#


ssh客户端:
1、for linux
ssh -P <port> <remote_ip>
scp local.file <remote_ip>:/dirname/remote.file 上传
scp <remote_ip>:/dirname/remote.file local.file 下载

2、for windows
putty,SecureCRT==> ssh
winscp ==> scp,sftp


ssh服务器的认证机制:
1、本地用户认证。(/etc/shadow)
2、通过rsa或dsa非对称密钥对认证。(推荐)
# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
5b:5f:9c:65:b7:18:5d:a2:c4:bd:3e:09:b9:1f:1d:be root@test
The key's randomart image is:
+--[ DSA 1024]----+
| .... .|
| ...o..|
| .o o+|
| o.+=o|
| S . ==+.|
| o ...=..|
| . .. o.|
| .E |
| |
+-----------------+
# ls
id_dsa id_dsa.pub
# scp id_dsa.pub 172.16.4.49:/root/.ssh/authorized_keys

# ssh 172.16.4.49
The authenticity of host '172.16.4.49 (172.16.4.49)' can't be established.
RSA key fingerprint is e6:ee:be:7c:4f:f1:1c:15:ec:01:1b:55:10:63:de:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.4.49' (RSA) to the list of known hosts.
Enter passphrase for key '/root/.ssh/id_dsa':
Enter passphrase for key '/root/.ssh/id_dsa':
Enter passphrase for key '/root/.ssh/id_dsa':
root@172.16.4.49's password:
Permission denied, please try again.
root@172.16.4.49's password:
Permission denied, please try again.
root@172.16.4.49's password:
Permission denied (publickey,password).

# ssh 172.16.4.49
Enter passphrase for key '/root/.ssh/id_dsa':
Last login: Tue Oct 28 22:43:16 2014 from 172.16.4.49
#
#


VNC服务器:
1、vnc服务器的工作原理
2、安装vnc服务器。
# yum search vnc-server
# yum install tigervnc-server.x86_64 -y
#
3、配置vnc服务器。
# yum groupinstall "通用桌面" -y
# yum search vnc-server
# yum install tigervnc-server.x86_64 -y
# vncserver :1

You will require a password to access your desktops.

Password:
Verify:

New 'test:1 (root)' desktop is test:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/test:1.log

# cd /root/.vnc/
# ls
passwd test:1.log test:1.pid xstartup
# vim xstartup
将文件中末尾中的twm更改gnome-session

# vncserver -kill :1 关闭:1图形界面
Killing Xvnc process ID 21090
# vncserver :2 启动:2图形界面

New 'test:2 (root)' desktop is test:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/test:2.log

# netstat -atnup|grep -i vnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:*
LISTEN 21182/Xvnc
tcp 0 0 0.0.0.0:6002 0.0.0.0:*
LISTEN 21182/Xvnc
tcp 0 0 :::6002 :::*
LISTEN 21182/Xvnc
# /etc/init.d/iptables stop

# vim /etc/sysconfig/vncservers
# cat /etc/sysconfig/vncservers |tail -1
VNCSERVERS="2:root"
# service vncserver restart
关闭 VNC 服务器:2:root [失败]
正在启动 VNC 服务器:2:root
New 'test:2 (root)' desktop is test:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/test:2.log

[确定]
# netstat -antup|grep -i vnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:*
LISTEN 22492/Xvnc
tcp 0 0 0.0.0.0:5903 0.0.0.0:*
LISTEN 21916/Xvnc
tcp 0 0 0.0.0.0:6002 0.0.0.0:*
LISTEN 22492/Xvnc
tcp 0 0 0.0.0.0:6003 0.0.0.0:*
LISTEN 21916/Xvnc
tcp 0 0 172.16.4.49:5903 172.16.4.47:53462
ESTABLISHED 21916/Xvnc
tcp 0 0 :::6002 :::*
LISTEN 22492/Xvnc
tcp 0 0 :::6003 :::*
LISTEN 21916/Xvnc
#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值