日常積累的一些linux和營運的東西

來源:互聯網
上載者:User

轉自: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:.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.