日常积累的一些linux和运维的东西


转自:http://my.benorz.org/index.php/more/135/zh-cn

============证书生成======
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore ben.keystore -validity 3600

=======================常用到的命令========================
netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
  状态:描述
  CLOSED:无连接是活动的或正在进行
  LISTEN:服务器在等待进入呼叫
  SYN_RECV:一个连接请求已经到达,等待确认
  SYN_SENT:应用已经开始,打开一个连接
  ESTABLISHED:正常数据传输状态
  FIN_WAIT1:应用说它已经完成
  FIN_WAIT2:另一边已同意释放
  ITMED_WAIT:等待所有分组死掉
  CLOSING:两边同时尝试关闭
  TIME_WAIT:另一边已初始化一个释放
  LAST_ACK:等待所有分组死掉

被DDOS了
你使用这个命令可以查出哪个IP地址连接最多,将其封了.

netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n
netstat -na|grep SYN|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n
cat file |grep google |awk ‘/Googlebot/{print $1}’|sort|uniq|sort -rn

netstat -n |awk ‘/^tcp/{print substr($5,0,(index($5,”:”)-1)),$NF}’|sort -r|uniq -c|sort -rn|head -n 5
[root@mth01 logs]# cat *.log|awk ‘/GET/{++N[$1]} END{for(i in N){print N,i}}’|sort -rn|head -n8

==============JVM内存优化===========
-Xmn256M -Xms1024M -Xmx1024M -XX:MaxNewSize=512m -XX:MaxPermSize=512m”

增量备份
rsync -v -a -z -e ssh –delete /opt/virtual/ 192.168.3.1:/bakhome/virtual
rsync -v -a -z -e ssh –delete /opt/mthpic/ 192.168.3.1:/bakhome/mthpic
===============================

——–什么序列号忘记了,好像是server 2003的————–
EnterPrise :YCFX3-376TJ-KD224-Y9B8J-7XDQK
Standard :738XF-4MBKQ-9GRM6-4MVVH-PVJ6Q
Web :GH9QJ-FY3VX-VCD6X-3T2VV-3G9QV
Datacenter :YWD28-W67QX-F22JD-3JJJ6-7H8R3

Windows XP 专业版 (这个号保证正版,可以用):
MRX3F-47B9T-2487J-KWKMF-RPWBY

时间服务器
cn.pool.ntp.org
=======缓存清理(只支持32位系统下使用)=================
编译:
引用 blog.s135.com
wget http://www.wa.apana.org.au/~dean/sources/purge-20040201-src.tar.gz
tar zxvf purge-20040201-src.tar.gz
cd purge
make

  清除Squid缓存示例:
  1、清除 URL 以“.mp3”结尾的缓存文件
引用
purge -p pic.benorz.org:80 -P 1 -se ‘\.jpg$’
purge -p pic.benorz.org:80 -P 1 -se ‘\.gif$’
purge -p html.benorz.org:80 -P 1 -se ‘\.swf$’
purge -p html.benorz.org:80 -P 1 -se ‘\.html$’
purge -p html.benorz.org:80 -P 1 -se ‘benorz.org’
  2、清除URL中包含benorz.org的所有缓存:
引用
./purge -p localhost:80 -P 1 -se ‘benorz.org’

  我喜欢将程序推到后台去执行,让它慢慢地去清Squid缓存,同时将输出内容记录到purge.log文件:
引用
./purge -p localhost:80 -P 1 -se ‘benorz.org’ > purge.log 2>&1 &
============================================================================================
Linux 每日小技巧

/*每日一更新*/
/*从今天开始每天给大家提供一个小技巧,方便大家学习和LINUX知识!*/
/*以命令,系统管理,小技巧为主*/

1.按内存从大到小排列进程:
ps -eo “%C : %p : %z : %a”|sort -k5 -nr

2.查看当前有哪些进程;查看进程打开的文件:
ps -A ;lsof -p PID

3.获取当前IP地址(从中学习grep,awk,cut的作用)
ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6-

4.统计每个单词出现的频率,并排序
awk ‘{arr[$1]+=1 }END{for(i in arr){print arr”\t”i}}’ 文件名 | sort -rn

5.显示10条最常用的命令
sed -e “s/| /\n/g” ~/.bash_history | cut -d ‘ ‘ -f 1 | sort | uniq -c | sort -nr | head

6.杀死Nginx进程(杀死某一进程)
ps -ef|grep -v grep |grep nginx|awk ‘{print $2}’ 或
for i in `ps aux | grep nginx | grep -v grep | awk {’print $2′}` ; do kill $i; done

7.列出当前文件夹目录大小,以G,M,K显示。
du -b –max-depth 1 | sort -nr | perl -pe ’s{([0-9]+)}{sprintf”%.1f%s”, $1>=2**30? ($1/2**30, “G”): $1>=2**20? ($1/2**20, “M”):$1>=2**10? ($1/2**10, “K”): ($1, “”)}e’

8.清空linux buffer cache
sync && echo 3 > /proc/sys/vm/drop_caches

9.将当前目录文件名全部转换成小写
for i in *; do mv “$i” “$(echo $i|tr A-Z a-z)”; done

10.消除vim中的^M的几种方法
1)dos2uninx filename
2)sed -e ’s/^M//’ filename
3)vim中 :s/^M//gc
4)col -bx newfile
5)tr -s “\r\n” “\n” newfile

11. 清除所有arp缓存
arp -n|awk ‘/^[1-9]/ {print “arp -d “$1}’|sh

12. 绑定已知机器的arp地址
cat /proc/net/arp | awk ‘{print $1 ” ” $4}’ |sort -t. -n +3 -4 > /etc/ethers

==================oracle操作步骤=====================
su oracle

source /home/oracle/.bash_profile

cd /opt/oracle/p*/10.2/bin

lsnrctl start

sqlplus / as sysdba

SQL> startup

====================

SQL> exit停止:$ sqlplus

Enter user-name:/ as sysdba
SQL> shutdown immediate
SQL> exit

列出 Oracle 进程:$ ps a€“fuoracle
create or replace directory dump_dir as ‘/home/oracle/dump’
impdp system/123456 dumpfile=gh_080822.dmp DIRECTORY=dump_dir
impdp system/123456 dumpfile=mth20081014.dmp DIRECTORY=dump_dir
impdp system/123456 dumpfile=mth.dmp DIRECTORY=dump_dir
impdp mth/mth dumpfile=MTH_PROP_JOURNAL%U.dmp DIRECTORY=dump_dir
impdp system/123456 dumpfile=gh_080822.dmp CONTENT=METADATA_ONLY DIRECTORY=dump_dir
drop user xxxx cascade;
用sys登录: connect as /sysdba;
解锁scott: alter user scott account unlock;
===================修改2003默认远程终端端口==================
1、HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp下的PortNumber=3389改为自宝义的端口号
2、HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp下的PortNumber=3389改为自宝义的端口号
===================================
基本的使用方法
*取得squid运行状态信息: squidclient -p 80 mgr:info
*取得squid内存使用情况: squidclient -p 80 mgr:mem
*取得squid已经缓存的列表: squidclient -p 80 mgr:objects. use it carefully,it may crash
*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
*强制更新某个url:squidclient -p 80 -m PURGE http://www.php-oa.com/static.php
*更多的请查看:squidclient -h 或者 squidclient -p 80 mgr:

* 如何得知 squid 执行中的状态?
最简单的方式便是透过浏览器来观察。squid 本身提供一只 cgi 程式,档名为cachemgr.cgi,squid 安装完后将它复制到 Apache 下的 cgi-bin 这个目录下即可使用。
要察看Cache Manager提供的资讯时,请在浏览器的位址列中键入
http://服务器的名称或IP位址/cgi-bin/cachemgr.cgi
当然,我更加喜欢使用下面的方法
squidclient -t 1 -h localhost -p 80 mgr:inf 这样也行
[root@MTH93 squid]# bin/squidclient -h BEN -p 80 mgr:
HTTP/1.0 200 OK
Server: squid/2.6.STABLE21-20080721
Date: Thu, 23 Oct 2008 04:49:14 GMT
Content-Type: text/plain
Expires: Thu, 23 Oct 2008 04:49:14 GMT
Last-Modified: Thu, 23 Oct 2008 04:49:14 GMT
X-Cache: MISS from pic.benorz.org
Via: 1.0 pic.benorz.org:80 (squid/2.6.STABLE21-20080721)
Connection: close

mem Memory Utilization public
cbdata Callback Data Registry Contents public
events Event Queue public
squidaio_counts Async IO Function Counters public
coss COSS Stats public
diskd DISKD Stats public
config Current Squid Configuration hidden
ipcache IP Cache Stats and Contents public
fqdncache FQDN Cache Stats and Contents public
dns Dnsserver Statistics public
external_acl External ACL stats public
http_headers HTTP Header Statistics public
menu This Cachemanager Menu public
shutdown Shut Down the Squid Process hidden
offline_toggle Toggle offline_mode setting hidden
info General Runtime Information public
filedescriptors Process Filedescriptor Allocation public
objects All Cache Objects public
vm_objects In-Memory and In-Transit Objects public
openfd_objects Objects with Swapout files open public
pending_objects Objects being retreived from the network public
client_objects Objects being sent to clients public
io Server-side network read() size histograms public
counters Traffic and Resource Counters public
peer_select Peer Selection Algorithms public
digest_stats Cache Digest and ICP blob public
5min 5 Minute Average of Counters public
60min 60 Minute Average of Counters public
utilization Cache Utilization public
histograms Full Histogram Counts public
active_requests Client-side Active Requests public
storedir Store Directory Stats public
store_check_cachable_stats storeCheckCachable() Stats public
store_io Store IO Interface Stats public
pconn Persistent Connection Utilization Histograms public
refresh Refresh Algorithm Statistics public
delay Delay Pool Levels public
forward Request Forwarding Statistics public
client_list Cache Client List public
asndb AS Number Database public
server_list Peer Cache Statistics public

export JAVA_HOME=/usr/java/jdk1.6.0_12/
export PATH=$JAVA_HOME/bin/:$PATH
export CLASSPATH=$JAVA_HOME/lib:.

你可能感兴趣的:(linux)