顯示包含「Linux」標籤的文章。顯示所有文章
顯示包含「Linux」標籤的文章。顯示所有文章

7.17.2012

Linux Network Interface Bonding

環境:
OS:CentOS 6.3

假設:
IP Address:10.0.10.11
Netmask:255.255.255.0
Gateway:10.0.10.1
實體網路介面名稱:eth0 eth1

設定網路介面(Network Interface):

bond0 (Bonding Interface):
建立檔案 "ifcfg-bond0" 在 "/etc/sysconfig/network-scripts"
nano /etc/sysconfig/network-scripts/ifcfg-bond0
加入以下設定
DEVICE=bond0
BONDING_OPTS="mode=1 miimon=100"
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.0.10.11
NETMASK=255.255.255.0
GATEWAY=10.0.10.1
TYPE=Unknown
IPV6INIT=no
* mode 的設定請參考下面 (bond mode) 的參考連結

eth0 (實體網路介面):
修改檔案 "/etc/sysconfig/network-scripts/ifcfg-eth0"
nano /etc/sysconfig/network-scripts/ifcfg-eth0
改為以下設定
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

eth1 (實體網路介面):
修改檔案 "/etc/sysconfig/network-scripts/ifcfg-eth1"
nano /etc/sysconfig/network-scripts/ifcfg-eth1
改為以下設定
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

設定bond0介面模組:

建立檔案 "bonding.conf" 在 "/etc/modprobe.d"
nano /etc/modprobe.d/bonding.conf
加入以下設定
alias bond0 bonding
設定網路服務:

CentOS 6 新增了 "NetworkManager" 服務去管理網路介面卡但此服務會影響 bonding 的設定的所以需要停了它,請執行以下指令以確保啟動後不會啟動
chkconfig NetworkManager off
並確定 "network" 服務啟動後會自動啟動,可執行以下指令 chkconfig network on
完成後請重新啟動電腦即可





參考 - dominic16y.world.edoors.com (bond mode)
參考 - www.newitperson.com
參考 - www.360doc.com

7.06.2012

Amanda 基礎設定步驟

服務器環境:
OS:CentOS 6.2
Amanda 版本:2.6.1p2-7
IP 地址:192.168.1.11
主機名稱:backup.yourdomain.com
備份的目的地:/backup/


客戶端環境:
OS:CentOS 5.8
Amanda版本:2.5.0p2-9
IP 地址:192.168.1.31
主機名稱:data.yourdomain.com


*注意
服務器及客戶端的Amanda版本是不同的,而Amanda的預設使用者名稱也是不同的。


安裝Amanda到服務器及客戶端:
以Yum安裝yum -y install amanda*


客戶端設置:
  1. 設置 /etc/hosts 檔案
    在檔案加入服務器的IP地址及主機名稱。加入的設定如下
    192.168.0.11 backup backup.yourdomain.com            IP地址       主機名      主機完整名稱(FQDN)
  2. 設置 /var/lib/amanda.amandahost/.amandahosts
    ( 在 "amandahosts" 前是有一個點的,這檔案是Amanda專用的主機名稱對應表)

    在檔案加入服務器的名稱及服務器上的使用都名稱(下面會再提及的)。加入的設定如下
    backup         amandabackup 服務器主機名    服務器上Amanda的使用者名稱
  3. 設定 Amanda 為啟動狀態
    chkconfig amanda on
  4. 啟動 Amanda
    /etc/init.d/xinetd reload
服務器設置:
  1. 設置 /etc/hosts 檔案
    在檔案加入客戶端的IP地址及主機名稱。加入的設定如下
    192.168.0.31   data    data.yourdomain.com        IP地址            主機名       主機完整名稱(FQDN)
  2. 建立備份設定
    1. 在 /etc/amanda/ 內建立備份策略目錄,假設策略名稱是 "DataBak"
      mkdir -p /etc/amanda/DataBak
    2. 建立設定檔 amanda.conf 並放在 DataBak 內,把以下內容貼上
      org             "DataBak"            #對應策略名稱
      mailto          "admin@yourdomain.com"
      dumpuser        "amandabackup"       #執行Amanda的使用者名稱
      dumpcycle       7days                #此策略的備份周期
      runspercycle    5                    #此策略在備份周期內的執行次數(對應於Cronjob的設定)
      tapecycle       6 tapes              #tapecycle 需大於 runspercycle

      labelstr        "^DataBak-[0-9][0-9]*$"
      logdir          "/var/log/amanda"
      tpchanger       "chg-disk"
      changerfile     "/etc/amanda/DataBak/changer"
      infofile        "/etc/amanda/DataBak/curinfo"
      indexdir        "/etc/amanda/DataBak/index"
      tapedev         "file:/backup/DataBak"
      tapetype        HARD-DISK            #這裏的 HARD-DISK 是對應於下面的設定

      define dumptype DataBackup {         #"DataBackup" 是 dumptype 的名稱,在下面會用到
              program "GNUTAR"
              comment "Server Backup"
              compress none
              index   yes
              priority low
      }

      define tapetype HARD-DISK {
              comment "disk-to-disk"
              length  10gbytes             #每一個Slot容量是10GB
      }
    3. 建立備份資料的設定檔 disklist 並放在 DataBak 內,內容如下
        data           share/documents      DataBackup 客戶端的主機名稱   在客戶端要備份的資料路徑   dumptype名稱
    4. 更改剛所建立的檔案的權限
      chown -R amandabackup:disk /etc/amanda/DataBak
    5. 建立策略的儲存目錄for ((i=1;i<=6;i++));do mkdir -p /backup/DataBak/slot$i; done;紅色 6 是對應 amanda.conf 中的 tapecycle
    6. 更改儲存目錄內的檔案權限chown -R amandabackup:disk /backup/DataBak
    7. 建立 tape slot 文件
      su - amandabackup                     #改變登入為 amandabackup
      for ((i=1;i<=6;i++));do amlabel DataBak DataBak-0$i slot $i; done;
      退出 amandabackup 請用 exit 指令(暫時不用退出)
    8. 檢查測試設定amcheck DataBak結果輸出應會如下Amanda Tape Server Host Check
      -----------------------------
      slot 6:read label `DataBak-06', date `X'.
      NOTE: skipping tape-writable test
      Tape DataBak-06 label ok
      NOTE: conf info dir /etc/amanda/DataBak/curinfo does not exist
      NOTE: it will be created on the next run.
      NOTE: index dir /etc/amanda/DataBak/index does not exist
      NOTE: it will be created on the next run.
      Server check took 1.449 seconds

      Amanda Backup Client Hosts Check
      --------------------------------
      Client check: 1 host checked in 0.096 seconds. 0 problems found.

      (brought to you by Amanda 2.6.1p2)
    9. 進行第一次備份的測amdump DataBak完成後你會收到電郵通知你備份的結果
  3. 如果一切正常可設定 cronjob,以amandabackup身份執行crontab -e加入以下設定35 0 * * 1-5 /usr/sbin/amdump DataBak以上設定了星期一至五凌晨12:35執行備份

12.14.2011

Linux 服務進程 (Daemons) 列表

服務 進程名稱 說明
abrt-ccpp The ABRT service that provides the C/C++ problems analyzer Website
abrt-oops The ABRT service that provides the kernel oopses analyzer Website
abrtd The ABRT daemon which runs under root as a background service Automatic Bug Reporting Tool Website
apcid Advanced Configuration and Power Interface 能源管理進程 Website
anacron anachronistic cron 常用於會關機的系統的排程服務,服務會基於設定而決定因關機而未有執行的排程會如何處理 Website
apmd Advanced Power Management 能源管理進程,正逐漸被 acpid 所取代
autofs Auto Mount File System 自動掛載服務 More
auditd Linux Auditing System 系統審核服務,可用於紀錄SELinux的事件作除錯之用
auditd Linux Auditing System 系統審核服務,可用於紀錄SELinux的事件作除錯之用
avahi-daemon
avahi-dnsconfd
Avahi 是一個基於zeroconf 協議的服務,類似mDNS的服務 Website
Bluetooth
hidd
pand
Bluetooth Daemon More
capi Common ISDN Application Programming Interface 如要連接ISDN設備才需要使用More
conman conmand daemon 支援多Console及多人同時使用,類似Remote Terminal Service More
cpuspeed CPU Speed power consumption management 用以控制CPU速度及能源消耗 More
crond CPU Speed power consumption management 基本排程服務 More
cups Common UNIX Printing Solution Linux的列印服務 More
dhcdbd DHcp Client D-Bus Daemon More
gpmd Mouse Daemon 在文字模式下可以用鼠標
hald Hardware Abstraction Layer Daemon 用於收集硬件及內核信息以供應一致的方式到系統其他的程序 More
hplipd HP Linux Imaging and Printing Daemon More
irda Infrared Data Association More
irqbalance Distributes hardware interrupts to the CPUs in symmetric processor 用於多處理器控制硬件中斷以提升系統效率及能源消耗,單處理器系統是沒有效果的More
kudzu Detect and Configure new or updated hardware 些服務只會在開機時搜索更新了的硬件並且設定該硬件More
lm_sensors System Static Monitoring Daemon 監察系統溫度,電壓及風扇轉速More
mcstrans SELinux Context Translation System Daemon More
mdmonitor
mdmpd
RAID data storage system More
messagebus D-BUS system-wide message bus daemon More
NetworkManager NetworkManager daemon 管理不同方式的網路連線More
nfsd NFS daemon More
nscd name service cache daemon More
oddjobd oddjob service More
pcscd PC/SC Smart Card Daemon More
portmap The portmapper daemon manages RPC connections 在NFS及NIS間轉換Port No.More
rdisc router discovery daemon More
restorecond SELinux daemon 些進程會監察檔案建立以確保檔案符合SELinux的政策More
rpcgssd
rpcidmapd
rpcsvcgssd
RPC Security and maps Daemon More
readahead_early
readahead_later
read a head daemon
setroubleshoot SELinux Troubleshooting Daemon More


對中文解釋有疑問請參考以下引用
Redhat

12.13.2011

在 CentOS 6.1 安裝 Virtual Box Guest Addition


環境:
虛擬機(VM Guest) : CentOS 6.1
虛擬主機(VM Host): Windows XP
VirtualBox Ver: 4.1.6


設定網路:(假設使用DHCP)
  1. vi /etc/sysconfig/network-scripts/ifcfg-eth0 (按 "i" 開始編輯模式)
  2. 修改 ONBOOT="no" => ONBOOT="yes"
  3. 加入 BOOTPROTO="dhcp"
  4. 保存 (按 ":qw")
  5. 重新啟動網路 ( /etc/init.d/network restart)
安裝X-Windows:

  1. yum -y groupinstall "X Window System"
  2. yum -y groupinstall "Desktop"


安裝VirtualBox Guest Addition:
  1. 安裝 虛擬機作業系統 (CentOS 6.1)
  2. 登入CentOS,執行以下指令
    • yum -y install kernel-devel
    • yum -y groupinstall "development tools" 
  3. 重新啟動系統 (指令: reboot)
  4. 插入 "Guest Additions" (按虛擬機的工具列 Devices -> "Install Guest Additions..."
  5. 在 CentOS 進入 Media 目錄 (指令: cd /media)
  6. 建立目錄 DVD (指令: mkdir DVD),如果有可以跳過或有其他目錄名也可
  7. 掛載 "Install Guest Additons" 到 DVD (指令: mount /dev/cdrom /media/DVD)
  8. 進入 DVD (指令: cd /media/DVD)
  9. 執行安裝 (指令: VBoxLinuxAdditions.run)
  10. 如一切順利不會出現 Fail 

11.30.2011

Linux 指令集

列出系統已開的端口是那個服務 / 程序打開的
e.g.: lsof -Pni
Output: 

COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd      2213  root    3r  IPv6  10236      0t0  TCP *:22 (LISTEN)
sshd      2213  root    4u  IPv4  10238      0t0  TCP *:22 (LISTEN)
avahi-dae 2313 avahi   13u  IPv4  11402      0t0  UDP *:5353
avahi-dae 2313 avahi   14u  IPv6  11403      0t0  UDP *:5353
avahi-dae 2313 avahi   15u  IPv4  11404      0t0  UDP *:39899
avahi-dae 2313 avahi   16u  IPv6  11405      0t0  UDP *:37739
vsftpd    3384  root    3u  IPv4  13849      0t0  TCP *:21 (LISTEN)
cupsd     3428  root    8u  IPv6  15201      0t0  TCP [::1]:631 (LISTEN)
cupsd     3428  root    9u  IPv4  15202      0t0  TCP 127.0.0.1:631 (LISTEN)

-P: 停止把端口號轉為服務名稱
-n: 停止把IP地址轉為域名
-i: 只列出任何與IP地址有關連的服務/程序

reference

把 Unix timestamp 轉為可讀日期
e.g.: date -d @1305082453
Output: Wed May 11 10:54:13 HKT 2011

reference

下載 FTP 服務器內的所有檔案
Command: wget -r ftp://username:password@ftp.mydomain.com:port/path/directory/
e.g.: wget -r ftp://username:password@ftp.mydomain.com:21/home/staff/

reference

把 man page 轉為純文字檔
Command: man sshd_config|col -bx  > sshd_config.man

reference

把Faxstat 固定顯示
Command: watch -n 1 faxstat -s

reference

4.28.2011

VirtualBox Usage Note

Environment:
OS: CentOS 5.6
VirtualBox Ver: 4.0-4.0.6 (RPM)
VM Name: Windows XP


Assumption:
  • You have installed Development Tools and Library (yum -y groupinstall "Development Library" "Development Tools" 
  • You have installed kernel-devel package (yum -y install kernel-devel), please make sure the installed kernel-devel version is matched with your kernel version.
Install Kernel Modules

  1. "/etc/init.d/vboxdrv setup" #Please make sure you have installed kernel development rpms



Console Start VM:

  1. VBoxManage startvm 'CentOS-5.6' (optional: --type headless , this option make VM Guest run safer in background)
Console Stop VM:
  1. Power off -- VM guest will shutdown immediately, just like pressed power button
    command: VBoxManage controlvm 'CentOS-5.6' poweroff
  2. Save State -- System will save the VM guest State in "~/VirtualBox VMs/Windows XP/Snapshots", if you want to backup the VM guest please make sure you have backup the whole 'Windows XP' directory. In this state you won't allow change the VM guest settings.command: VBoxManage controlvm 'CentOS-5.6' savestate
  3. ACPI off -- System will send ACPI poweroff signal to VM guest (You must install VBox Guest Additions Package)
    command: VBoxManage controlvm 'CentOS-5.6' acpipowerbutton

    If you found that VM Guest can't shutdown, please make sure the x-windows/gnome is not running. (Actually "gnome-power-manager" is not running.)

    OR
    Make sure you VM Guest can receive shutdown signal (you can check /var/log/acpid), Run 
    "nano /etc/acpi/events/power.conf" and change action to "action=/sbin/shutdown -h now" then try again. (The acpi config file path is used for CentOS only)

Install Virtual Box Guest Additions Package
  1. Please make sure you have installed all package which described in assumption section.
  2. Mount Guest Additions Disc ( Press Devices -> Install Guest Additions or Host + D )
  3. In VM guest, mount /dev/cdrom /media
  4. cd /media
  5. ./VBoxLinuxAdditions.run
  6. reboot (restart VM Guest)
  7. If it doesn't work please check the /var/log/vboxadd-install.log to find out what is the problem and run "/etc/inti.d/vboxadd setup" to reinstall the package
Remote Desktop Server Port

  1. Please download "VirtualBox Extension Packages" form VirtualBox website (Link)
  2. Add the Extension Pack to VirtualBox,  "File" -> "Preferences" -> "Extensions" -> "Add Package"
  3. Enable Remote Display, Stop VM -> Settings -> Display -> Remote Display -> tick "enable Server", enter server port (e.g. 3391)
  4. Config firewall enable prot 3391


Reference
Chinese Reference
Reference: Convert VDI <=> VMDK/VHD

4.19.2011

Build Samba RPM from Source (samba-3.5.8)

Environment:
OS: CentOS 5.6
Kernel: 2.6.18-238.5.1.el5
Unofficial RPM Build for RHEL link
  1. install development tools "yum -y groupinstall 'Development Tools' "
  2. Download Samba Source Link
  3. Extract source file (samba-3.5.8.tar.gz)
  4. cd amba-3.5.8/packaging/RHEL
  5. nano samba.spec
  6. Search the line "BuildRequires" update "keyutils-devel" to "keyutils-libs-devel"
  7. Search the line "cc="$cc" CLFLAGS= [..skipped..]   ./configure" and add this new line "--with-cifsumount \"
  8. run "sh makerpms.sh &>/root/samba.build.log"
  9. When the end of the process has shown "error: Installed (but unpackaged) file(s) found:", please add those mentioned file in the "samba.spec" file at the end of "%files" section, and then repeat step 8.
  10. Now the new rpm files should built in "/usr/src/redhat/RPMS/i386"
  11. You need to uninstall the installed samba please run "rpm -e samba-common samba samba-client --nodeps"
  12. And you need to uninstall some dependent files, please run "rpm -e libsmbclient libtdb libtalloc --nodeps"
  13. Install new the samba rpms run "rpm -ivh samba*"

Setup Netatalk for Cent OS 5.6 (Guest Login ONLY)

Environment:
OS: Cent OS 5.6
Kernel: 2.6.18-238.5.1

Assumption:
You had installed a support netatalk kernel.

  1. Download the Netatalk RPM file (Link - netatalk-2.0.5-1.el5.i386.rpm).
  2. rpm -ivh netatalk-2.0.5-1.el5.i386.rpm
  3. Update /etc/atalk/netatalk.confATALK_MAC_CHARSET='UTF8-MAC'
    ATALKD_RUN=no
    PAPD_RUN=no
    CNID_METAD_RUN=yes
    AFPD_RUN=yes
    TIMELORD_RUN=no
    A2BOOT_RUN=no
  4. Append the below line to  /etc/atalk/afpd.conf "Mac Share" -uamlist uams_guest.so -tcp -noddp
  5. Append the below line to /etc/atalk/AppleVolumes.default/home/public    "Share" options:usedots,invisibledots,noadouble ea:none
  6. Create a new file with below content /etc/avahi/services/afpd.service
    <?xml version="1.0" standalone='no'?><!--*-nxml-*-->
    <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
    <service-group>
        <name replace-wildcards="yes">%h Drive</name>
        <service>
            <type>_afpovertcp._tcp</type>
            <port>548</port>
        </service>
        <service>
            <type>_device-info._tcp</type>
            <port>0</port>
            <txt-record>model=Xserve</txt-record>
        </service>
    </service-group>
  7. run /etc/init.d/avahi-daemon start
  8. run /etc/init.d/atalk start
  9. If you share the same folder with samba please update your smb.conf with below options
    veto files = /._*/.DS_*/.AppleDB/.AppleDouble/.AppleDesktop/Network Trash Folder/TheFindByContentFolder/TheVolumeSettingsFolder/Temporary Items/.TemporaryItems/.VolumeIcon.icns/Icon?/.FBCIndex/.FBCLockFolder/
    delete veto files = Yes
    vfs objects = netatalk
Netatalk Setup Reference
Netatalk Setup Reference

Recomplie Kernel CentOS 5.6 (From RPM-Source)

Environment:
OS: CentOS5.6
Kernel: 2.6.18-238.5.1-el5

  1. Download Kernel RPM Source from CentOS website link
  2. Install RPMS file "rpm -ivh kernel-2.6.18-238.5.1.el5.src.rpm"
    (many warning "user mockbuild does not exist is normal")
  3. cd /usr/src/redhat/SPECS
  4. rpmbuild -bp kernel-2.6.spec   #Run the patch for kernel source
  5. cd /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i386
  6. nano Makefile #Update "EXTRAVERSION = -238.netatalk" (Optional)
  7. make menuconfig
  8. Update your config e.g. Networking -> Networking options -> Appletalk protocol support
  9. make all
  10. make rpm        #RPM fine will stored in "/usr/src/redhat/RPMS/i386/"
  11. rpm -ivh kernel-2.6.18-238.5.1.netatalk.rpm    #install rpm kernel
  12. /sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install 2.6.18-238.netatalk    #Update Grub config and create initrd image, "-238.netatalk" is the EXTRAVERSION setting from the SPECS file, which is part of kernel modules directory name, you can check the /lib/modules/ to find correct directory name.

4.14.2011

Setup Firewall Builder to use Private Key

Environment:
OS: CentOS 5.6
Firewall Builder Version: 4.1.3

Assumption:
Use Root to install Firewall Builder
Use GNOME to setup firewall rules and run by root
The user name that use for Firewall Builder is "fwUser", please create it, assign a password for it and generate SSH key for it.(Generate SSH Key please refer to other instruction for details)
SSH Private stored in "[HOME FOLDER]/cert"
SSH Private key file name is "fwUser.key"
  1. Install Firewall Builder from RPM files
  2. Create Firewall Rules
  3. Setup SSH Private Key, right click firewall name (under Firewalls folder), click "Edit"
  4. Firewall Properties dialog will show under the rules panel, click "Firewall Settings"
  5. Click "Installer" tab, update user name "fwUser", add "-i ~/cert/fwUser.key" to "Additional command line parameters for ssh" and "Additional command line parameters for scp"
  6. Save Firewall Builder, store the file in /etc/firewall, make sure user "fwUser" have read and write permission for this folder and files.
  7. Update /etc/sudoers, add "%fwUser ALL = /etc/firewall/[FILENAME].fw"
  8. Goto Firewall Builder click "Install"(on Toolbar)
  9. At "Install options" page enter Password, then click "Install", Finish
Change SSH Port Number
  1. Firewall Properties dialog will show under the rules panel, click "Firewall Settings"
  2. add "-p 23" to "Additional command line parameters for ssh" (Lowercase)
  3. add "-P 23" to "Additional command line parameters for scp" (Uppercase)