Chinaunix首页 | 论坛 | 博客
  • 博客访问: 716193
  • 博文数量: 235
  • 博客积分: 4309
  • 博客等级: 中校
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-17 11:25
个人简介

If you don\\\\\\\\\\\\\\\'t wanna do it, you find an EXCUSE; if you do, you\\\\\\\\\\\\\\\'ll find a WAY :-)

文章分类

全部博文(235)

文章存档

2014年(3)

2013年(2)

2012年(31)

2011年(199)

分类: LINUX

2011-02-17 18:27:54

一:RPM (Red Hat Package Manager)

Package files: name - version - release.architectures.rpm


1.【Installing and Removing Software】

[root@rhel5 ~]#  ls -l /var/lib/rpm →→ 查看RPM 资料库
1.1. Install → :rpm -i, --install →→ 新、旧版本程序都保留, 一般用于升级Kernel,避免升级后不能正常
使用(保留旧有版本Kernel, 新版本Kernel 并不能保证100%没有问题)。
Upgrade→ :rpm -U, --upgrade →→ 一般用于升级应用程序, 不保留旧版本。
Freshen → :rpm -F, --freshen →→ 只更新已经安装过的程序(不保留旧版本), 通常用于更新

当前系统。
Erase→ :rpm -e --erase →→ 移除软体套件。
Options:- v, -h →→ 显示安装进度

1.2. Example
[root@rhel5 ~]# rpm -ivh bind-9.3.6-4.Pl.el5.rpm →→ 安装程序
[root@rhel5 ~]# rpm -e bind→→ 移除程序套件
[root@rhel5 ~]# rpm -Uvh  →→ 支持从服务器
端安装程序


1.3. 升级Kernel

[root@rhel5 ~]# uname -r →→ 显示目前Kernel 版本
2.6.18-164.2.1.el5xen
[root@rhel5 ~]# rpm -ivh kernel-2.6.30-11.EL.i686.rpm →→ 升级Kernel 
[root@rhel5 ~]# vi /boot/grub/grub.conf →→ 安装Kernel 后查看开机管理配置文件,发现多了一个开
机程序(默认仍使用原Kernel 开机)。


2.【RPM Queries】:
2.1.『Installed Package Options』:
rpm -qa lists installed packages →→ q=query, a=all 
rpm -qf filename shows owning package →→ 查询档案属于哪个套件
rmp -qi package_name general information →→ i=information 
rpm -ql package_name lists files in package →→ l=list ,列出套件里包含哪些档案


2.2.『Uninstalled Package Options』:
rpm -qip package_file.i386.rpm →→ i=information,p=package 显示套件档案的相关资讯
rpm -qlp package_file.i386.rpm →→ l=list ,列出套件里包含哪些档案


2.3.【验证RPM 档案是否被修改过】:
S               -file Size differs
M              -Mode differs(includes permissions and file type)
5               -MD5 sum differs
D              -Device major/minor number mismatch
L               -readLink (2) path mismatch
U              -User ownership differs
G              -Group ownership differs
T               -mTime differs

2.3.1.『安装后验证』:
[root@rhel5 ~]# rpm -Va →→ " V "(Verify) " a "(All) 验证所有档案与RPM 数据库进行比对, 显示出
被修改过的档案。
S.5....T c /etc/xinetd.d/eklogin →→ 5 表示档案MD5 被修改过
S.5....T c /etc/xinetd.d/eklogin →→ S 表示档案大小被修改过
S.5....T c /etc/xinetd.d/eklogin →→ T 表示档案mTime 被修改过
.M5....T c /etc/xinetd.d/eklogin →→ M 表示档案类型或权限被修改过
S.5....T c /etc/xinetd.d/eklogin
[root@rhel5 ~]# rpm -V package_name →→ 验证某个套件档案与RPM 数据库进行比对。
[root@rhel5 ~]# rpm -Vp package_file.i386.rpm →→ 与某个套件档案进行比对。


2.3.2.『安装前验证』:(Signature verification Before package install)
[root@rhel5 ~]# rpm --import RPM-GPG-KEY →→ 记录了各个RPM 档案文件的签署资料
[root@rhel5 ~]# rpm -qa gpg-pubkey →→ 查看目前的RPM-GPG-KEY 是否已经导入成功
[root@rhel5 ~]# rpm --checksig package_file.i386.rpm →→ 验证某个档案是否拥有RH 签章


3.【Other RPM Utilites and Features】:
3.1.『rpm2cpio』:
RPM 档案文件只有Root 可以使用,cpio 类型文件可供普通user 使用。
[root@rhel5 ~]# rpm2cpio sysstat-5.0.5-1.i386.rpm > sysstat.cpio →→ 将RPM 档案转cpio 类型
[root@rhel5 ~]# cpio -it < sysstat.cpio →→ 查看cpio 类型档案包括哪些内容。
[root@rhel5 ~]# cpio -id < sysstat.cpio →→ 将文件导入到当前目录


3.1.1.【cpio】:备份还原档案
-d               --make-directories
-i                --extract copy-in
-o               --create copy-out
-t                --list
[root@rhel5 ~]# mkdir test
[root@rhel5 ~]# touch test/t1
[root@rhel5 ~]# find test/ | cpio -o > test.cpio →→ 找到test 目录所有文件并打包成cpio 档案
[root@rhel5 ~]# cpio -it < test.cpio→→ 查看cpio 类型档案包括哪些内容。
[root@rhel5 ~]# cpio -id < test.cpio →→ 解压缩cpio


3.2.『rpmdb-redhat』: (安装包的相互关联数据库dependence)
[root@rhel5 ~]# rpm -ivh rpmdb-redhat-4-0.20050107.i386.rpm →→ 默认已安装

3.3.【Automatic Dependency Resolution】: (自动管理关联特性)

3.3.1.图形化套件管理视窗

[root@rhel5 ~]# pirut  →→(Package Install, Remove, and Update Tool)
[root@rhel5 ~]# system-config-packages  

3.3.2.必须安装redhatdb 2:关联性档案在同一目录中
[root@rhel5 ~]# rpm -ivh rpmdb-redhat-4-0.20050107.i386.rpm →→ 确定redhatdb 已安装
[root@rhel5 ~]# rpm -ivh xsane-0.92-13.i386.rpm --aid →→ " --aid "使得关联性套件自动安装

——————————————————————————————————————

 4.【Red Hat Network ( RHN )】: (检查需要更新的套件,需要支付一定费用。)
[root@rhel5 ~]# up2date →→ Red Hat Update Agent 进行套件更新
[root@rhel5 ~]# up2date-config →→ Red Hat Network Configuration, 更新套件默认保存在
/var/spool/up2date 目录


5.【Using Kickstart to Automate Installation】:(网络安装比CD-ROM 安装要快)
[root@rhel5 ~]# system-config-kickstart →→ 如果没有安装可以使用system-config-packages 进行
安装

5.1配置kickstart

Post-Installation Script(安装完毕要执行的script)  

→→  echo "nameserver 192.168.57.129" >> /etc/resolve.conf 
保存在: /root/ks.cfg

[root@rhel5 ~]# vi /root/ks.cfg→→ 查看刚刚配置好的kickstart 配置文件

——————————————————————————————————————

6.【Software RAID】: (将partition 模拟成硬盘)

RAID 0 (两个硬盘同时读写、速度快但是不安全同一份档案存共同存在两块硬盘上)
RAID 1 (数据分别存储在两个硬盘、速度慢但是相对安全同一份档案分别存在两块硬盘上)
RAID 5 (将逻辑运算值写入下一个硬盘, 安全性较高)

6.1.软件模拟RAID
[root@rhel5 ~]# partprobe →→ inform the OS of partition table changes
[root@rhel5 ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/sdb2 /dev/sdb3→→ " -l 0 "建立RAID0 " -n 2 "两个
硬盘
[root@rhel5 ~]# cat /proc/mdstat
[root@rhel5 ~]# mke2fs -j /dev/md0 →→ 格式化(create the filesystem with an ext3 journal)
[root@rhel5 ~]# mkdir /raiddata
[root@rhel5 ~]# mount /dev/md0 /raiddata/
[root@rhel5 ~]# vi /etc/fstab
/dev/md0 /raiddata ext3 defaults 1 2
~

~

:wq


6.2.[root@rhel5 ~]# mount →→ 查看挂载了哪些设备
[root@rhel5 ~]# mdadm /dev/md0 -f /dev/sdb2 →→ "-f " 模拟硬盘坏掉
[root@rhel5 ~]# mdadm /dev/md0 -a /dev/sdb2 →→ "-a " 将新建立的硬盘添加到RAID 硬盘


6.3.【LVM(Logical Volume Manager)】:

6.3.1. pvcreate
[root@rhel5 ~]# pvcreate /dev/sdb5 →→ pv=Physical Volume 
[root@rhel5 ~]# pvcreate /dev/sdb6 →→ pv=Physical Volume


6.3.2. vgcreate and lvcreate

[root@rhel5 ~]# vgcreate vg1 /dev/sdb5 /dev/sbd6 →→ vg=Volume Group 
[root@rhel5 ~]# lvcreate -L 30M -n lv01 vg1 →→ lv=Logical Volume , -L(size), -n(name)


[root@rhel5 ~]# mke2fs -j /dev/vg1/lv01 →→ 格式化
[root@rhel5 ~]# mkdir /lvmdata
[root@rhel5 ~]# mount /dev/vg1/lv01 /lvmdata
[root@rhel5 ~]# df -h →→ 列出系统中文件系统
[root@rhel5 ~]# vi /etc/fstab
/dev/vg1/lv01 /lvmdata ext3 defaults 1 2
~

~

 :wq


6.3.3. lvextend、ext2online、vgextend、vgdisplay

[root@rhel5 ~]# mount →→ 查看挂载了哪些设备
[root@rhel5 ~]# lvextend -L +20M /dev/vg1/lv01 →→ 动态放大Logical Volume 
[root@rhel5 ~]# ext2online /dev/vg1/lv01 →→ 格式化已经挂载起来的分区
[root@rhel5 ~]# vgextend vg1 /dev/sdb7 →→ 放大Volume Group 
[root@rhel5 ~]# vgdisplay vg1 →→ 查看Volume Group


6.3.4.『Remove Volume Group』
[root@rhel5 ~]# umount /lvmdata/ →→ 移除前卸载Logical Volume 
[root@rhel5 ~]# lvremove /dev/vg1/lv01 →→ 移除Logical Volume 
[root@rhel5 ~]# vgremove vg1 →→ 移除Volume Group


6.3.5.『The Linux Quota System』
Limit users usrquota
Limit groups grpquota
Limit to the number of blocks
Limit to the number of inodes
Soft limit ===>Grace period(允许暂时超过)
Hard limit
[root@rhel5 ~]# vi /etc/fstab
LABEL=/home /home ext3 defaults,usrquota 1 2
~

~ :wq


6.3.6.使用quota管理

[root@rhel5 ~]# mount -o remount /home →→ 重新挂载/home 
[root@rhel5 ~]# quotacheck -c /home →→ " -c "(create) 建立quota 资料库并存放到/home 
[root@rhel5 ~]# ls -l /home
total 28
-rw- - - - - - - 1 root root 7168 Jul 21 06:52 aquota.user


6.3.7.quotaon and quotaoff (turn filesystem quotas on and off)

[root@rhel5 ~]# quotaon /home
[root@rhel5 ~]# dd if=/dev/zero of=big bs=1M count=6 →→ " if "复制" of "复制到当前目录命名为big
bs(block size) count(block 数量) 建立一个名称为big 大小为6M 的档案

 

6.3.7. edquota  (edit user quotas)
[root@rhel5 ~]# ls -lh
Total 6.1M
-rw-rw-r- - 1 user1 user1 6.0M Jul 21 06:58 big


[root@rhel5 ~]# edquota user1 →→ 配置user1 的Quota 磁碟配额
Disk quotas for user user1(uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sda2 6180 3072 (KBytes) 5120 7 0 0

Soft limit hard limit inode Soft limit inode hard limit


[root@rhel5 ~]# quota →→ 查看本用户的quota 配置情况
[root@rhel5 ~]# ls -lh
[root@rhel5 ~]# edquota -p user1 user2 →→ 将user1 的Quota 设定应用到user2 * /
[root@rhel5 ~]# repquota -a ( 列出所有用户的Quota 配置)

7.【dump】: (ext2/ext3 filesystem backup) 备份分区
-level#               (0-9) →→ 0:Full backup,1-9 则只备份上次备份到目前为止没有备份的部分
-f                        指定备份储存在哪里
-u(update)        /etc/dumpdates


[root@rhel5 ~]# dump -0 -u -f ~/backup /dev/sda1 →→ 备份/dev/sda1 到~/backup 
[root@rhel5 ~]# vi /etc/dumpdates
/dev/sda1 0 Tue Oct 11 12:17:44 2009 +0800
~

~:wq

8.【备份档案到远端服务器】:
[root@rhel5 ~]# tar -czvf 
root@example1:/var/home.tar.gz  /home
[root@rhel5 ~]# Dump -0uf 
root@example1:/var/home.dump  /home

——————————————————————————————————————

 

二:【System Monitoring and Process Control】:(系统监控 与 服务安全)

 

9.1.【File system monitoring】:
[root@rhel5 ~]#  df -h →→  File system的使用情况。
[root@rhel5 ~]#  du -h /tmp →→  查看目录的使用情况。
[root@rhel5 ~]#  du -sh /tmp →→  " -s "(Summary)查看目录占用空间的情况。
[root@rhel5 ~]#  du -ah /tmp →→  " -a "(All)查看目录占用空间详细的情况。
logwatch →→  预设每天都会自动执行, 并将错误日志邮件给Root。

——————————————————————————————————————

9.2. find

[root@rhel5 ~]#  find / -type f -perm +6000 →→  " / "(搜索整个文件系统)" -f "(file)" perm "(permission)

[root@rhel5 ~]#  touch 6000
[root@rhel5 ~]#  touch 6600
[root@rhel5 ~]#  touch 2000
[root@rhel5 ~]#  chmod 6000 6000
[root@rhel5 ~]#  chmod 6600 6600
[root@rhel5 ~]#  chmod 2000 2000
[root@rhel5 ~]#  ls -l
total 0
- - - - - - S - - - 1 root root 0 Oct 3 12:12 2000
- - - S- - S - - - 1 root root 0 Oct 3 12:12 6000
-rwS - - S - - - 1 root root 0 Oct 3 12:12 6600 SUID+SGID+rw=(4+2)+(4+2)+0+0

[root@rhel5 ~]#  find / -type f -perm 6000 
[root@rhel5 ~]#  find / -type f -perm +6000 →→  有1即可
[root@rhel5 ~]#  find / -type f -perm -6000 →→  缺1不可

[root@rhel5 ~]#  find / -nouser →→  查找无法识别Owner的档案
[root@rhel5 ~]#  find / -nouser -exec chown root.root {} \; →→  " {} " 表示搜寻的结果都执行此操作。
[root@rhel5 ~]#  find / -type f -perm -2 →→  Other组有 Write权限的文件
[root@rhel5 ~]#  find / -type d -perm -2 →→  Other组有 Write权限的目录
——————————————————————————————————————

9.3. 去掉SUID权限重新挂载文件系统

[root@rhel5 ~]#  mount -o remount,nosuid / →→  去掉SUID权限重新挂载文件系统。
[root@rhel5 ~]#  mount
[root@rhel5 ~]#  mount -o remount /
——————————————————————————————————————
9.4. 
【lsattr】:(查看档案属性)
[root@rhel5 ~]# lsattr test →→  查看" test "档案的属性

9.5. 【chattr】:(管理档案属性)
chattr + | - | = attibute[attribute ...] file[file ...] →→  " + "表示添加属性," - "删除属性," = "设定属性。*/
A              -档案被修改时, 存取时间戳记不变
a              -值允许对档案做附加内容,源文件不可被覆盖(root only)
d              -dump指令做备份时,可以不用备份该档案
i               -档案不可变,不能删除或更改档案名称 (root only)
j               -将档案记录到 ext3 journal 里  (root only)
S              -资料被更改时,进行同步(synchronously)的动作立即写入到硬盘而不是缓冲区

[root@rhel5 ~]# chattr +a test →→  设定" test "档案的属性,只允许附加资料。
[root@rhel5 ~]# cat > test →→   导出到test 意味着覆盖
bash: test: Operation not permitted
[root@rhel5 ~]# cat >> test →→   附加动作则可以, 因为 test 档案属性为:chattr +a
[root@rhel5 ~]# cat file1 file2 file3 > file4→→  cat 指令将多个文件的内容导出到一个新的文件
里*/

[root@rhel5 ~]# chattr -a test →→  删除" test "档案的属性
[root@rhel5 ~]# chattr =aAS test →→  设定" test "档案的属性
[root@rhel5 ~]# lsattr test →→  查看" test "档案的属性
--S--a-A----- test
[root@rhel5 ~]# chattr = test →→  删除档案全部属性, " = "后面不输入任何属性即可。

——————————————————————————————————————

 9.6. 【Log file analysis】:
/var/log/messages  -记录了系统相关资讯
/var/log/secure  -authentication messages, xinetd services
/var/log/vsftpd.log  -FTP (vsftpd)相关资讯
/var/log/maillog  -记录了Mail相关资讯

syslogd       -Many daemons messages
klogd           -Kernel messages

[root@rhel5 ~]#  ls -l /etc/cron.daily/00-logwatch →→  logwatch预设每天执行一次
[root@rhel5 ~]#  mv /etc/cron.daily/00-logwatch /etc/cron.hourly →→  将logwatch搬移到" /etc/cron.hourly "目录 每小时执行一次
——————————————————————————————————————

9.7. 【facility.priority log_location】

常用Facilities如下: 
authpriv    -security/authorization messages
cron           -clock daemons
kern           -kernel messages
lpr              -printing system
mail            -mail system
news          -news system
syslog        -internal syslog messages

常用Priorities如下:
debug          -debugging information
info              -general information messages
notice          -normal,but significant,conditon
warning       -warning messages
err                -error condition
crit               -critical conditon
alert             -immediate action required
emerg          -system no longer available

——————————————————————————————————————

9.8. 管理系统日志

[root@rhel5 ~]#  vi /etc/syslog.conf
klogd负责如下日志
#kern.*        /dev/console(会将kernel信息马上在控制台显示)
kern.info    /var/log/kernel(管理info以上等级的信息)
#kern.info    tom,root(Mail 至用户info以上等级的信息)

syslogd负责如下日志
*.info;mail.none;authpriv.none;cron.none  /var/log/messages
authpriv.*                                                        /var/log/secure

mail.*                                                              -/var/log/maillog(" - " 表示会将记录先存到buffer)  
cron.*                                                              /var/log/cron
*.emerg                                       * (" * "Everyone表示会马上提示用户)
uucp,news,crit                                              /var/log/spooler
local7.*                                                           /var/log/boot.log

9.9. 重启服务
[root@rhel5 ~]#  service syslog restart →→  重启服务使设置生效。
——————————————————————————————————————
10.【Advanced syslogd Configuration】:
Operators
mail.info             -记录info(含)等级以上
mail.=info           -只记录info等级
mail.=!info          -仅不记录info等级
mail,cron.info    -记录mail,cron 等info(含)等级以上

10.1. 配置服务器接收远端LOG

Client端
[root@rhel5 ~]#  vi /etc/syslog.conf
#authpriv.*   @rhel5 (表示将日志存放到这台服务器上)
~
~
Server端
[root@rhel5 ~]#  vi /etc/sysconfig/syslog
SYSLOG_OPTIONS=" -r -m 0 " →→  在服务器端配置接收其他机器发送的LOG
~
~

——————————————————————————————————————

 11.【cron】

[root@rhel5 ~]# vi /etc/crontab →→ 编辑crontab
2 * * * * /bin/echo hello!
[root@rhel5 ~]# mail →→ 查看是否在后台执行了 echo指令

-u          username
-l           list
-r           remove crontab
-e          edit
-i           remove crontab(带有询问机制)

Minute  Hour  Day of month     Month   Day of week   Meaning
0              0              25                     12            *                 Run once a week
0              *               *                        *              *                 Run once an hour
2 4           *               *                        *              *                 Run once a day
*/10          *               *                        *              *                 Run once every 10 minutes
13           13            13                       *              5                Run once every 13th at 13:13,or every Friday


—————————————————————————————————————— 


12.【Process monitoring】:
[root@rhel5 ~]#  top →→  查看进程信息
按键 大写 P        -按照CPU排列
按键 大写 M      -按照Memory排列

[root@rhel5 ~]#  gnome-system-monitor
[root@rhel5 ~]#  kpm →→  KDE桌面的监控工具

[root@rhel5 ~]# vmstat  →→  显示 内存的 详细使用状况  
[root@rhel5 ~]# free      →→   显示 内存的 使用概要

——————————————————————————————————————

12.1.『调整程序或进程的优先级』
                  nice                                             renice
Target    Application                                   Process
Command nice -n      renice

——————————————————————————————————————

12.2. PS:
[root@rhel5 ~]# ps  -aux 
[root@rhel5 ~]# ps aux | less →→   将输出通过管道,使用less 查看
[root@rhel5 ~]# ps aux | grep →→   通过关键字查找进程

-aux            以BSD 风格显示进程(常用)
-efH            以System V 风格显示进程
-e , -A         显示所有进程
-a                显示终端上所有用户的进程
-x                显示无终端进程
-u                显示详细信息
-f                 树状显示
-w               完整显示信息
-l                 显示长列表

输出字段
USER          进程所有者
PID              进程
ID PPID       父进程
%CPU         CPU 占用率
%MEM        内存占用率
NI                 进程优先级。数值越大,占用CPU 时间越少
VSZ             进程虚拟大小
RSS             页面文件占用
TTY              终端
ID STAT      进程状态
D                  不可中断Uninterruptible sleep (usually IO)
R                  正在运行,或在队列中的进程
S                  处于休眠状态
T                  停止或被追踪
Z                  僵尸进程
W                进入内存交换(从内核2.6 开始无效)
X                 死掉的进程< 高优先级N 低优先级
L                 有些页被锁进内存s 包含子进程+ 位于后台的进程组;
l                   多线程,克隆线程multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

——————————————————————————————————————

12.3. pstree: →→   display a tree of processes
[root@rhel5 ~]# pstree  →→ 树状显示进程信息
-a     显示完整命令及参数
-c     重复进程分别显示
-n     按PID 排列进程

——————————————————————————————————————

12.4. pgrep and pkill: →→   look up or signal processes based on name and other attributes
[root@rhel5 ~]# pgrep -l →→ 显示进程的PID

——————————————————————————————————————

12.5.『Kill 指令』
[root@rhel5 ~]# kill -l →→  显示所有 kill的信息  
kill -9  -用于强制结束某个进程

——————————————————————————————————————

13. 【System Activity Reporting ( sar)】:

[root@rhel5 ~]#  yum install sysstat →→  必备安装包
[root@rhel5 ~]#  cd /var/log/sa
[root@rhel5 ~]#  sar →→  查看当天的报表
[root@rhel5 ~]#  vi sar31 →→  查看31号的报表

[root@rhel5 ~]#  vi /etc/cron.d/sysstat 
*/10 * * * * root  /usr/lib/sa/sa1 1 1
53 23 * * * root /usr/lib/sa/sa2 -A
~
~

——————————————————————————————————————

14. last →→  查看用户登录记录
[root@rhel5 ~]#  vi  .bash_history →→  储存使用者输入过的命令

[root@rhel5 ~]#whoami  →→  显示当前用户 
[root@rhel5 ~]#groups  →→ 显示目前用户属于哪个群组  
[root@rhel5 ~]#id   →→ 显示目前用户属于哪个群组 并且显示所属群组 ID  userID、groupID

[root@rhel5 ~]#users  →→  显示哪些用户登录到这台Linux系统 
[root@rhel5 ~]#who  →→ 显示哪些用户登录到这台Linux系统,  信息比较详细。
[root@rhel5 ~]#w  →→显示哪些用户登录到这台Linux系统,    信息最详细。 

[root@rhel5 ~]#last   →→ 查看用户登录、重启的  历史信息记录 
[root@rhel5 ~]#  last tom →→  查看用户 tom 登录记录

[root@rhel5 ~]#  ac -p →→  显示每个用户登录的总时间
[root@rhel5 ~]#  ac -d →→  显示每天用户登录的总时间

 

14.1.whois

查看域名的注册备案情况

[root@rhel5 ~]# whois baidu.cn
Domain Name: baidu.cn
ROID: 20030312s10001s00062053-cn
Domain Status: serverDeleteProhibited
Domain Status: serverUpdateProhibited
Domain Status: serverTransferProhibited
Registrant Organization: 百度在线网络技术(北京)有限公司
Registrant Name: 徐勇
Administrative Email: fengyongxiao@baidu.com
Sponsoring Registrar: 厦门东南融通在线科技有限公司
Name Server:proxy.baidu.com
Name Server:dns.baidu.com
Registration Date: 2003-03-17 12:20
Expiration Date: 2018-03-17 12:48

——————————————————————————————————————

 14.2.显示系统运行时间 和 负载情况
[root@rhel5 ~]# uptime
11:47:04 up 85 days,  2:10,  1 user,  load average: 2.40, 2.18, 2.34


14.3 accton

[root@rhel5 ~]#  rpm -qa | grep psacct
[root@rhel5 ~]#  accton /var/account/pacct →→  启用帐号记录, 会记录大量日志影响系统性能。
[root@rhel5 ~]#  lastcomm | less

[root@rhel5 ~]#  accton  →→  停用帐号记录

——————————————————————————————————————

15. 【Securing the Service】:
[root@rhel5 ~]#  ldd /usr/sbin/xinetd →→  查看程式都链接到哪些库
libwrap.so.0 => /usr/lib/libwrap.so.......... →→  只有链接到libwrap.so 的程式才支持 tcp_wrapper 安全机制
..............
~
~

——————————————————————————————————————
15.1. 【tcp_wrapper】:
支持 tcp_wrapper 的服务:
sendmail
sshd
xinetd
gdm
portmap
vsftpd

——————————————————————————————————————

15.2. 管理服务的使用权限

Syntax: Daemon_list : client_list

[root@rhel5 ~]#  vi /etc/hosts.allow
in.telnetd : 192.168.57.129
in.telnetd@192.168.57.129 : 192.168.57.0/255.255.255.0
in.telnetd@10.0.1.144 : 10.0.1.0/255.255.255.0
~
~
[root@rhel5 ~]#  vi /etc/hosts.deny
ALL EXCEPT in.telnetd : 192.168.0.
ALL : 192.168.0. EXCEPT 192.168.0.100
~
~

【Example】
[root@rhel5 ~]#  vi /etc/hosts.deny
in.telnetd : 192.168.0.100

vsftpd:  

vsftpd:  .example.com
→→  下面两个实现同样功能
vsftpd:  192.168.1.0/255.255.255.0
vsftpd:  192.168.1.

~
~

方法一:
[root@rhel5 ~]#  vi /etc/hosts.allow
sshd: 192.168.0.
~
~
[root@rhel5 ~]#  vi /etc/hosts.deny
sshd: ALL
~
~
方法二:
[root@rhel5 ~]#  vi /etc/hosts.deny
sshd: ALL EXCEPT 192.168.0.
~
~

——————————————————————————————————————

15.3. 查看服务的真正执行路径
[root@rhel5 ~]#  cat /etc/xinetd.d/klogin→→  查看klogin真正执行的程式是什么
server = /usr/kerberos/sbin/klogind

——————————————————————————————————————


17. 【wildcard】:(通配符)
ALL                always matches
LOCAL           all hosts without a dot in their name
UNKNOWN    all hosts that cannot be looked up
KNOWN         all hosts that can be determined
PARANOID     matches all hosts where lookup and reverse lookup do not match 

 

17.1.【Advanced Options】( 高级服务权限管理选项 )
Syntax:  Daemon_list : client_list [:option1 :option2 ..]


17.1.1.『Spawn 』
Example:  in.telnetd: ALL : spawn echo "login attempt from %c to %s" | mail -s warning root
%c client information (user@host)
%s server information(daemon@host)


 

17.1.2.『DENY』Can be used as an option in hosts.allow
Example:  ALL: ALL :Deny  →→  禁止所有服务 所有电脑的存取。

——————————————————————————————————————
18. 【xinetd Access Control】:
Syntax:
Allow with only_from = host_pattern
Deny with no_access = host_pattern

 

18.1. host-based        

根据IP控制服务使用权限
[root@rhel5 ~]#  vi  /etc/xinetd.d/klogin
........................................................
no_access = 192.168.0.100
only_from  =  192.168.0.0/24
#only_from =  192.168.0.0/255.255.255.0
#only_from =  192.168.1.0 (" 0 "代表 " * "(wildcard)这一行代表该网段。)
#only_from =  
#only_from =  .domain.com
~
~


18.2. time-based 

根据时间控制
[root@rhel5 ~]#  vi  /etc/xinetd.d/klogin

access_times = 9:00-18:00
~
~
:wq


18.3. 重启服务使配置生效
[root@rhel5 ~]#  service xinetd restart →→  重启服务

——————————————————————————————————————

#######################################################################

19.【Number of simultaneous connections】:(控制同时连线数)
[root@rhel5 ~]#  vi /etc/xinetd.d/telnet →→  Prevent DoS( Denial-of-Service )
.................................
instances  =60 (同一时间内最多连线 60个) Total Number
per_source =5 (同一IP address 连线最多 5个) Per IP Address
~
~
——————————————————————————————————————


20.各种加密措施


20.1. 【random】:
[root@rhel5 ~]#  ls -lh /dev/random →→  Encryption
crw-rw-rw-  1 root root 1,8 Oct 7 12:12 /dev/random

[root@rhel5 ~]#  ls -lh /dev/urandom →→  Decryption
crw-rw-rw-  1 root root 1,8 Oct 7 12:12 /dev/urandom

[root@rhel5 ~]#  cat /dev/random

 

20.2. 【One-Way Hashes】:
MD2,MD5,MDC2,RMD160,SHA,SHA1

 

20.3.【Symmetric Encryption】:(对称式加密,加密解密使用同一把钥匙)
DES,3DES,Blowfish,RC2,RC4,RC5,IDEA,CAST5

 

20.4.【Asymmetric Encryption】:(非对称式加密,加密解密使用两把钥匙)
One key uses to encrypt,and the other key will decrypt
Public Key     Private Key


——————————————————————————————————————


22. 【OpenSSH Overview】:
rcp             -remote copy


 

22.1. TOM用户端:
[root@rhel5 ~]#  rpm -qa | grep openssh


[root@rhel5 ~]#  ssh-keygen -t dsa →→  产生钥匙
Generating public/private dsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_dsa):
Private Key  →→  /home/tom/.ssh/id_dsa
Public Key  →→  /home/tom/.ssh/id_dsa.pub

[root@rhel5 ~]#  cd .ssh/
[root@rhel5 ~]#  ls -l
[root@rhel5 ~]#  mail -s "tom's key" jacky@rhel5.com < id_dsa.pub →→  将产生的KEY发送给jacky
——————————————————————————————————————

22.2. jacky用户端:

[root@rhel5 ~]#  mail →→  切换到jacky查看邮件

...................................

& w tom.key  →→  " w "(write)将邮件内文写入到文件

& x


[root@rhel5 ~]#  mkdir .ssh;chmod 700 .ssh →→  在用户Home目录建立.ssh目录并更改权限
[root@rhel5 ~]#  cp tom.key .ssh/authorized_keys
[root@rhel5 ~]#  cd .ssh/
[root@rhel5 ~]#  ls -l
[root@rhel5 ~]#  chmod 600 authorized_keys

[root@rhel5 ~]#  ssh tom@127.0.0.1 →→  切换到tom用户, 发现不用输入密码就可以登录了。

——————————————————————————————————————

22.3. 【OpenSSH Server Configuration】:
[root@rhel5 ~]#  vi /etc/ssh/sshd_config
..................................................
#Protocol 2,1 →→  "2"(SSH2:have high security) "1"(SSH1:have low security,provided for compatibility with older systems)
#ListenAddress 192.168.0.147:22 
#ListenAddress : :
..................................................
PermitRootLogin no →→  设定为不允许远端登录
~
~
[root@rhel5 ~]#  service sshd restart →→  重启服务

——————————————————————————————————————

 

——————————————————————————————————————

阅读(526) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~