11 月 292012
 

查看系统时区

[root@oracle ~]# date
Wed Nov 28 10:29:03 CST 2012
[root@oracle ~]# date -R
Wed, 28 Nov 2012 10:29:06 +0800

查看时区配置文件

[root@oracle ~]# ls /usr/share/zoneinfo/

CentOS 6.3系统中时区文件包含的中国标准时城市

Chongqing
Chungking
Harbin
Shanghai
Urumqi

设定时区
向导方式

[root@oracle ~]# tzselect

覆盖方式

# cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime

禁用UTC时间

#vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false

常见时区

UTC (Universal Time Coordinated,UTC)世界协调时间
CST (China Standard Time UTC+8:00)中国沿海时间(北京时间)
GMT (Greenwich Mean Time)格林威治标准时间

美国常用时区及与中国时差

EST 东部时间 13小时
MST 山地时间 15小时
PST 太平洋时间 16小时
11 月 292012
 
[root@oracle ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 9
Please select one of the following time zone regions.
1) east China - Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of Tibet & Xinjiang
5) west Tibet & Xinjiang
#? 1
The following information has been given:
China
east China - Beijing, Guangdong, Shanghai, etc.
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Wed Nov 28 10:24:46 CST 2012.
Universal Time is now: Wed Nov 28 02:24:46 UTC 2012.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
[root@oracle ~]#
11 月 292012
 

#yum install logwatch

查看配置文件目录
#ls /usr/share/logwatch/default.conf/

编辑配置文件
[root@oracle default.conf]# vi logwatch.conf

配置文件参数
指定系统日志存储目录(默认)
LogDir = /var/log

指定临时目录
TmpDir = /var/cache/logwatch

邮件报告的接收联系人
MailTo = root
多个联系人采用逗号分隔
MailTo = user1@mail.com,user2@mail.com

邮件发件人名称
MailFrom = Logwatch

指定报告内容时间段
Range = yesterday
可选参数包括、
All Today Yesterday

报告详细程度
Detail = Low

报告服务类型
Service = All
查看支持的报告服务类型
#ls /usr/share/logwatch/scripts/services/
afpd denyhosts ftpd-messages named postfix saslauthd syslogd
amavis dhcpd ftpd-xferlog netopia pound scsi tac_acc
arpwatch dnssec http netscreen proftpd-messages secure up2date
audit dovecot identd oidentd pureftpd sendmail vpopmail
automount dpkg imapd openvpn qmail sendmail-largeboxes vsftpd
autorpm emerge init pam qmail-pop3d shaperd windows
bfd evtapplication in.qpopper pam_pwdb qmail-pop3ds slon xntpd
cisco evtsecurity ipop3d pam_unix qmail-send smartd yum
clamav evtsystem iptables php qmail-smtpd sonicwall zz-disk_space
clamav-milter exim kernel pix raid sshd zz-fortune
clam-update eximstats mailscanner pluto resolver sshd2 zz-network
courier extreme-networks modprobe pop3 rt314 stunnel zz-runtime
cron fail2ban mountd portsentry samba sudo zz-sys

邮件发送参数(默认)
mailer = “sendmail -t”

系统每日计划任务
[root@oracle default.conf]# ls /etc/cron.daily/
0logwatch logrotate mlocate.cron readahead.cron
cups makewhatis.cron prelink tmpwatch
[root@oracle default.conf]#

手工执行报告发送
# /usr/share/logwatch/scripts/logwatch.pl

查看系统日志报告
#logwatch –print

# logwatch –range Today –print –mailto user1@mail.com

# /usr/share/logwatch/scripts/logwatch.pl –mailto user1@mail.com

11 月 282012
 

查看系统登录成功记录
#last
查看最后两笔登录记录
#last -n 2
查看指定用户的登录记录
#last oracle
oracle pts/0 :0.0 Thu Nov 22 08:53 still logged in
oracle pts/1 :0.0 Tue Nov 20 17:39 still logged in
oracle tty1 :0 Tue Nov 20 17:26 still logged in

清空登录日志文件(特殊编码)
[root@localhost root]# echo “”>/var/log/wtmp

再次查看系统登录记录
[root@localhost root]# last

查看系统登录失败记录
#lastb
root ssh:notty 192.168.1.50 Tue Nov 27 20:21 – 20:21 (00:00)
root ssh:notty 192.168.1.50 Tue Nov 27 20:20 – 20:20 (00:00)
root ssh:notty 192.168.1.50 Mon Nov 26 11:09 – 11:09 (00:00)
root ssh:notty 192.168.1.50 Tue Nov 20 17:11 – 17:11 (00:00)

清空登录系统失败记录(特殊编码)
# echo “”> /var/log/btmp
再次查看系统登录失败记录
# lastb

清空历史命令记录
[root@localhost root]# history -c

[root@localhost root]# echo “”> .bash_history

查看指定数量的最近命令记录
[root@oracle ~]# history 3
10 history
11 cat .bash_history
12 history 3
使用命令记录编号重复执行命令
[root@oracle ~]# !11
cat .bash_history
执行最后一次以tar起始的命令
[root@oracle ~]# tar xzf awstats-7.0.tar.gz
[root@oracle ~]# rm -rf awstats-7.0
[root@oracle ~]# !tar
tar xzf awstats-7.0.tar.gz
[root@oracle ~]#

历史命令记录数量控制
#env |grep HISTSIZE
HISTSIZE=1000

11 月 272012
 

linux 断开某个用户的终端连接
断开某个用户的连接
who 查看用户连接

断开远程用户
fuser -k /dev/pts/x

x为who下看到的这个用户的pts序号

断开本地用户

fuser -k /dev/ttyx

x为who查看到的tty序号

11 月 272012
 

使用pwgen批量生成随机密码

安装

[root@oracle pwgen-2.06]# ./configure --prefix=/usr/local/pwgen
[root@oracle pwgen-2.06]# make
[root@oracle pwgen-2.06]# make install
mkdir -p /usr/local/pwgen/bin /usr/local/pwgen/man/man1
/usr/bin/install -c pwgen /usr/local/pwgen/bin/pwgen
/usr/bin/install -c -m 644 ./pwgen.1 /usr/local/pwgen/man/man1/pwgen.1
[root@oracle pwgen-2.06]#

查看帮助

[root@oracle bin]# ./pwgen --help
Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]
Options supported by pwgen:
 -c or --capitalize
 Include at least one capital letter in the password
 -A or --no-capitalize
 Don't include capital letters in the password
 -n or --numerals
 Include at least one number in the password
 -0 or --no-numerals
 Don't include numbers in the password
 -y or --symbols
 Include at least one special symbol in the password
 -s or --secure
 Generate completely random passwords
 -B or --ambiguous
 Don't include ambiguous characters in the password
 -h or --help
 Print a help message
 -H or --sha1=path/to/file[#seed]
 Use sha1 hash of given file as a (not so) random generator
 -C
 Print the generated passwords in columns
 -1
 Don't print the generated passwords in columns
 -v or --no-vowels
 Do not use any vowels so as to avoid accidental nasty words

生成4组12位长度密码

[root@oracle bin]# ./pwgen 12 4
aik3ieC8oNee Chee6ririsi5 noiPo6aiquoo AeShaeriequ9

生成含有符号的4组12位长度密码

[root@oracle bin]# ./pwgen -y 12 4
uu!qu2Oobii4 kohM/ai6eith miReipi;th4e chu5ooj~ooNg

生成完全随机且含有符号的4组12位长度密码

[root@oracle bin]# ./pwgen -sy 12 4
g=~6J]!$}4Ws GK&0YCvj(pq~ AV`Q[Y|3wdwi ;0KUJ:f8bCCT

相关下载:
(1) pwgen 2.06

11 月 272012
 

Tomcat访问日志配置

#vi /usr/local/tomcat/conf/server.xml
<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
directory="logs"  prefix="app01_access_log." suffix=".txt"
pattern="combined" resolveHosts="false"/>

日志文件目录

directory="logs"

日志文件前缀

prefix="app01_access_log."

日志文件后缀

suffix=".txt"

模式

common(默认)

192.168.11.70 - - [26/Nov/2012:17:12:35 +0800] "GET / HTTP/1.1" 200 8579
192.168.11.70 - - [26/Nov/2012:17:12:35 +0800] "GET /tomcat.gif HTTP/1.1" 200 1934
192.168.11.70 - - [26/Nov/2012:17:12:35 +0800] 
"GET /tomcat-power.gif HTTP/1.1" 200 2324
192.168.11.70 - - [26/Nov/2012:17:12:35 +0800] 
"GET /asf-logo-wide.gif HTTP/1.1" 200 5866

combined

192.168.11.70 - - [27/Nov/2012:13:27:37 +0800] "GET / HTTP/1.1" 200 8579 "-" 
"Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0"
192.168.11.70 - - [27/Nov/2012:13:27:37 +0800] "GET /tomcat.gif HTTP/1.1" 304 - 
"http://192.168.11.150:8080/" "Mozilla/5.0 (Windows NT 6.1; rv:16.0) 
Gecko/20100101 Firefox/16.0"
192.168.11.70 - - [27/Nov/2012:13:27:37 +0800] "GET /asf-logo-wide.gif HTTP/1.1" 
304 - "http://192.168.11.150:8080/" "Mozilla/5.0 (Windows NT 6.1; rv:16.0) 
Gecko/20100101 Firefox/16.0"
192.168.11.70 - - [27/Nov/2012:13:27:37 +0800] "GET /tomcat-power.gif HTTP/1.1" 
304 - "http://192.168.11.150:8080/" "Mozilla/5.0 (Windows NT 6.1; rv:16.0) 
Gecko/20100101 Firefox/16.0"
192.168.11.70 - - [27/Nov/2012:13:27:37 +0800] "GET /favicon.ico HTTP/1.1" 304 - 
"-" "Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0"

解析主机名

resolveHosts="false"

日志文件日期格式(可选参数)

fileDateFormat="yyyy-MM-dd.HH"

按月生成日志文件

fileDateFormat="yyyy-MM"
11 月 272012
 

如果丢失 admin 密码,则可以使用下列步骤将安全设备重置到其缺省设置。配置 将失去,但是对设备的访问将恢复。要执行此操作,需要连接控制台。

注意: 在缺省情况下,会启用设备恢复功能。可通过输入 unset admin device-reset 命 令禁用它。同样,如果安全设备处于 FIPS 模式,恢复特征被自动禁用。

1. 在登录提示下,输入设备的序列号。

2. 在密码提示下,再次输入序列号。

出现以下消息:

!!!! Lost Password Reset !!!!You have initiated a command to reset the device to 
factory defaults, clearing all current configuration, keys and settings.Would 
you like to continue? y/n

3. 按 y 键。

出现以下消息:

!! Reconfirm Lost Password Reset !!If you continue, the entire configuration of 
the device will be erased.In addition, a permanent counter will be incremented 
to signify that this device has been reset.This is your last chance to cancel 
this command.If you proceed, the device will return to factory default 
configuration, which is: System IP: 192.168.1.1; username: netscreen; 
password: netscreen.Would you like to continue? y/n

4. 按 y 键,重置设备。现在可以用 netscreen 作为缺省用户名和密码进行登录。

11 月 262012
 

 

备份当前YUM配置文件

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

中国科技大学YUM更新源
USTC
mirrors.ustc.edu.cn

CentOS 5
http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=1
CentOS 6
http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2

更新缓存

[root@com01 ~]# yum makecache 
Loaded plugins: fastestmirror, presto Determining fastest mirrors 
base                                                           | 3.7 kB     00:00 
base/filelists_db                                              | 5.9 MB     00:03 
base/other_db                                                  | 2.6 MB     00:01 
base/group_gz                                                  | 211 kB     00:00 
extras                                                         | 3.5 kB     00:00 
extras/filelists_db                                            | 3.9 kB     00:00 
extras/prestodelta                                             |  863 B     00:00 
extras/other_db                                                | 4.3 kB     00:00 
updates                                                        | 3.5 kB     00:00 
updates/filelists_db                                           | 3.0 MB     00:04 
updates/other_db                                               | 410 kB     00:00 
Metadata Cache Created [root@com01 ~]#
11 月 262012
 

配置全局IP地址

AX(config)#ip address 192.168.11.2 /24
AX(config)#ip default-gateway 192.168.11.1

启用LAN接口

AX(config)#interface ethernet 1
AX(config-if:ethernet1)#enable
AX(config-if:ethernet1)#exit

配置真实服务器

AX(config)#slb server app01 192.168.11.150
AX(config-real server)#port 8080 tcp
AX(config-real server-node port)#exit
AX(config-real server)#exit
AX(config)#slb server app02 192.168.11.151
AX(config-real server)#port 8080 tcp
AX(config-real server-node port)#exit
AX(config-real server)#exit

配置服务组

AX(config)#slb service-group sg-http tcp
AX(config-slb service group)#member app01:8080
AX(config-slb service group)#member app02:8080
AX(config-slb service group)#exit

配置虚拟服务器

AX(config)#slb virtual-server vapp-http 192.168.11.100
AX(config-slb virtual server)#port 8080 tcp
AX(config-slb virtual server-slb virtua...)#service-group sg-http
AX(config-slb virtual server-slb virtua...)#no-dest-nat

真实服务器端配置

#ifconfig lo:0 192.168.11.100 netmask 255.255.255.255 -arp up
 
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
#echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce