Board logo

標題: [資源分享] [分享] Linux技術心得 [打印本頁]

作者: 祐祐    時間: 2010-8-20 00:00     標題: [分享] Linux技術心得

Linux技術心得
        --------Collected or Written by Dandy

-------------------------------------------------------------------------------        
*用日期做檔案名稱
>touch file`date +%y%m%d`
>ls -al file*
-rw-r--r--   1 root     root            0 May 23 11:18 file020523
-------------------------------------------------------------------------------
*監測封包tcpdump
tcpdump -i eth1 -ns 1500 -w /tmp/dhcp.dump
-------------------------------------------------------------------------------
*解讀封包
tcpdump -r /tmp/dhcp.dump
-------------------------------------------------------------------------------
* 做一個批次處理的檔,目地在重建/home/下的user
cat /etc/passwd | awk -F ’:’ ’{printf("mkdir /home/%s \n", $1);}’ > 檔名1
-------------------------------------------------------------------------------
*增快DNS正查速度(利用DNS forwarder)
修改 /etc/named.conf檔, 其中有個
options {..........的敘述, 在此敘述的大括號中加入以下三行,
forwarders {
168.95.192.1;
};
-------------------------------------------------------------------------------
*初始化 Squid 快取
squid -f /etc/squid/squid.conf -z
-------------------------------------------------------------------------------
*mysql 指令
登入->mysql -u root -p
新開資料庫->mysqladmin -u root -p create data_name
新開資料庫->mysqladmin -u root -p drop data_name
-------------------------------------------------------------------------------
*RH80的apache預設字元為西歐字元,欲改繁體中文

修改/etc/httpd/conf/httpd.conf
將AddDefaultCharset ISO-8859-1修改如下
AddDefaultCharst Big5
語言順序
LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv tw
改成
LanguagePriority tw en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv
-------------------------------------------------------------------------------
*系統校時
ntpdate ntp.nasa.gov        //校時
clock -w                  //寫入硬體
-------------------------------------------------------------------------------
在 CLE 1.0 寫程式,由於bash的bug,會使得output若不跳到下一行就會消失,請加讓\n
#include <stdio.h>
int main() {
   printf("hello world");
改成 printf("hello world\n");

-------------------------------------------------------------------------------
*反向輸出--tac
反向列出系統登入者
last|tac
-------------------------------------------------------------------------------
*/var/log有些記錄檔無法自動更換,使檔案變得太大
=>使用logrotate
=>編輯/etc/logrotate.d/syslog,加入此檔名,例如procmail.log
-------------------------------------------------------------------------------
*設定logrotate使/var/log/procmail.log能每天換一次並將記錄email出來

/var/log/procmail.log {
rotate 7
daily
prerotate
mutt -a /var/log/procmail.log -s log`date +%y%m%d` dandy@mail.deanshoes.com </dev/null
endscript
create 0666 root root
}
-------------------------------------------------------------------------------
*lspci -v 查看硬體晶片

-------------------------------------------------------------------------------
*時鐘分為系統時鐘和硬體時鐘,在啟動時,硬體時鐘會去讀取系統時鐘的設置,然後系統時鐘就會獨立于硬體運作.

查看時鐘:
date

設置系統時鐘:
date 091713272004.30
格式:
date 月日時分年.秒

查看硬體時鐘:
hwclock或clock,命令差不多.

設置硬體時鐘:
hwclock --set --date="04/11/2004 23:16:25"
或clock --set --date="04/11/2004 23:16:25"

-------------------------------------------------------------------------------
arp 查看本地的MAC位址

-------------------------------------------------------------------------------
ifconfig eth0 210.75.32.28 netmask 255.255.255.128 broadcast 210.75.32.127
給eth0界面加入IP位址及netmask

-------------------------------------------------------------------------------
ifconfig eth0 down 關閉eth0界面
ifconfig eth0 up 打開eth0界面

-------------------------------------------------------------------------------
FTP命令:
ls:列出遠程機上改變工作目錄
cd:在遠程機上改變工作目錄
lcd:在本地機改變工作目錄
close:終止當前的ftp對話
get(mget):從遠程伺服器指定文件到本機
put(mput):從本機上傳到遠程伺服器
bye:離開
-------------------------------------------------------------------------------
more /root/.bash_history 查看歷史命令
-------------------------------------------------------------------------------
在一張網卡上虛擬多個IP位址:
ifconfig eth0:0 192.168.0.253 netmask 255.255.255.0
ifconfig eth0:1 192.168.0.252 netmask 255.255.255.0

-------------------------------------------------------------------------------
把iso製作成虛擬光驅 dd if=/dev/cdrom of=jin.iso bs=2048

-------------------------------------------------------------------------------
env命令用來查看環境變量
-------------------------------------------------------------------------------
du -h 顯示本目錄的文件及各文件的大小
du -sh 顯示目錄占硬碟容量的大小

-------------------------------------------------------------------------------
Linux下如何搜尋文件?
**在當前目錄下搜尋文件明為*.sql的文件:
--find . -name "*.sql"
**搜尋大于100M的文件:
find . -size +100000
**搜尋含有"china" 的文件:
find . -name "*" -exec grep -l "china" {}\
**搜尋並刪除tmp*的文件:
find . -name "tmp* -exec rm {}\
**搜尋7天沒有被修改過的文件:
find . -mtime +7
搜尋目錄並更改屬性為755
--find ./ -type d -exec chmod 755 {} \;

-------------------------------------------------------------------------------
/boot/grub/grub.conf
GRUB 配置
-------------------------------------------------------------------------------
/boot/module-info-*
內核驅動訊息
-------------------------------------------------------------------------------
Module information for the Linux kernel
/boot/System.map-*
系統列表
-------------------------------------------------------------------------------
Map of the Linux kernel
/boot/vmlinuz-*
內核
Linux kernel
-------------------------------------------------------------------------------
/etc/aliases
郵件別名
Mail aliases
-------------------------------------------------------------------------------
/etc/at.deny
被禁止的用戶
User IDs of users forbidden to use the at command
-------------------------------------------------------------------------------
/etc/auto.master
自動mount
Configuration file for the autofs daemon, which automatically mounts filesystems
-------------------------------------------------------------------------------
/etc/auto.misc
Automounter map file
-------------------------------------------------------------------------------
/etc/crontab
系統日誌
System cron file
-------------------------------------------------------------------------------
/etc/cron.daily/*
安全日誌
Daily cron jobs
-------------------------------------------------------------------------------
/etc/cron.hourly/*
時誌
Hourly cron jobs
-------------------------------------------------------------------------------
/etc/cron.monthly/*
月誌
Monthly cron jobs
-------------------------------------------------------------------------------
/etc/cron.weekly/*
周誌
Weekly cron jobs
-------------------------------------------------------------------------------
/etc/filesystems
支持的文件系統格式
Supported filesystem types
-------------------------------------------------------------------------------
/etc/fstab
文件系統mount
Filesystems mounted or available for mounting
-------------------------------------------------------------------------------
/etc/group
系統組定義
System group definitions
-------------------------------------------------------------------------------
/etc/host.conf
Resolver configuration file
-------------------------------------------------------------------------------
/etc/hosts
域名IP
Map of IP numbers to hostnames
-------------------------------------------------------------------------------
/etc/hosts.allow
允許的IP
ALL : 1.1.1.1
ALL : 2.2.2.* : deny
sendmail : 3.3.3.3 : deny
ipop3d : *
sendmail : ALL : allow
in.ftpd : *
Hosts allowed to access Internet services
-------------------------------------------------------------------------------
/etc/hosts.deny
禁止的IP
ALL:*
Hosts forbidden to access Internet services
-------------------------------------------------------------------------------
/etc/httpd/conf/*
Apache配置文件
Apache configuration files
-------------------------------------------------------------------------------
/etc/httpd/httpd.conf
Web伺服器配置文件
Web server configuration file
-------------------------------------------------------------------------------
/etc/initlog.conf
登陸配置文件
Logging configuration file
-------------------------------------------------------------------------------
/etc/inittab
Configuration for the init daemon, which controls executing processes
-------------------------------------------------------------------------------
/etc/issue
Linux kernel and distribution version

-------------------------------------------------------------------------------
查詢設定檔有無用# Mark起來
sed 's/#.*$//' xxx.conf | grep -v '^$'
-------------------------------------------------------------------------------
查看snmpd的運作
snmpwalk localhost -c public -v 1
------------------------------------------------------------------------------
打開RHEL 3.0的MRTG,從外部可以瀏覽
/etc/httpd/conf.d/mrtg.conf

<Location /mrtg>
    Order deny,allow
    Deny from all
#    Allow from localhost
     Allow from all
</Location>

-------------------------------------------------------------------------------
RHEL 3.0的postfix使用sasl
=>需將/usr/lib/sasl2/smtpd.conf copy到/usr/lib/sasl

-------------------------------------------------------------------------------
將man的結果輸出成文字檔
=>man foo| col -b >text

-------------------------------------------------------------------------------
RedHat AS3 中有 mysql 選項可以安裝,不過 AS3 卻由於商業化因素而缺 mysql server 相關檔案,也就是說除非您是RHN註冊者,否則無法下載這個 RPM 的。
=>需自行下載SRPM來rebuild,在以下download:
http://ebrc.ntpu.edu.tw/~jeffher ... l-3.23.58-1.src.rpm

rpmbuild --rebuild mysql-3.23.58-1.src.rpm
接下來你會在 /var/src/redhat/RPMS/i386 下找到五個包裝好的 RPM 檔,其中 mysql-server-3.23.58-1.rpm 就是您要補安裝的套件
rpm -Uvh /var/src/redhat/RPMS/i386/mysql-server-3.23.58-1.rpm

立即啟動 mysql daemon
=>service mysqld start

設定開機時啟動 mysql daemon
=>chkconfig mysqld on
-------------------------------------------------------------------------------
啟動phpMyAdmin注意事項
--開啟時發生以下錯誤:
Warning: mb_internal_encoding(): Unknown encoding "big5" in /var/www/html/phpMyAdmin/libraries/string.lib.php on line 29

==>修改var/www/html/phpMyAdmin/libraries/string.lib.php 的29行-->// mb_internal_encoding($GLOBALS['charset']);


-------------------------------------------------------------------------------
使用Apache Server的 mod_auth安全模組
--1.修改/etc/httpd/conf/httpd.conf,加入以下:
<Directory /var/www/html/phpmyadmin>
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

  2.1.基本密碼Basic
  在/var/www/html/phpmyadmin裡,create一個.htaccess檔案,加入以下:

AuthName "用戶驗證,請輸入兩次!"
AuthType Basic
AuthUserFile /var/www/html/phpmyadmin/.htpasswd
require valid-user

  建立帳號:
htpasswd -c  /var/www/html/phpmyadmin/.htpasswd admin
================================
2.2安全密碼Digest
在/var/www/html/phpmyadmin裡,create一個.htaccess檔案,加入以下:

AuthName "用戶驗證,請輸入兩次!"
AuthType Digest
AuthDigestFile /var/www/html/phpmyadmin/.htpasswd
require valid-user

  建立帳號:
htdigest -c   /var/www/html/phpmyadmin/.htpasswd digest admin

-------------------------------------------------------------------------------
解壓多個zip壓縮檔
==>ls -al *.zip|xargs -n 1 unzip

[ Last edited by hrsenshen on 2005-4-5 at 06:54 AM ]




歡迎光臨 Queer01 (http://2fwww.queer01.com/) Powered by Discuz! 7.0.0