歡迎您光臨本站 註冊首頁

個人經驗點滴

←手機掃碼閱讀     火星人 @ 2014-03-23 , reply:0

1、hexdump ?C | od -A d ?t x1 以二進位方式查看文件內容
2、SPident ?v | cat /etc/SuSE-release 查看版本號;
3、getfacl ?R ?P ?skip-base ?absolute-names 列出目錄下的所有具有ACL類型許可權的文件(絕對路徑,且跳過符號連接文件);
4、setfacl ?R ?P ?b 清楚目錄下所有文件的ACL;
5、setfacl ?R ?P ?m u:sysadmin:rx
6、/etc/ssh/sshd_config:AllowUsers root osadmin,控制哪些用戶允許通過ssh登入;
7、在HP 的linux上構造陣列:
hpacucli controller all show
hpacucli controller slot=0 physicaldrive all show;
hpacucli controller slot=0 array A create type=logicaldrive raid=5 size=? 顯示A陣列上的剩餘空間;
hpacucli controller slot=0 array A create type=logicaldrive raid=5 創建邏輯盤(剩餘容量);
8、Linux下安裝oracle時注意要設置環境變數:事先安裝Java和orarun 然後運行/usr/sbin/rcoracle,這樣就在添加/etc/profile.d/oracle.sh,登入oracle用戶后所有的環境變數已設好;export DISPLAY=:0.0;
備份:exp \'/ as sysdba\' file=/data/backup/travel_user.dmp owner=TRAVEL_USER direct=y log=/data/backup/travel_user.log;
恢復到另一個資料庫中:先創建用戶create user travel_user identified by travel_cxpeng default tablespace users; 授權grant connect ,resource to travel_user; 恢復imp \'/ as sysdba\' file=/tmp/travel_user.dmp fromuser=travel_user touser=travel_user tablespaces=users buffer=100000000 log=testimp.log;建立客戶端連接時SERVUCE_NAME要等於伺服器端定義的「服務名」(show paramter service查看);設置為歸檔模式:SQL> SHUTDOWN IMMEDIATE;SQL> STARTUP MOUNT;SQL> ALTER DATABASE ARCHIVELOG;SQL> archive log start;SQL> alter system set log_archive_start=true scope=spfile;SQL> ALTER DATABASE OPEN;

9、chkstat ?set /etc/permissions,……
10.http://www.xwinman.org 窗口管理器評測網站;
11.http://www.distrowatch.com linux發行版本評測網站
12.http://www.linuxiso.org 可下載各種linux發行版本;
13.http://clustercenter.org/集群軟體評測網站;
14.diff ?Nru Makefile Makefile.new >my.patch
diff ?Nru fee.c fee.new.c >>my.patch
生成一個補丁併發布給用戶,用戶收到后打補丁:patch ?l 注意事項:
diff ?Naur 兩個目錄不要包含任何「/」,用patch ?Np1是個好注意
15.刪除一個打文件,但磁碟空間並沒有釋放,為什麼?那個大文件正被某個程序打開,找到並退出那個程序即可。
16.Ssh遠程沒法登入時考慮:能否ping通?sshd是否啟動(netstat ?tnlp|grep sshd)?主控制台進入然後ssh localhost能否成功?防火牆策略是否屏蔽了22號埠?刪除~/.ssh/known_hosts再試能否成功?刪除伺服器上的/etc/ssh/ssh_*並rcsshd restart然後再試,檢查/etc/ssh的許可權是否正確?如果ssh登陸非常慢,表明對客戶的ip反解釋超時,在sshd_config中設置UseDNS no或者把客戶端的IP和hostname加入到服務端的/etc/hosts文件中或者在DNS中建立響應的反解釋記錄。
17.從rpm包中抽取文件:
rpm2cpio http://szxist02-lx/install/sles9_i386/SUSE-SLES-9-Service-Pack-Version-3/CD1/suse/
i586/openldap2-2.2.24-4.12.i586.rpm | cpio -i --make-directories或者
rpm -ivh --nodeps --relocate /=/tmp/ http://szxist02-lx/install/sles9_i386/SUSE-SLES-9-Service
-Pack-Version-3/CD1/suse/i586/openldap2-2.2.24-4.12.i586.rpm
18.記錄用戶按鍵:把「script ?q ?a $HOME/.cmrc」加入到/etc/profile末尾,則可記錄用戶輸入的全部命令和結果;在控制台上輸入mkfifo /tmp/foo; cat /tmp/foo;然後把/usr/bin/script ?q ?f /tmp/foo加入到/etc/profile末尾,那麼用戶輸入的每一鍵都會及時顯示在主控台上;
19.利用make命令進行源代碼控制(先在目錄下touch copy)。
Vim Makefile
copy: *.pl
scp $? root@10.72.129.163:/root/wlm
touch copy
20.檢查根系統失敗的處理(機器重起后自動檢查根失敗,自動進入只讀維護模式):
1)、使用安裝盤引導進入resecue system;
發現直接使用e2fsck -f /dev/cciss/c0d0p2由於內存不夠被cancel了,應該增加虛擬內存數量:
  2)、mount /dev/cciss/c0d1p1 /mnt;
  3)、dd if=/dev/zero of=/mnt/swap bs=1024 count=1024000; #修復文件系統要使用大量內存,所以要創建一個大的臨時交換區。
  4)、mkswap /mnt/swap;
  5)、swapon -a;
  6)、e2fsck -b 119200 -B 4096 -c -C 0 -D -F -k -p -v /dev/cciss/c0d0p2;#使用超級塊副本(位於119200塊)並起用壞塊檢測(-c)、並顯示進度(-C 0)、優化磁碟文件(-D)、為壞塊預留空間(-k)、自動修復(-p)、顯示詳細過程(-v);
  7)、swapoff -a; rm /mnt/swap;
  8)、shutdown -r now
  9)、從光碟啟動
  10)、發現網卡不行,把原來的配置刪除並重配;
**設想:直接進入維護模式(此時根為只讀),把/dev/cciss/c0d1p1搭接過來,轉上述2步**
21.root密碼忘記的處理:使用安裝盤引導進入resecue system;mount /dev/sda2 /mnt; chroot /mnt; cd /dev; mknod urandom c 1 9; passwd;(修改root密碼即可);exit; umount /mnt; shutdown ?r now;
22.建立整個目錄的影子: lndir ,todir要事先存在
23.手工修改機器名字:vim /etc/HOSTNAME; sysctl kernerl.hostname = 「ldapserver」
24.跟蹤命令的執行路徑:strace ?ff ?o /tmp/gdm.txt /etc/init.d/xdm start;列出系統中的設備:lspci ?v; lsusb ?v ; lsscsi ?v;跟蹤一個進程的系統調用:strace ?p
25.掃描機器上的埠是否開啟:nmap ?sU | -p <埠>,如:nmap ?sU 10.193.14.0/24 ?p 123
26.在虛擬內存中創建虛擬文件系統:mount ?t tmpfs tmpfs /dev/shm ?o size=64M(最大不能超過64M);
27.絆定安裝目錄:mkdir ?p /opt/tmp; mount --bind /opt/tmp /mnt; mount --bind /opt/tmp /abc,這樣就可以通過多個地方訪問目錄/opt/tmp了,新創建的文件在任何地方都是可見的。mkdir /opt/abc; mount --bind / /opt/abc,把根目錄再安裝到其他地方。
28.通過yast配置后查看到底修改了哪些文件:touch /tmp/timer->yast->find / -newer /tmp/timer
29.設置目錄的粘連位,這樣目錄中的文件只有主人才可以刪除,即使其他人也有寫的許可權:chmod ?v a+wt /tmp/abc
30.查看一個目錄佔用的磁碟空間:du ?sh dir-name
31.當登陸輸入用戶名和密碼之後報錯:Permissions on the password database may be too restrictive,並登陸失敗。原因是認證模塊無法從密碼源(/etc/shadow、LDAP或kerberos庫)獲取信息,相應檢查/etc/shadow的許可權,LDAP和KERBEROS的可用性。
32.如果系統的網卡名不是從eth0順序取起,那麼刪除文件/etc/udev/rules.d/ 30-net_persistent_names.rules中的內容並重起網路子系統即可。
33.跟蹤路由:traceroute ip | mtr ip
34.一台機器的兩快網卡分別在兩個網段上,其中一塊網卡接到交換機上,另一塊沒接網線,但交換機保MAC地址衝突,通過ping通一塊網卡ip,結果發現MAC地址經常發生變化,把下列幾行加入文件/etc/sysctl.conf中並運行命令chkconfig boot.sysctl on:
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.arp_ignore = 2
net.ipv4.conf.all.arp_announce = 1
net.ipv4.conf.default.arp_ignore = 2
net.ipv4.conf.default.arp_announce = 1
35.計算文件的MD5摘要:md5sum > .md5;驗證文件完整性(文件和其摘要文件都在同一個目錄下):md5sum ?c .md5
36.加快mozilla firefox的速度:啟動firefox並在URL中輸入about:config修改下列參數
Network.dns.disableIPv6 true
Network.http.pipelining true
Network.http.pipelining.maxrequests 8
Network.http.proxy.pipelining true
37.手工生成sshd的主機密要文件/etc/ssh/ssh_host_dsa_key:
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
ssh-keygen -b 1024 -t dsa -f /etc/ssh/ssh_host_dsa_key -N ""
38.如果把一個軟體包安裝在非標準目錄(如/tools),那麼為了能正常運行,需要做:
1)、把/tools/bin加到環境變數PATH中;
2)、把/tools/sbin加到root的環境變數PATH中;
3)、把/tools/lib 加到/etc/ld.so.conf(或加到環境變數LD_LIBRARY_PATH中),並運行命令ldconfig更新/etc/ld.so.cache;
4)、把/tools/man加到/etc/man_db.conf或加到環境變數MANPATH中;
5)、把/tools/info加到INFOPATH 環境變數中;
6)、把/tools/lib/pkgconfig(有時是/tools/share/pkgconfig)加到PKG_CONFIG_PATH中;
7)、如果要用這個特殊的頭文件編譯文件,則編譯時把/tools/include加到CPPFLAGS,如:CPPFLAGS=」/tools/include」 ./configure && make;
39.rpm2targz和 deb2targz可以轉化.deb, .rpm格式的文件到.tar.gz格式的文件;
40.找出最近10分鐘內被訪問過的文件:find / -amin -10;找出最近10分鐘內被修改過的文件:find / -mmin -10;查看一個進程打開的全部文件ls /proc//fd
41.使用命令kibitz實現兩個用戶共享一個shell,這樣任何一方的輸入輸出另一方業看得到。首先兩個用戶同時登陸到一台機器上,然後甲方發出命令:
# w
16:23:10 up 2:21, 2 users, load average: 0.00, 0.00, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 16:15 5:36 0.03s 0.03s -bash
root pts/1 16:15 0.00s 0.08s 0.00s w
# kibitz -tty pts/0 root
asking root to type: kibitz -12037
乙方的屏幕上出現:
Message from root@admincon on pts/1 at 16:25 ...
Can we talk? Run: kibitz -12037
EOF
這時乙方輸入kibitz -12037就可以了。任何一方輸入exit就可以結束共享。
42. CDPNs(Context-Dependent Path Names)具有許多實用場景,linux中CDPN有:@hostname(返回uname -n);@mach(實際返回機器型號=uname -m);@os(uname ?s);@sys(`uname ?m`_`uname ?s`);@uid; @gid。例如建立鏈接:touch /tmp/{0,100,150}; ln ?s @uid log,那麼用戶root登陸, log實際上是鏈接到0上;
43.在腳本的開頭加一個命令set ?e指明此後任何一個返回非0的命令都將終止本腳本的執行。
44.構造啟動光旁:
# mkinitrd ?k vmlinuz ?i initrd ?d /dev/cdrom
# mkisofs ?o rescue.iso ?b boot/isolinux.bin ?c boot/boot.cat ?no-emul-boot ?boot-load-size 4 ?boot-info-table ?l /mnt/rootnew
45.編譯安裝源程序的rpm包:
#rpm -Uvh clumanager-1.2.26.1-1.src.rpm
#rpmbuild -bs /usr/src/redhat/SPECS/clumanager.spec

#rpmbuild --rebuild --target i686 /usr/src/redhat/SRPMS/clumanager-1.2.26.1-1.src.rpm
46.生成自簽證書:
證書和密鑰放在同一個文件server.pem中:
openssl req -newkey rsa:1024 -x509 -nodes -out server.pem -keyout server.pem -days 3650

證書和密鑰放在同不同文件中:
openssl req -newkey rsa:1024 -x509 -nodes -out server-crt.pem -keyout server-key.pem -days 3650

1)# /usr/bin/openssl genrsa 1024 > /etc/httpd/conf/ssl.key/server.key --生成鑰匙
2)# /usr/bin/openssl req -new -key /etc/httpd/conf/ssl.key/server.key -x509 -days 365 -out /etc/httpd/conf/ssl.crt/server.crt ---生成證書

# openssl x509 -in a.cer -out 123.pem -pubkey --從證書中導出公鑰。
47.創建軟陣列:mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/hd[ac]1,創建軟陣列設備/dev/md0,raid 1,由兩個物理設備/dev/hda1和/dev/hdc1組成鏡像,即向設備/dev/md0寫數據時相當於同時向兩個物理設備寫,兩個物理設備實際上是互為鏡像。
實驗:
# dd if=/dev/zero of=dev1 bs=1024 count=5000
# dd if=/dev/zero of=dev2 bs=1024 count=5000
# losetup /dev/loop1 dev1
# loserup /dev/loop2 dev2
# mdadm --create /dev/md0 --level=1 --raid-devices=2 dev{1,2}
# mkfs.ext2 /dev/md0
# mount /dev/md0 /mnt
# cd /mnt; ls -la / > abc
# umount /mnt
# mdadm --stop /dev/md0
# mount /dev/loop1 /mnt --進入目錄/mnt,發現文件abc。
# umount /mnt; mount /dev/loop2 /mnt --進入目錄/mnt,也發現文件abc。
即軟raid1陣列可以合起來用,也可以分開來用。
48.不啟動機器上的postfix,直接使用nail命令通過其他郵件系統發送郵件:
# set smtp=172.24.1.82
或:
# vim ~/.mailrc
set smtp=smtp.huawei.com
set smtp-auth=login
set smtp-auth-user=w56869
set smtp-auth-password=I#wanna#fly
set folder=imap://w56869@webmail.huawei.com
set password-accountname@webmail.huawei.com=I#wanna#fly
# nail -s hellp LuckyJack@huawei.com
I am a playboy, how are you?
.
注意如果直接在公司內部向內部員工的郵箱發送郵件,那麼上面的配置文件中只要保留第一行就可以了。
49.測試伺服器的證書:openssl s_client -connect myserver.com:636 -showcerts -state -CAfile /var/cacert/cacert.pem
50.掃描另外一台機器上的全部監聽埠:nmap -P0 10.75.47.5
51.禁用和激活網卡:ifdown eth1, ifup eth1
52.建立NAT:
/sbin/iptables -A INPUT -i 「eth1」 -j ACCEPT
echo 「1」>/proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -s 「192.168.1.0/24」 -o 「eth0」 -j MASQUERADE
---注意:eth0對外網卡,eth1是內部網卡,內部網段192.168.1.0/24。
53、#iptables ?A FORWARD ?s 192.168.1.23 ?m mac ?mac-source 00:e0:4c:3d:5e:4f ?j ACCEPT
上例表明源IP地址為192.168.1.23,源MAC地址為00:e0:4c:3d:5e:4f的計算機能夠通過防火牆,如果這個用戶將自己的IP地址改成了192.168.1.24,而該地址同樣也做了MAC地址的match,那麼要想通過更改IP地址而獲取上網許可權的企圖是徒勞的。
說明:可以通過iptables實現IP地址與MAC地址綁定的功能,但還有一種更加高效的方法,我們在這裡簡要的說明一下,在/etc/目錄下編輯文件ethers,在文件中添加如下內容:
192.168.1.1 00:e0:4c:3d:5e:4f
192.168.1.1 00:e0:4c:3d:5b:3d
…….
文件編輯完成後執行命令:
#/sbin/arp ?f
54.製作啟動cd:

It is possible to create a bootable CD-ROM containing the Linux start-up files if your system has an installed CD writer. It is easiest to create a bootable CD with the ISOLINUX boot manager. The SUSE installation CDs are also made bootable with isolinux.
1.Boot the installed system first using the following alternate procedure:
Boot from the installation CD or DVD as for installation.
Choose the preselected option 『Installation』 during the boot sequence.
Choose the language and keyboard map next.
In the following menu, choose 『Boot installed system』.
The root partition is automatically detected and the system is booted from it.
2.Install syslinux with YaST.
3.Open a root shell. The following commands create a temporary directory and copy the files required for the booting of the Linux system (the isolinux boot loader as well as the kernel and the initrd) into it:
4.mkdir /tmp/CDroot
5.cp /usr/share/syslinux/isolinux.bin /tmp/CDroot/
6.cp /boot/vmlinuz /tmp/CDroot/linux
7.cp /boot/initrd /tmp/CDroot
8.Create the boot loader configuration file /tmp/CDroot/isolinux.cfg with your preferred editor. Enter the following content:
9.DEFAULT linux
10.LABEL linux
11. KERNEL linux
12. APPEND initrd=initrd root=/dev/hdXY [boot parameter]
Enter your root partition for the parameter root=/dev/hdXY. It is listed in the file /etc/fstab. Enter additional options for the setting [boot parameter], which should be used during booting. The configuration files could look like this:
DEFAULT linux
LABEL linux
KERNEL linux
APPEND initrd=initrd root=/dev/hda7 hdd=ide-scsi
13.The following command (entered at a command prompt) then creates an ISO-9660 file system for the CD.
14.mkisofs -o /tmp/bootcd.iso -b isolinux.bin -c boot.cat
15. -no-emul-boot -boot-load-size 4
16. -boot-info-table /tmp/CDroot
The complete command must be entered as one line.
17.The file /tmp/bootcd.iso can be written to CD after that with graphical CD writing applications, like K3b, or at a command prompt with cdrecord -v speed=2 dev=0,0,0 /tmp/bootcd.iso -eject. Change the parameter dev=0,0,0 according to the SCSI ID of the writer. Determine it with the command cdrecord -scanbus. Also refer to the man page cdrecord.
18.Test the boot CD. Reboot the computer to verify whether the Linux system starts correctly from the CD.

[火星人 ] 個人經驗點滴已經有797次圍觀

http://coctec.com/docs/linux/show-post-117144.html