MySQL的語法 (無大小寫之分)
不登入mysql 所使用指令
#建立及刪去資料庫
mysqladmin -u root create test -p
mysqladmin -u root drop test -p
#顯示資料庫
mysqlshow -u root -p
#顯示table
mysqlshow dataname
#顯示欄位
mysqlshow dataname table
#檢查權限之命令
mysqlaccess localhost user mysql -U root -P abc123 <==檢查user帳號的權限
mysqlaccess localhost caitl -U root -P <==檢查towns帳號的權限,會要求打入root 密碼
#登入mysql指令
mysql -u root -p
mysql -h 遠瑞IP -u root -p
#mysql 登出中斷 (二種方式)
mysql> quit;
按Control-D
Mysql-CLI (mysql command line)
#顯示所有 MySQL 資料庫
mysql> show databases;
#顯示該資料庫資料表
mysql> show tables;
#顯示 data 資料表的欄位資訊
mysql> show COLUMNS from table_name;
#顯示系統狀態(詳細)
mysql> show status;
#顯示系統狀態(簡單)
mysql> status;
#顯示連線的狀態
mysql> show table status;
#顯示mysql系統設定及變數
mysql> show variables;
mysql> show variables like '%max%';
#顯示 process list
mysql> show processlist;
#顯示mysql所支持的不同權限有那些
mysql> show privileges;
#顯示表格格式類能
mysql> show table types;
#查看MySQL的版本
mysql> select version();
#顯示系統現在所有user的帳號連線資料
mysql> select * from mysql.user ;
mysql> select * from mysql.user \G;
#顯示系統現在所有 user及從某ip連db的權限
mysql> select user, host from mysql.user ;
#顯示目前登入使用者的當時所建立權限的語法
mysql> show GRANTS ;
#顯示 username 時下的 Grant 語法, 也可用此來做帳號備份.
mysql> show grants for username@localhost;
#顯示當初表格如何建立
mysql> show create table user;
#顯示表的结構
mysql> DESCRIBE MYTABLE;
#顯示innoDB存諸情況
mysql> show innodb status;
mysql> show logs; // 顯示BDB存储引擎的log日志
mysql> show warnings; //顯示最後一個執行的語句所產生的錯誤、警告和通知
mysql> show errors; // 只顯示最後一個執行语句所產生的錯誤
#建立 與 删除庫:
mysql> create database 資料庫名;
mysql> drop database 資料庫名;
#建表與刪表、清空與顯示表中記錄 :
mysql> use 資料庫名;
mysql> create table 表名(字段列表);
mysql> drop table 表名;
mysql> delete from 表名;
mysql> select * from 表名;
#刪除指定內容
mysql> DELETE * FROM 資料表名稱 WHERE 欄位名稱 = '要尋找的資料';
#尋找指定內容
mysql> SELECT * FROM 資料表名稱 WHERE 欄位名稱 = '要尋找的資料';
#檢查 phpmyadmin table 是否有日久損毀資料的現象
mysql> use phpmyadmin
mysql> show tables ;
mysql> CHECK TABLE `table_name1` , `table_name2` , `table_name3` ;
#修復 table
mysql> REPAIR TABLE `table_name1` , `table_name2` , `table_name3` ;
#重新讀取.更新記憶體上的資料
mysql> FLUSH PRIVILEGES ;
#命令的取消
#當命令輸入錯誤而又無法改變(多行語句情形)時,只要在分號出現前就可以用 c來取消該條命令
mysql> select
-> user()
-> c
mysql>
2012年4月5日 星期四
2012年3月29日 星期四
[Debian] 32bit Ram 2G 限制問題
OS : Debian 6.04-i386-32bit
RAM : 32G
問題 : Debian6.04-i386(32-bit)版不支援 RAM 4G以上,只呈現2G
解決方法:
#ps -ef
# apt-get install linux-image-2.6-686-bigmem
#reboot
參考網頁 : http://serverfault.com/questions/25366/linux-only-detects-2gb-of-ram-with-4-installed-i386-debian-lenny
RAM : 32G
問題 : Debian6.04-i386(32-bit)版不支援 RAM 4G以上,只呈現2G
解決方法:
#ps -ef
# apt-get install linux-image-2.6-686-bigmem
#reboot
參考網頁 : http://serverfault.com/questions/25366/linux-only-detects-2gb-of-ram-with-4-installed-i386-debian-lenny
[MYSQL] -權限相關設定
# 備份
mysqldump -u root -p mysql > /tmp/fifimysql.sql
或 tar low data 方式
a. 先停止 mysql /etc/init.d/mysql stop
b. 下達指令 tar xxx.tar.gz 資料庫名稱
或 gzip
mysqldump -u root -p fifitest | gzip - > fifitest.gz
# 還原
mysql -u root -p fifitest < fifimysql.sql
或 zip
zcat fifitest.gz | mysql -u root -p fifitest
# cli 模式 秀出所有資料庫 跟 指定資料庫
mysqlshow -u root -p
mysqlshow -u root -p fifitest db
# 進入 Mysql cli 模式 ( command line )
mysql -u root -p
# 建立資料庫
mysql> create database `fifitest`;
# 秀資料庫
mysql> show databases ;
# 離開資料庫
mysql> quit ;
# mysqlshow -u root -p fifitest db
透過 phpmyadmin 操作後, 會有 mysql cli 模式指令
# 建立用戶test123 , 宣告密碼 111
CREATE USER 'test123'@'localhost' IDENTIFIED BY '111';
# 宣告test123 這各身分在 localhost 可以做的權限
GRANT USAGE ON * . * TO 'test123'@'localhost' IDENTIFIED BY '111' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
# 宣告 test123 再, localhost 這一台裡面對於 fifitest 資料庫 , 有所有權限
GRANT ALL PRIVILEGES ON `fifitest` . * TO 'test123'@'localhost';
# 新增宣告 test123 在 localhost 這台機器上 , 對於 123 這各資料庫 , 有四種權限
GRANT SELECT , INSERT , UPDATE , DELETE ON `123` . * TO 'test123'@'localhost';
# 移除所有權限 , test123 在 localhost 這台機器上 , 對於 123 這各資料庫
REVOKE ALL PRIVILEGES ON `123` . * FROM 'test123'@'localhost';
# 再宣告
GRANT SELECT , INSERT , UPDATE ON `123` . * TO 'test123'@'localhost';
# 檢查 table
use 哪各DB
CHECK TABLE `pma_bookmark` , `pma_column_info` , `pma_designer_coords` , `pma_history` , `pma_pdf_pages` , `pma_relation` , `pma_table_coords` , `pma_table_info` , `pma_tracking`
# 修復 table
REPAIR TABLE `pma_bookmark` , `pma_column_info` , `pma_designer_coords` , `pma_history` , `pma_pdf_pages` , `pma_relation` , `pma_table_coords` , `pma_table_info` , `pma_tracking`
use 哪各DB
CHECK TABLE `pma_bookmark` , `pma_column_info` , `pma_designer_coords` , `pma_history` , `pma_pdf_pages` , `pma_relation` , `pma_table_coords` , `pma_table_info` , `pma_tracking`
# 修復 table
REPAIR TABLE `pma_bookmark` , `pma_column_info` , `pma_designer_coords` , `pma_history` , `pma_pdf_pages` , `pma_relation` , `pma_table_coords` , `pma_table_info` , `pma_tracking`
2012年3月15日 星期四
[ How-To] ESXI5 GhettoVCB 備份還原(linux 版)
測試環境
新 HOST OS : ESXI5
使用套件 : pietty0327、ghettoVCB、ghettoVCB-restore.sh
使用需求: 需使用ghettoVCB.sh備份檔(還原格式同原本備份格式)
能SSH連線訪問的到該台主機並有足夠的空間,再進行還原。
1、使用 pietty SSH 進入 ESXI5 主機後,上傳ghettoVCB.tar.gz 及 ghettoVCB作出的備份檔
2、查看ghettoVCB-restore.sh使用到的參數
OPTIONS:
-c VM backup list (要還原備份的列表)
-l File ot output logging (指定LOG所儲存的路徑)
-d Dryrun/Debug Info [1|2] (可用來測試或是Debug還原看是否有誤)
還原 清單(vms_to_restore)上的虛擬機
#./ghettoVCB-restore.sh -c vms_to_restore
還原 清單(vms_to_restore)上的虛擬機,並指定 LOG 暫存路徑
#./ghettoVCB-restore.sh -c vms_to_restore -l /tmp/ghettoVCB-restore.log
設定好vms_to_restore後,可以使用Dryrun/Debug來測試看看腳本和vms_to_restore是否有問題。
#./ghettoVCB-restore.sh -c vms_to_restore -d 1
#./ghettoVCB-restore.sh -c vms_to_restore -d 2
3、建立還原使用的list
# vi vms_to_restore
"/vmfs/volumes/datastore1/test123/Guest01-2012-01-11_23-48-35;/vmfs/volumes/datastore1;3"
# " VM備份檔所在地的完整路徑 ; 恢復後的VM要存放的完整路徑 ; 設定恢復硬碟的格式"
注意 : 此list請使用在ESX或ESX(i)主機上。請勿用在non-Linux/UNIX系統上,避免特殊符號影響導致腳本錯誤。
格式代號 格式名稱
1 = zeroedthick
2 = 2gbsparse
3 = thin
4 = eagerzeroedthick
4、還原完成後請開啟VMware vSphere Client,看VM已經自己掛上了,接下來請開啟VM 測試是能正常開機運作。
5、在還原後第一次開啟時會出現詢問說此VM是怎麼來的,請選[I copied it],如果VM開啟正常,請將VM關起來後和一般正常的VM相比對,若沒有差異的 即是還原備份完成 。
參考網站 : FAQ-BOOK VMware esxi 備份還原ghettoVCB-restore.sh
FAQ-BOOK VMware ESX(i)虛擬磁碟格式介紹
新 HOST OS : ESXI5
使用套件 : pietty0327、ghettoVCB、ghettoVCB-restore.sh
使用需求: 需使用ghettoVCB.sh備份檔(還原格式同原本備份格式)
能SSH連線訪問的到該台主機並有足夠的空間,再進行還原。
1、使用 pietty SSH 進入 ESXI5 主機後,上傳ghettoVCB.tar.gz 及 ghettoVCB作出的備份檔
2、查看ghettoVCB-restore.sh使用到的參數
OPTIONS:
-c VM backup list (要還原備份的列表)
-l File ot output logging (指定LOG所儲存的路徑)
-d Dryrun/Debug Info [1|2] (可用來測試或是Debug還原看是否有誤)
還原 清單(vms_to_restore)上的虛擬機
#./ghettoVCB-restore.sh -c vms_to_restore
還原 清單(vms_to_restore)上的虛擬機,並指定 LOG 暫存路徑
#./ghettoVCB-restore.sh -c vms_to_restore -l /tmp/ghettoVCB-restore.log
設定好vms_to_restore後,可以使用Dryrun/Debug來測試看看腳本和vms_to_restore是否有問題。
#./ghettoVCB-restore.sh -c vms_to_restore -d 1
#./ghettoVCB-restore.sh -c vms_to_restore -d 2
3、建立還原使用的list
# vi vms_to_restore
"/vmfs/volumes/datastore1/test123/Guest01-2012-01-11_23-48-35;/vmfs/volumes/datastore1;3"
# " VM備份檔所在地的完整路徑 ; 恢復後的VM要存放的完整路徑 ; 設定恢復硬碟的格式"
注意 : 此list請使用在ESX或ESX(i)主機上。請勿用在non-Linux/UNIX系統上,避免特殊符號影響導致腳本錯誤。
格式代號 格式名稱
1 = zeroedthick
2 = 2gbsparse
3 = thin
4 = eagerzeroedthick
4、還原完成後請開啟VMware vSphere Client,看VM已經自己掛上了,接下來請開啟VM 測試是能正常開機運作。
5、在還原後第一次開啟時會出現詢問說此VM是怎麼來的,請選[I copied it],如果VM開啟正常,請將VM關起來後和一般正常的VM相比對,若沒有差異的 即是還原備份完成 。
參考網站 : FAQ-BOOK VMware esxi 備份還原ghettoVCB-restore.sh
FAQ-BOOK VMware ESX(i)虛擬磁碟格式介紹
[ Note ] ESX(i) 指令集
*查看版本
#vmware -v
列出 esx 裡知道的服務
#esxconfig-firewall -s
查看具體服務的情況
#esxcfg-firewall -q sshclinet
-sh: esxcfg-firewall: not found
重新啟動 vmware 服務
#service mgmt-vmware restart
*修改 root 的密碼
#passwd root
*列出你當前的虛擬交換機
#esxcfg-vswitch –l
查看控制台的設置
#esxcfg-vswif -1
*列出系統的網卡
#esxcfg-nics –l
實作案例 :
添加一個虛擬交換機,名字叫(internal)連接到兩塊物理網卡(重新啟動服務,vi就能看見了)
#esxcfg-vswitch -a vSwitch1
#esxcfg-vswitch -A internal vSwitch1
#esxcfg-vswitch -L vmnic1 vSwitch1
#esxcfg-vswitch -L vmnic2 vSwitch1
刪除交換機,(注意,別把控制台的交換機也刪了
#esxcfg-vswitch -D vSwitch1
刪除交換機上的網卡
#esxcfg-vswitch -u vmnic1 vswitch2
刪除 portgroup
#esxcfg-vswitch -D internel vswitch1
創建 vmkernel switch ,如果你希望使用 vmotion,iscsi 的這些功能,你必須創建(通常是不需要添加網關的)
#esxcfg-vswitch -l
#esxcfg-vswitch -a vswitch2
#esxcfg-vswitch -A "vm kernel" vswitch2
#esxcfg-vswitch -L vmnic3 vswitch2
#esxcfg-vmknic -a "vm kernel" -i 172.16.1.141 -n 255.255.252.0
#esxcfg-route 172.16.0.254
打開防火牆 ssh 端口
#esxcfg-firewall -e sshclient
#esxcfg-firewall -d sshclient
創建控制台
#esxcfg-vswitch -a vSwitch0
#esxcfg-vswitch -A "service console" vSwitch0
#esxcfg-vswitch -L vmnic0 vSwitch0
#esxcfg-vswif -a vswif0 -p "service console" -i 172.16.1.140 -n 255.255.252.0
添加 nas 設備(a 添加標籤,-o,是 nas 伺服器的名字或 ip,-s 是 nas 輸入的共用名稱字)
#esxcfg-nas -a isos -o nas.vmwar.cn -s isos
列出 nas 連接
#esxcfg-nas –l
強迫 esx 去連接 nas 服務器(用 esxcfg-nas -l 來看看結果)
#esxcfg-nas -r
#esxcfg-nas –l
連接 iscsi 設備(e:enable q:查詢 d:disable s:強迫搜索)
#esxcfg-swiscsi –e
設置 targetip
#vmkiscsi-tool -D -a 172.16.1.133 vmhba40
列出和 target 的連接
#vmkiscsi-tool -l -T vmhba40
列出當前的磁盤
#ls -l /vmfs/devices/disks
Esxcfg command help
Networking: Esxcfg-firewall Esxcfg-nics Esxcfg-vswitch Esxcfg-vswif Esxcfg-route Esxcfg-vmknic
Esxcfg-firewall
Description: Configures the service console firewall ports
Syntax: esxcfg-firewall <options>
Options:
-q Lists current settings
-q <service> Lists settings for the specified service
-q incoming|outgoing Lists settings for non-required incoming/outgoing ports
-s Lists known services
-l Loads current settings
-r Resets all options to defaults
-e <service> Allows specified service through the firewall (enables)
-d <service> Blocks specified service (disables)
-o <port, tcp|udp,in|out,name> Opens a port
-c <port, tcp|udp,in|out> Closes a port previously opened by –o
-h Displays command help
-allowincoming Allow all incoming ports
-allowoutgoing Allow all outgoing ports
-blockincoming Block all non-required incoming ports (default value)
-blockoutgoing Block all non-required outgoing ports (default value)
Default Services:
AAMClient Added by the vpxa RPM: Traffic between ESX Server hosts for VMware High Availability (HA) and EMC Autostart Manager – inbound and outbound TCP and UDP Ports 2050 – 5000 and 8042 – 8045
activeDirectorKerberos Active Directory Kerberos - outbound TCPs Port 88 and 464
CIMHttpServer First-party optional service: CIM HTTP Server - inbound TCP Port 5988
CIMHttpsServer First-party optional service: CIM HTTPS Server - inbound TCP Port 5989
CIMSLP First-party optional service: CIM SLP - inbound and outbound TCP and UDP Ports 427
commvaultDynamic Backup agent: Commvault dynamic – inbound and outbound TCP Ports 8600 – 8619
commvaultStatic Backup agent: Commvault static – inbound and outbound TCP Ports 8400 – 8403
ftpClient FTP client - outbound TCP Port 21
ftpServer FTP server - inbound TCP Port 21
kerberos Kerberos - outbound TCPs Port 88 and 749
LicenseClient FlexLM license server client - outbound TCP Ports 27000 and 27010
nfsClient NFS client - outbound TCP and UDP Ports 111 and 2049 (0 – 65535)
nisClient NIS client - outbound TCP and UDP Ports 111 (0 – 65535)
ntpClient NTP client - outbound UDP Port 123
smbClient SMB client - outbound TCP Ports 137 – 139 and 445
snmpd SNMP services - inbound TCP Port 161 and outbound TCP Port 162
sshClient SSH client - outbound TCP Port 22
sshServer SSH server - inbound TCP Port 22
swISCSIClient First-party optional service: Software iSCSI client - outbound TCP Port 3260
telnetClient NTP client - outbound TCP Port 23
TSM Backup agent: IBM Tivoli Storage Manager – inbound and outbound TCP Ports 1500
veritasBackupExec Backup agent: Veritas BackupExec – inbound TCP Ports 10000 – 10200
veritasNetBackup Backup agent: Veritas NetBackup – inbound TCP Ports 13720, 13732, 13734, and 13783
vncServer VNC server - Allow VNC sessions 0-64: inbound TCP Ports 5900 – 5964
vpxHeartbeats vpx heartbeats - outbound UDP Port 902
Note: You can configure your own services in the file /etc/vmware/firewall/services.xml
防火牆指令範例
esxcfg-firewall examples:
Enable ssh client connections from the Service Console:
# esxcfg-firewall -e sshClient
Disable the Samba client connections:
# esxcfg-firewall -d smbClient
Allow syslog outgoing traffic:
# esxcfg-firewall -o 514,udp,out,syslog
Turn off the firewall:
# esxcfg-firewall -allowIncoming
# esxcfg-firewall -allowOutgoing
Re-enable the firewall:
# esxcfg-firewall -blockIncoming
# esxcfg-firewall –blockOutgoing
Esxcfg-nics
Description: Prints a list of physical network adapters along with information on the driver, PCI device, and link state of each NIC. You can also use this command to control a physical network adapter’s speed and duplexing.
Syntax: esxcfg-nics <options> [nic]
Options:
-s <speed> Set the speed of this NIC to one of 10/100/1000/10000. Requires a NIC parameter.
-d <duplex> Set the duplex of this NIC to one of 'full' or 'half'. Requires a NIC parameter.
-a Set speed and duplex automatically. Requires a NIC parameter.
-l Print the list of NICs and their settings.
-r Restore the NICs configured speed/duplex settings. (Internal use only)
-h Displays command help
查看實際本機系統的網卡
esxcfg-nics examples:
Set the speed and duplex of a NIC (vmnic2) to 100/Full:
#esxcfg-nics -s 100 -d full vmnic2
Set the speed and duplex of a NIC (vmnic2) to auto-negotiate:
#esxcfg-nics -a vmnic2
#vmware -v
列出 esx 裡知道的服務
#esxconfig-firewall -s
查看具體服務的情況
#esxcfg-firewall -q sshclinet
-sh: esxcfg-firewall: not found
重新啟動 vmware 服務
#service mgmt-vmware restart
*修改 root 的密碼
#passwd root
*列出你當前的虛擬交換機
#esxcfg-vswitch –l
查看控制台的設置
#esxcfg-vswif -1
*列出系統的網卡
#esxcfg-nics –l
實作案例 :
添加一個虛擬交換機,名字叫(internal)連接到兩塊物理網卡(重新啟動服務,vi就能看見了)
#esxcfg-vswitch -a vSwitch1
#esxcfg-vswitch -A internal vSwitch1
#esxcfg-vswitch -L vmnic1 vSwitch1
#esxcfg-vswitch -L vmnic2 vSwitch1
刪除交換機,(注意,別把控制台的交換機也刪了
#esxcfg-vswitch -D vSwitch1
刪除交換機上的網卡
#esxcfg-vswitch -u vmnic1 vswitch2
刪除 portgroup
#esxcfg-vswitch -D internel vswitch1
創建 vmkernel switch ,如果你希望使用 vmotion,iscsi 的這些功能,你必須創建(通常是不需要添加網關的)
#esxcfg-vswitch -l
#esxcfg-vswitch -a vswitch2
#esxcfg-vswitch -A "vm kernel" vswitch2
#esxcfg-vswitch -L vmnic3 vswitch2
#esxcfg-vmknic -a "vm kernel" -i 172.16.1.141 -n 255.255.252.0
#esxcfg-route 172.16.0.254
打開防火牆 ssh 端口
#esxcfg-firewall -e sshclient
#esxcfg-firewall -d sshclient
創建控制台
#esxcfg-vswitch -a vSwitch0
#esxcfg-vswitch -A "service console" vSwitch0
#esxcfg-vswitch -L vmnic0 vSwitch0
#esxcfg-vswif -a vswif0 -p "service console" -i 172.16.1.140 -n 255.255.252.0
添加 nas 設備(a 添加標籤,-o,是 nas 伺服器的名字或 ip,-s 是 nas 輸入的共用名稱字)
#esxcfg-nas -a isos -o nas.vmwar.cn -s isos
列出 nas 連接
#esxcfg-nas –l
強迫 esx 去連接 nas 服務器(用 esxcfg-nas -l 來看看結果)
#esxcfg-nas -r
#esxcfg-nas –l
連接 iscsi 設備(e:enable q:查詢 d:disable s:強迫搜索)
#esxcfg-swiscsi –e
設置 targetip
#vmkiscsi-tool -D -a 172.16.1.133 vmhba40
列出和 target 的連接
#vmkiscsi-tool -l -T vmhba40
列出當前的磁盤
#ls -l /vmfs/devices/disks
Esxcfg command help
Networking: Esxcfg-firewall Esxcfg-nics Esxcfg-vswitch Esxcfg-vswif Esxcfg-route Esxcfg-vmknic
Esxcfg-firewall
Description: Configures the service console firewall ports
Syntax: esxcfg-firewall <options>
Options:
-q Lists current settings
-q <service> Lists settings for the specified service
-q incoming|outgoing Lists settings for non-required incoming/outgoing ports
-s Lists known services
-l Loads current settings
-r Resets all options to defaults
-e <service> Allows specified service through the firewall (enables)
-d <service> Blocks specified service (disables)
-o <port, tcp|udp,in|out,name> Opens a port
-c <port, tcp|udp,in|out> Closes a port previously opened by –o
-h Displays command help
-allowincoming Allow all incoming ports
-allowoutgoing Allow all outgoing ports
-blockincoming Block all non-required incoming ports (default value)
-blockoutgoing Block all non-required outgoing ports (default value)
Default Services:
AAMClient Added by the vpxa RPM: Traffic between ESX Server hosts for VMware High Availability (HA) and EMC Autostart Manager – inbound and outbound TCP and UDP Ports 2050 – 5000 and 8042 – 8045
activeDirectorKerberos Active Directory Kerberos - outbound TCPs Port 88 and 464
CIMHttpServer First-party optional service: CIM HTTP Server - inbound TCP Port 5988
CIMHttpsServer First-party optional service: CIM HTTPS Server - inbound TCP Port 5989
CIMSLP First-party optional service: CIM SLP - inbound and outbound TCP and UDP Ports 427
commvaultDynamic Backup agent: Commvault dynamic – inbound and outbound TCP Ports 8600 – 8619
commvaultStatic Backup agent: Commvault static – inbound and outbound TCP Ports 8400 – 8403
ftpClient FTP client - outbound TCP Port 21
ftpServer FTP server - inbound TCP Port 21
kerberos Kerberos - outbound TCPs Port 88 and 749
LicenseClient FlexLM license server client - outbound TCP Ports 27000 and 27010
nfsClient NFS client - outbound TCP and UDP Ports 111 and 2049 (0 – 65535)
nisClient NIS client - outbound TCP and UDP Ports 111 (0 – 65535)
ntpClient NTP client - outbound UDP Port 123
smbClient SMB client - outbound TCP Ports 137 – 139 and 445
snmpd SNMP services - inbound TCP Port 161 and outbound TCP Port 162
sshClient SSH client - outbound TCP Port 22
sshServer SSH server - inbound TCP Port 22
swISCSIClient First-party optional service: Software iSCSI client - outbound TCP Port 3260
telnetClient NTP client - outbound TCP Port 23
TSM Backup agent: IBM Tivoli Storage Manager – inbound and outbound TCP Ports 1500
veritasBackupExec Backup agent: Veritas BackupExec – inbound TCP Ports 10000 – 10200
veritasNetBackup Backup agent: Veritas NetBackup – inbound TCP Ports 13720, 13732, 13734, and 13783
vncServer VNC server - Allow VNC sessions 0-64: inbound TCP Ports 5900 – 5964
vpxHeartbeats vpx heartbeats - outbound UDP Port 902
Note: You can configure your own services in the file /etc/vmware/firewall/services.xml
防火牆指令範例
esxcfg-firewall examples:
Enable ssh client connections from the Service Console:
# esxcfg-firewall -e sshClient
Disable the Samba client connections:
# esxcfg-firewall -d smbClient
Allow syslog outgoing traffic:
# esxcfg-firewall -o 514,udp,out,syslog
Turn off the firewall:
# esxcfg-firewall -allowIncoming
# esxcfg-firewall -allowOutgoing
Re-enable the firewall:
# esxcfg-firewall -blockIncoming
# esxcfg-firewall –blockOutgoing
Esxcfg-nics
Description: Prints a list of physical network adapters along with information on the driver, PCI device, and link state of each NIC. You can also use this command to control a physical network adapter’s speed and duplexing.
Syntax: esxcfg-nics <options> [nic]
Options:
-s <speed> Set the speed of this NIC to one of 10/100/1000/10000. Requires a NIC parameter.
-d <duplex> Set the duplex of this NIC to one of 'full' or 'half'. Requires a NIC parameter.
-a Set speed and duplex automatically. Requires a NIC parameter.
-l Print the list of NICs and their settings.
-r Restore the NICs configured speed/duplex settings. (Internal use only)
-h Displays command help
查看實際本機系統的網卡
esxcfg-nics examples:
Set the speed and duplex of a NIC (vmnic2) to 100/Full:
#esxcfg-nics -s 100 -d full vmnic2
Set the speed and duplex of a NIC (vmnic2) to auto-negotiate:
#esxcfg-nics -a vmnic2
[ How-To ] ESXI5 GhettoVCB 線上不停機備份(linux版 )
GhettoVCB 線上不停機備份
測試環境 :
HOST OS : ESXI5 IP:192.168.10.5 NFS自動掛載備份 :/vmfs/volumes/backup/nfsshare
Geust OS : Debian6.04 IP:192.168.10.3 servername : Guest01
Geust OS : Debian6.04 IP:192.168.10.2 servername : Guest02
NFS OS : Debian6.04 IP:192.168.10.1 (mount point :/home/backup)
使用套件下載 : pietty0327、ghettoVCB
使用方法 : crontab + Linux shell script + mount (自動掛載 nfs)
一、NFS 設定步驟
1-1.安裝 nfs-server 並編輯設定檔
# apt-get update
# apt-get install nfs-kernel-server
# mkdir /home/backup
# chmoe 777 backup
# vi /etc/exports
/home/tools 192.168.10.*(rw,sync,no_subtree_check) #放多台Server使用的
/home/backup 192.168.10.*(rw,sync,no_subtree_check)
# /etc/init.d/nfs-kernel-server restart
nfs-server防火牆設定
# vi /etc/hosts.allow
portmap : 192.168.10.
mountd : 192.168.10.
1-2.檢查 nfs 服務是否有啟動
看 111 (portmap) 和 2049 (rpc.statd) port 是否有正常啟動, 沒有請重新啟動。
# showmount -e lcoalhost
二、EXSI5 HOST設定步驟
2-1.先開啟 ESXI5 ssh 連線功能
用vSphere Clint--> configuration --> Security Profile --> Services Properties --> ssh Options --> Start and stop manually -->start --> OK2-2.使用pietty 上傳 ghettoVCB.tar.gz 至 EXSI5 host 下不會因重開機而刪去的目錄內, 解tar 。(請自行下載 pietty0327.exe、ghettoVCB.tar.gz ; 因重開機而會刪去的有 tmp/、var/ 下的目錄 )
2-3.編寫設定檔
2-3-1. # vi ghettoVCB.sh (此為備份在本機端)#設定備份所存放的路徑,在這邊設定備份到本地端,用NFS設定請 # 此行
VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/backup
#定義被份的硬碟格式(zeroedthick, eagerzeroedthick, thin, and 2gbsparse are available)
DISK_BACKUP_FORMAT=thin
#定義備份保留的數量
VM_BACKUP_ROTATION_COUNT=3
#設定POWER DOWN的時間。在等待關閉時VM會放棄或是忽略特定的VM備份
POWER_DOWN_TIMEOUT=5
#設定等待VM快照的時間,在等待關閉時會放棄和忽略特定備份的VM
SNAPSHOT_TIMEOUT=15
#備份是否啟用壓縮(enable=1,disable=0)
ENABLE_COMPRESSION=0
#---- NFS的相關設定----
#定義非持久性的NFS備份(yes=1,no=0)
ENABLE_NON_PERSISTENT_NFS=0
#以下是給不想讓NFS與系統長期連接的設定,允許只在備份的過程中連接到NFS,需要才掛載
當有備份需要使用到NFS時才會自動掛載上去,一旦備份完成後就會自動卸載,並不會持續的掛載。
並使用到以下5個變數。
#是否要卸載NFS(yes=1,no=0)
UNMOUNT_NFS=0
#NFS Server 的地址(ip或主機名)
NFS_SERVER=192.168.10.1
# Defining the NFS export path:/home/backup
NFS_MOUNT=/home/backup
#NFS 資料存放地方的名稱 (掛載在 /vmfs/volumes/下 )
NFS_LOCAL_NAME=TEST
#虛擬機上NFS備份的目錄
NFS_VM_BACKUP_DIR=mybackups
#------MAIL 發送LOG的設定-------
#是否要透過電子郵件來發送備份LOG(yes=1,no=0)
EMAIL_LOG=1
#是否發送debug的LOG,這是做為測試使用。
EMAIL_DEBUG=1
#mail server的ip或網址
EMAIL_SERVER= emailserver.com
#設定mail 所使用的port
EMAIL_SERVER_PORT=25
#設定每封mail之間發送的延遲時間。
EMAIL_DELAY_INTERVAL=1
#收件人的mail
EMAIL_TO=xxx@gmail.com
#寄件人的mail
EMAIL_FROM=root@ghettoVCB
#---修改EMAIL LOG存放位置--預設定情況下log都是存放在/tmp內,避免重開機後log會被清除。
USE_VM_CONF=0
USE_GLOBAL_CONF=0
BACKUP_ALL_VMS=0
EXCLUDE_SOME_VMS=0
EMAIL_LOG_HEADER=/tmp/ghettoVCB-email$$.header
EMAIL_LOG_OUTPUT=/tmp/ghettoVCB-email-$$.log
EMAIL_LOG_CONTENT=/tmp/ghettoVCB-email-$$.content
#(將tmp修改成所要存放的路徑後儲存執行即可,建議存到/vmfs/volumes/datastore1/log 內)
2-3-2. 可編輯不同的備份腳本
# vi ghettoVCB.conf (備份在NFS 端 )
VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/test
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=2
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=3
POWER_DOWN_TIMEOUT=5
ENABLE_COMPRESSION=0
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0
ENABLE_NON_PERSISTENT_NFS=1
UNMOUNT_NFS=1
NFS_SERVER=192.168.10.1
NFS_MOUNT=/home/backup
NFS_LOCAL_NAME=backup
NFS_VM_BACKUP_DIR=nfsshare
SNAPSHOT_TIMEOUT=5
EMAIL_LOG=1
EMAIL_DEBUG=1
EMAIL_SERVER=smtp.gmail.com
EMAIL_SERVER_PORT=25
EMAIL_DELAY_INTERVAL=1
EMAIL_TO=xxxx@gmail.com
EMAIL_FROM=root@ghettoVCB
2-4.建立List vms_to_backup & vm_exclusion_list
# vi vms_to_backup (備份指定名單)
Guest01
#加入要指定要自動備份的虛擬機名稱,需和/vmfs/volumes/datastore1 下 虛擬機名稱相同)
# vi vm_exclusion_list (排除list中指定)
Guest02
#加入要指定排除的虛擬機名稱
2-5.ghettoVCB.sh 手動使用說明
ghettoVCB.sh參數說明 :
-a Backup all VMs on host
(備份主機上所有的虛擬機)
-f List of VMs to backup
(針對List名單內的虛擬機備份)
-c VM configuration directory for VM backups
(VM 配置目錄for VM備份)
-g Path to global ghettoVCB configuration file
-l File to output logging
(將LOG記錄寫到指定檔案內)
-d Debug level [info|debug|dryrun] (default: info)
(Debug測試,不會產生備份)
範例操作
只備份list內的虛擬機
#./ghettoVCB.sh -f vms_to_backup
全部備份
#./ghettoVCB.sh -a
除了排除清單(vm_exclusion_list)上的虛擬機外,剩下的都備份
#./ghettoVCB.sh -a -e vm_exclusion_list
Backup VMs using global ghettoVCB configuration file
備份虛擬機時使用ghettoVCB.conf此設定檔來備份vms_to_backup內指定的虛擬機
#./ghettoVCB.sh -f vms_to_backup -g /global/ghettoVCB.conf
Backup VMs
based on specific configuration located in
directory
根據vm_backup_configs中特定配置來備份vms_to_backup內指定的虛擬機
#./ghettoVCB.sh -f vms_to_backup -c vm_backup_configs
輸出的記錄到/tmp/ghettoVCB.log(可自行設定LOG所儲存的路徑和檔案)
#./ghettoVCB.sh -f vms_to_backup -l /vmfs/volume/local-storage/ghettoVCB.log
Dryrun測試,不會產生備份
#./ghettoVCB.sh -f vms_to_backup -d dryrun
Debug不產生備份,執行後提供詳細訊息包括備份和LOG存放的路徑及備份所需容量訊息,用來排除故障是相當好用的。
#./ghettoVCB.sh -f vms_to_backup -d debug
三、防火牆及排程設定
3-1.加入 crontab 的排程,自動定期備份 (為了測試是否正常可以先設定每10分測試一次)
# vi var/spool/cron/crontab/root
30 20 * * 1-5 /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/ghettoVCB.sh -f /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/vms_to_backup
* 24 * * 5 /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a
3-2.開啟 EMAIL 請加入 25 port 的防火牆設定
3-2-1.先確認ESXI是否有開啟防火牆25port
方法一 用介面 : [Configuration]→[Security Profile]
方法二 ESXI5 SSH # esxcli network firewall ruleset list
3-2-2.加入25port
# cd /etc/vmware/firewall/
# vi smtp.xml (在最後加入以下內容)
<!-- E-MAIL SMTP -->
<ConfigRoot>
<service id='1000'>
<id>SMTP</id>
<rule>
<direction>outbound</direction>
<protocol>tcp</protocol>
<porttype>dst</porttype>
<port>25</port>
</rule>
<enabled>true</enabled>
<required>false</required>
</service>
</ConfigRoot>
3-2-3.重啟防火牆,重啟後會看到多出SMTP 25port的設定
# esxcli network firewall refresh
# esxcli network firewall ruleset list
SMTP true (顯現出smtp有開啟)
四、重開機防火牆自動讀入設定
4-1.編寫開機執行腳本
# vi firewall.sh
#!/bin/sh
# Firewall rules
cp /vmfs/volumes/tools/file/service.xml /etc/vmware/firewall/
esxcli network firewall refresh #重啟防火牆設定
# chmod 755 firewall.sh
4-2.寫入到rc.local讓重開機ESXI主機自動跑firewall.sh
# vi /etc/rc.local
#在最下面加入此行
/vmfs/volumes/tools/script/firewall.sh
五、設定排程設定 (單台、多台主機環境)
在設定排程的部份,也和設定MAIL的防火牆規則一樣,都會因重開而還原。
單台主機設定
適合單一主機或是管理人員較少的使用。
缺點 : 日後要設的排程多的時後,或是加入到rc.local內的東西變多時,在管理上會容易亂掉,管理較不方便。
多台主機
建議最好新增一個NFS並將設定資料都統一放到NFS內,之後在有需要的ESXI主機上在掛載NFS就可使用。
優點 : 適合主機數較多且方便統一管理。
5-1.設定排程(root)
5-1-1.單台排程設定
直接寫在rc.local
# vi /etc/rc.local
#在最下面加入crontab
/bin/kill $(cat /var/run/crond.pid) #刪去目前跑的 crond.pid
/bin/echo " */5 * * * * /vmfs/volumes/datastore1/backup/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a”>> /var/spool/cron/crontabs/root
#每5秒 備份一次的備份shell寫入 /var/spool/cron/crontab/root 內
/bin/busybox crond #重啟crond
5-2-1.多台排程設定
以下範例檔案存放在NFS上 tools/script 內,可供多機備份用。
# mkdir -p /vmfs/volumes/tools/script
# mkdir /vmfs/volumes/tools/file
將要執行的 shell 暫存在 script (NFS server)
編寫 Crontab root
主要是為了日後如果有更多的排程要設定的話只需要改此root檔後,執行crontabs.sh
此腳本就會自動覆蓋舊的root檔了。在日後的管理會較為方便。
# cp /var/spool/cron/crontabs/root /vmfs/volumes/tools/file/
# cd /vmfs/volumes/tools/file/
# chmod 744 root
# vi root
#min hour day mon dow command
1 1 * * * /sbin/tmpwatch.py
1 * * * * /sbin/auto-backup.sh
0 * * * * /usr/lib/vmware/vmksummary/log-heartbeat.py
*/5 * * * * /vmfs/volumes/datastore1/backup/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a
#設定讓5分鐘跑一次看是否正常,測試時請用最小的vm 來測試,節省時間。
設定crontabs.sh
# cd /vmfs/volumes/tools/script
# vi crontabs.sh
#!/bin/sh
/bin/kill $(cat /var/run/crond.pid)
cp /vmfs/volumes/tools/file/root /var/spool/cron/crontabs
/bin/busybox crond
# chmod 755 crontabs.sh
設定rc.local開機自動跑crontabs.sh
# vi /etc/rc.local
#在最下面加入此行
/vmfs/volumes/tools/script/crontabs.sh
接下來就可以觀察在本機端 及 NFS Server 內是否有備份過去的目錄了。
備註: 安裝時出現的 error訊息
1、執行 ./ghettoVCB.sh -f vms_to_backup -g ghettoVCB.conf 第二各備份設定檔時出現
error 訊息 : "mkdir: cannot create directory '/tmp/ghettoVCB.lock': File exists"
原因 : 因同第一支設定檔都使用 ghettoVCB.sh 的設定會產生 '/tmp/ghettoVCB.lock' 在跑。
解決方法 :無法同時執行,需分開備份時間或是使用另支 ghettoVCB1.sh 修改 /tmp/ghettoVCB1.lock
2、ESXI5 本機上 mount出現文件錯亂問題
2012-03-21 02:26:53 -- info: ============ ghettoVCB LOG START ==============
(vim.fault.AlreadyExists) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
name = "/vmfs/volumes/62b67156-7cecaa9a",
msg = "The specified key, name, or identifier already exists.",
}
Datastore not found.
Datastore not found.
Datastore not found.
解決方法 :
在ESXi主机上重啟管理網路服務
# services.sh restart
3、ESXi主機配置NFS存儲為Datastore时,出錯,提示如下信息:
Error during the configuration of the host: NFS Error: Unable to Mount filesystem: Unable to connect to NFS server
解決方法: 1.確認 NFSServer的exports 設定了no_root_squash或chmod 777
2.在 EXSI主機手動MOUNT 測試,nfs設定是否成功
# esxcfg-nas -a -o 192.168.15.54 -s /home/backup NFS_Test
# esxcfg-nas -l
# df -h
# esxcfg-nas -d NFS_Test #umount
4、ghettoVCB備份 錯誤訊息 Snapshot found for「host」, backup will not take place
原因 : 會出現此錯誤訊息,主要是因為當正在使用的虛擬機VM要備份的時後,會先做出一個snapshot檔。然後在備份
的中途若有不當的中斷或停止時。此snapshot檔就會無法自動刪除。進而造成下次要備份時出現此錯誤訊息因此時需要手動自行刪除。
解決方法: 手動刪除snapshot --> 請先登入VMware vSphere Client --> 然後點選卡住的開台虛擬機右鍵。
[linux]→[Snapshot]→[Snapshot Manager]→[ghettoVCB-snapshot-2012-01-05] →[Delete]
5、查看 ESXi 的 VMkernel Log (/var/log/messages)
6、出現 " ERROR: Please enable firewall rule for email traffic on port 25 " 請加入25port的防火牆設定
參考網站 : 00086網誌 ESXi 5 下 ghettoVCB.sh 安裝及操作過程
FAQ-BOOK VMware esxi 備份ghettoVCB.sh基本設定說明
FAQ-BOOK VMware esxi 備份ghettoVCB.sh進階設定說明
VM官網 VMware Communities: ghettoVCB.sh - Free alternative for backing up VM's for ESX(i) 3.5, 4.x+ & 5.x
標籤:
ESXI-5-how-setup,
ghettoVCB,
linux
2012年3月5日 星期一
[ How-To] Debain NTP-server
OS : Debian 6.04
安裝套件
# apt-get install ntp
設定conf 檔
# cp /etc/ntp.conf.dpkg-dist /etc/ntp.conf
設定說明
1. 先處理權限方面的問題,包括放行上層伺服器以及開放區網用戶來源:
# vim /etc/ntp.conf
# restrict [你的IP] mask [netmask_IP] [parameter]
parameter 參數:
ignore : 拒絕所有類型的 NTP 連線;
nomodify: 用戶端不能使用 ntpc 與 ntpq 這兩支程式來修改伺服器的時間參數,
但用戶端仍可透過這部主機來進行網路校時的;
noquery:用戶端不能夠使用 ntpq, ntpc 等指令來查詢時間伺服器,等於不提供 NTP 的網路校時囉;
notrap: 不提供 trap 這個遠端事件登錄 (remote event logging) 的功能。
notrust: 拒絕沒有認證的用戶端。
無 : 表示『該 IP 或網段不受任何限制』的意思。
restrict default kod nomodify notrap nopeer noquery <==拒絕 IPv4 的用戶
restrict -6 default kod nomodify notrap nopeer noquery <==拒絕 IPv6 的用戶
restrict 220.130.158.71 <==放行 tock.stdtime.gov.tw 進入本 NTP 伺服器
restrict 59.124.196.83 <==放行 tick.stdtime.gov.tw 進入本 NTP 伺服器
restrict 59.124.196.84 <==放行 time.stdtime.gov.tw 進入本 NTP 伺服器
restrict 127.0.0.1 <==底下兩個是預設值,放行本機來源
restrict -6 ::1
restrict 192.168.100.0 mask 255.255.255.0 nomodify <==放行區網來源
2. 設定主機來源,請先將原本的 [0|1|2].centos.pool.ntp.org 的設定註解掉:
# server [IP or hostname] [prefer]
server 220.130.158.71 prefer <==以這部主機為最優先
server 59.124.196.83
server 59.124.196.84
3.預設時間差異分析檔案與暫不用到的 keys 等,不需要更動它:
# driftfile [可以被 ntpd 寫入的目錄與檔案]
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys 後面跟著的是存放 keys 資訊的檔案 .(Client 向 Server 連結的時候 , 可用 key 認證-ntp-keygen)
NTP 的啟動與觀察
1. 啟動 NTP
# /etc/init.d/ntpd start
# chkconfig ntpd on
# tail /var/log/messages <==自行檢查看看有無錯誤
# tail -f /var/log/syslog
2. 觀察啟動ntp-sever 的 123 埠口是否有開啟:
# netstat -tlunp |grep ntp
udp 0 0 192.168.15.161:123 0.0.0.0:* 1692/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1692/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1692/ntpd
udp6 0 0 fe80::20c:29ff:fe65:123 :::* 1692/ntpd
udp6 0 0 ::1:123 :::* 1692/ntpd
udp6 0 0 :::123 :::* 1692/ntpd
3.如何確認 NTP 伺服器有順利向上層連線後的更新本機的時間
列出目前 NTP-server 與相關的上層 NTP 的狀態
# ntpq -p
remote refid st t when poll reach delay offset jitter
========================================================================
*alqualonde.org 220.130.158.71 3 u 26 64 1 59.984 31.040 9.175
59-125-147-68.h 220.130.158.72 3 u 25 64 1 15.194 7.389 3.562
59-124-196-83.h 59.124.196.87 2 u 24 64 1 27.462 5.209 8.279
59-124-196-84.h 59.124.196.87 2 u 23 64 1 27.716 5.532 7.376
remote:亦即是 NTP 主機的 IP 或主機名稱囉~注意最左邊的符號
如果有『 * 』代表目前正在作用當中的上層 NTP
如果是『 + 』代表也有連上線,而且可作為下一個提供時間更新的候選者。
refid:參考的上一層 NTP 主機的位址
st:就是 stratum 階層囉!
when:幾秒鐘前曾經做過時間同步化更新的動作;
poll:下一次更新在幾秒鐘之後;
reach:已經向上層 NTP 伺服器要求更新的次數
delay:網路傳輸過程當中延遲的時間,單位為 10^(-6) 秒
offset:時間補償的結果,單位與 10^(-3) 秒
jitter:Linux 系統時間與 BIOS 硬體時間的差異時間, 單位為 10^(-6) 秒。
其它補充說明
用手動寫入校對時間
# crontab -e
0 0 * * * /usr/sbin/ntpdate time.stdtime.gov.tw && /sbin/hwclock -w
ntpdate:與 NTP Server 進行時間同步的指令,後面接的是所要同步的 NTP Server。
hwclock:可讀取 BIOS 的時間及將時間寫入 BIOS。
參考網站 :
ntp-keygen
2012年3月2日 星期五
【Linux】關閉 Linux Ping ( ICMP 協定 ) 回應
Disable Linux ICMP Ping
# echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
Enable Linxue ICMP Ping
# echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
2012年1月8日 星期日
[How-To] HOME Debian
安裝家裡 Home Debian
# 安裝光碟版本 : Debian 6.0.1a-i386
# 安裝磁區把 /usr /var /home /root ...etc 獨立分開
# 內部固定 IP 192.168.0.156
# DDNS xxx.myftp.org
1. 清掉 sources 的 從 CD ROM 讀取套件 List
$ vim /etc/apt/sources.list
# 把檔案裡面的 # deb cdrom:[Debian xxxxxxxxx … 開頭的刪掉
# 選擇後按下 dd 刪除 , 刪除後 ,
# 按下 ESC , 輸入 :wq , 按下 Enter
2. 安裝 ssh
$ apt-get update
$ apt-get -y install ssh
3, 安裝 pppoe
# 現在,您可以使用 "pon dsl-provider" 來建立 DSL │
# 連線並使用 "poff" 來中斷連線。
$ apt-cache search pppoe
$ apt-get install pppoe pppoeconf
# 啟動 pppoe
$ pppoeconf
# 安裝 vim 跟 移除預設的編輯器 nano
$ apt-get install ssh
$ apt-get autoremove nano
4. 安裝套件
$ apt-get -y install ssh w3m libncurses5 sudo gcc portmap
libncurses5-dev make unzip patch lynx
wget vim rcconf phpmyadmin libdate-calc-perl
rsync php5 apache2 php5-cgi php5-cli php5-curl php5-dev php5-gd
php5-mysql libapache2-mod-php5 mysql-client mysql-server chkrootkit ntpdate
mplayer ffmpeg curl ntp
5. 關掉 跟 移除 Mail Client ( MTA )
$ /etc/init.d/exim4 stop
$ apt-get autoremove exim4
6. 安裝 noip , 先申請 xxx.myftp.org
# 啟動 DDNS ( 動態 IP 網域對應 )
$ cd /root/
$ wget 'https://www.no-ip.com/client/linux/noip-duc-linux.tar.gz' .
$ tar zxvf noip-duc-linux.tar.gz
$ cd noip-2.1.9-1
$ make
$ make install
7. 設定開機的時候會啟動哪些服務
$ rcconf
8. 觀看每各磁區大小跟位置
$ df -h
檔案系統 Size Used Avail Use% 掛載點
/dev/sda1 323M 119M 188M 39% /
tmpfs 501M 0 501M 0% /lib/init/rw
udev 497M 192K 497M 1% /dev
tmpfs 501M 0 501M 0% /dev/shm
/dev/sda9 24G 173M 22G 1% /home
/dev/sda8 368M 11M 339M 3% /tmp
/dev/sda5 8.3G 732M 7.2G 10% /usr
/dev/sda6 2.8G 327M 2.3G 13% /var
9. 觀看服務的 port , 確定都是自己要使用的 port 服務
$ netstat -tlnap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1284/mysqld
tcp 0 0 0.0.0.0:51309 0.0.0.0:* LISTEN 778/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 763/portmap
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1288/sshd
tcp 0 52 192.168.0.156:22 192.168.0.112:1506 ESTABLISHED 1683/0
tcp6 0 0 :::80 :::* LISTEN 984/apache2
tcp6 0 0 :::22 :::* LISTEN 1288/sshd
10. 調整時區 , 調整所在位置的時區地點
$ dpkg-reconfigure tzdata
11. PHP Web 介面檔案上傳容量限制修改 ; 重新啟動 apache2
$ vim /etc/php5/apache2/php.ini
#upload_max_filesize = 50M ; 可以上傳50MB的檔案
#post_max_size = 50M ; PHP 將接受的POST資料最大大小。
#file_uploads = On ; 是否允許HTTP方式文件上載
12. 如果需要重新設定 Mysql 的 root 密碼 ; 或可透過 phpmyadmin 來設定
$ /usr/bin/mysqladmin -u root -p password '123456' ;
13. 檢查 PHP 是否有 run 起來
$ touch /var/www/phpinfo.php ; echo '<?PHP phpinfo(); ?>' > /var/www/phpinfo.php
$ 打開 Brwoser , 輸入 http://homedebian.myftp.org/phpinfo.php
14. 安裝 phpmyadmin
# 列出所有 Phpmyadmin 安裝目錄 跟檔案
# dpkg -L phpmyadmin
/var/lib/phpmyadmin
/etc
/etc/phpmyadmin
/etc/phpmyadmin/lighttpd.conf
..
# 移除系統安裝的 phpmyadmin
$ apt-get autoremove phpmyadmin
# 安裝 mcrypt libmcrypt4
$ apt-get install php5-mcrypt libmcrypt4
# 抓取 phpmyadmin 官方網站的, 重新取目錄名稱
$ cd /var/www/
$ wget 'http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.9/phpMyAdmin-3.4.9-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1325990408&use_mirror=ncu' .
$ mv phpMyAdmin-3.4.9-all-languages.tar.gz\?r\=http\:%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php\&ts\=1325990408\&use_mirror\=ncu phpmyadmin3.4.9.tar.gz
$ tar zxvf phpmyadmin3.4.9.tar.gz
$ mv phpMyAdmin-3.4.9-all-languages phpmyadmin_homedebain
15. 打開 Brwoser , 輸入 http://xxx.myftp.org/phpmyadmin_homedebain
# 安裝光碟版本 : Debian 6.0.1a-i386
# 安裝磁區把 /usr /var /home /root ...etc 獨立分開
# 內部固定 IP 192.168.0.156
# DDNS xxx.myftp.org
1. 清掉 sources 的 從 CD ROM 讀取套件 List
$ vim /etc/apt/sources.list
# 把檔案裡面的 # deb cdrom:[Debian xxxxxxxxx … 開頭的刪掉
# 選擇後按下 dd 刪除 , 刪除後 ,
# 按下 ESC , 輸入 :wq , 按下 Enter
2. 安裝 ssh
$ apt-get update
$ apt-get -y install ssh
3, 安裝 pppoe
# 現在,您可以使用 "pon dsl-provider" 來建立 DSL │
# 連線並使用 "poff" 來中斷連線。
$ apt-cache search pppoe
$ apt-get install pppoe pppoeconf
# 啟動 pppoe
$ pppoeconf
# 安裝 vim 跟 移除預設的編輯器 nano
$ apt-get install ssh
$ apt-get autoremove nano
4. 安裝套件
$ apt-get -y install ssh w3m libncurses5 sudo gcc portmap
libncurses5-dev make unzip patch lynx
wget vim rcconf phpmyadmin libdate-calc-perl
rsync php5 apache2 php5-cgi php5-cli php5-curl php5-dev php5-gd
php5-mysql libapache2-mod-php5 mysql-client mysql-server chkrootkit ntpdate
mplayer ffmpeg curl ntp
5. 關掉 跟 移除 Mail Client ( MTA )
$ /etc/init.d/exim4 stop
$ apt-get autoremove exim4
6. 安裝 noip , 先申請 xxx.myftp.org
# 啟動 DDNS ( 動態 IP 網域對應 )
$ cd /root/
$ wget 'https://www.no-ip.com/client/linux/noip-duc-linux.tar.gz' .
$ tar zxvf noip-duc-linux.tar.gz
$ cd noip-2.1.9-1
$ make
$ make install
7. 設定開機的時候會啟動哪些服務
$ rcconf
8. 觀看每各磁區大小跟位置
$ df -h
檔案系統 Size Used Avail Use% 掛載點
/dev/sda1 323M 119M 188M 39% /
tmpfs 501M 0 501M 0% /lib/init/rw
udev 497M 192K 497M 1% /dev
tmpfs 501M 0 501M 0% /dev/shm
/dev/sda9 24G 173M 22G 1% /home
/dev/sda8 368M 11M 339M 3% /tmp
/dev/sda5 8.3G 732M 7.2G 10% /usr
/dev/sda6 2.8G 327M 2.3G 13% /var
9. 觀看服務的 port , 確定都是自己要使用的 port 服務
$ netstat -tlnap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1284/mysqld
tcp 0 0 0.0.0.0:51309 0.0.0.0:* LISTEN 778/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 763/portmap
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1288/sshd
tcp 0 52 192.168.0.156:22 192.168.0.112:1506 ESTABLISHED 1683/0
tcp6 0 0 :::80 :::* LISTEN 984/apache2
tcp6 0 0 :::22 :::* LISTEN 1288/sshd
10. 調整時區 , 調整所在位置的時區地點
$ dpkg-reconfigure tzdata
11. PHP Web 介面檔案上傳容量限制修改 ; 重新啟動 apache2
$ vim /etc/php5/apache2/php.ini
#upload_max_filesize = 50M ; 可以上傳50MB的檔案
#post_max_size = 50M ; PHP 將接受的POST資料最大大小。
#file_uploads = On ; 是否允許HTTP方式文件上載
12. 如果需要重新設定 Mysql 的 root 密碼 ; 或可透過 phpmyadmin 來設定
$ /usr/bin/mysqladmin -u root -p password '123456' ;
13. 檢查 PHP 是否有 run 起來
$ touch /var/www/phpinfo.php ; echo '<?PHP phpinfo(); ?>' > /var/www/phpinfo.php
$ 打開 Brwoser , 輸入 http://homedebian.myftp.org/phpinfo.php
14. 安裝 phpmyadmin
# 列出所有 Phpmyadmin 安裝目錄 跟檔案
# dpkg -L phpmyadmin
/var/lib/phpmyadmin
/etc
/etc/phpmyadmin
/etc/phpmyadmin/lighttpd.conf
..
# 移除系統安裝的 phpmyadmin
$ apt-get autoremove phpmyadmin
# 安裝 mcrypt libmcrypt4
$ apt-get install php5-mcrypt libmcrypt4
# 抓取 phpmyadmin 官方網站的, 重新取目錄名稱
$ cd /var/www/
$ wget 'http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.9/phpMyAdmin-3.4.9-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1325990408&use_mirror=ncu' .
$ mv phpMyAdmin-3.4.9-all-languages.tar.gz\?r\=http\:%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php\&ts\=1325990408\&use_mirror\=ncu phpmyadmin3.4.9.tar.gz
$ tar zxvf phpmyadmin3.4.9.tar.gz
$ mv phpMyAdmin-3.4.9-all-languages phpmyadmin_homedebain
15. 打開 Brwoser , 輸入 http://xxx.myftp.org/phpmyadmin_homedebain
[ How-To] Debian Linux Apache2 + SVN Server +SSL
環境規格 :
OS : ( Debian6.0.1- 6.0.3) + apache2(2.2.16)+ HTTPS/SSL + Subversion(1.6.12)
需求 : 建立程式碼版本控制服務,使用 subversion
1. 安裝 svn
svn-server 套件
$ apt-get install subversion libapache2-svn apache2
svn-client 套件
$ apt-get install subversion-tools
2. 建立 svn 目錄(/home/svn/repository),配置目錄所有者(www-data)跟 權限
$ mkdir /home/svn
$ chown www-data:www-data -R /home/svn
$ chmod 770 -R /home/svn
3. 建立 svn 用戶 admin 密碼 /etc/apache2/dav_svn.passwd
$ /usr/bin/htpasswd -c /etc/apache2/dav_svn.passwd admin
New password:
Re-type new password:
Adding password for user admin
# 建立一般用戶的帳號 密碼
$ /usr/bin/htpasswd /etc/apache2/dav_svn.passwd fifi.chen
$ cat /etc/apache2/dav_svn.passwd
admin:OlOpE5W7gXLis
user1:W7zVH8zz13KgA
user2:qQ7eb81zSZ2.g
4. 建立 svn 目錄權限配置文件:/etc/apache2/dav_svn.authz
$ vim /etc/apache2/dav_svn.authz
[groups]
admin=admin
guest=user1,user2
#新建每一個版本庫都需要再設一各權限配置
[test1:/] # 版本庫 test1 權限配置
# *= # 默認禁止所有用戶訪問
@admin=rw # admin 組有 rw 權限
user1=r # 用戶 user1 有 r 權限
[test2:/] # 版本庫 test2 權限配置
@admin=rw # admin 組有 rw 權限
user2=r # 用戶 user2 有 r 權限
5. 修訂 /etc/apache2/mods-available/dav_svn.conf
建立 svn location,指定 svn 目錄,認證方式,認證信息;
指定 dav_svn.passwd 用戶密碼配置文件路徑;
指定 dav_svn.authz 目錄權限配置文件路徑。
$ cp /etc/apache2/mods-available/dav_svn.conf /etc/apache2/mods-available/dav_svn.conf.bak
$ vim /etc/apache2/mods-available/dav_svn.conf
<Location /svn>
DAV svn
SVNParentPath /home/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
Require valid-user
</Location>
6. 建立 svn 版本庫(test1、test2)
$ su www-data
$ svnadmin create /home/svn/test1
$ svnadmin create /home/svn/test2
7. 重新啟動 apache2
$ su root
$ /etc/init.d/apache2 restart
8. 打開瀏覽器,輸入 http://domain/svn/test1
9. SVN Clinet 端操作
Windows下, 使用 Tortoise 來存取 版本庫
[Tortoise]
Linux 下 , 使用 svn 存取 , checkout(co)/commit(ci)/update(up).
例如 svn co http://domain/svn/test1
匯入程式檔案
$ svn import /testtmp http://IP&Domain/svn/test1/tmp
打開 brwoser , 輸入 http://IP&Domain/svn/test1/
就可以看到剛剛匯入的 tmp
測試取出匯入檔案
$ cd /tmp/
$ mkdir checkout
$ cd checkout
$ svn co http://domain/svn/test1/tmp ( 在遠端server指令 )
or
$ svn co /home/svn/test1/tmp ( 在localhost指令 )
10. 建立用戶改為 sha 加密(htpasswd SHA 加密方法,參數:-s)
密碼文件默認加密方法:CRYPT encryption,密碼文件格式:用戶名:密碼
基於安全考慮,建議加密方法使用 SHA encryption:htpasswd -s 用戶名
刪除用戶指定行:dd
保存退出::wq
13. 創建 ssl 目錄,用于存放 ssl pem 証書文件
$ mkdir -p /etc/apache2/ssl
14. 創建 ssl 証書(svn.pem),保存到 ssl 目錄(/etc/apache2/ssl)
-days 365 証書有效時間一年,可依需求自行定義。
$ RANDFILE=/dev/random openssl req $@ -new -x509 -days 365 -nodes \
-out /etc/apache2/ssl/svn.pem \
-keyout /etc/apache2/ssl/svn.pem
15. 配置 ssl証書(svn.pem),包括國家,州(省),市,組織,姓名,E-mail地址
Generating a 1024 bit RSA private key
.......++++++
........++++++
writing new private key to '/etc/apache2/ssl/svn.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:GZ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Reistlin.com
Organizational Unit Name (eg, section) []:Reistlin.com
Common Name (eg, YOUR name) []:reistlin
Email Address []:admin@reistlin.com
17. 創建 apache2 svn ssl 設定
$ cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-available/svn
啟用 SSL Engine,並指定 /etc/apache2/ssl/svn.pem ssl-key存放的位置
並設定 apache2 日誌 svn_error.log 和 svn_access.log
$ vim /etc/apache2/sites-available/svn
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/svn.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/svn_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/svn_access.log combined
</VirtualHost>
18. apache2 svn ssl 配置(a2ensite),啟動 apache2 ssl mod(a2enmod)
$ cd /etc/apache2/sites-available
$ a2ensite svn
Enabling site svn.
Run '/etc/init.d/apache2 reload' to activate new configuration!
$ a2enmod ssl
Module ssl enabled
19. 配置完成,重新 apache2
$ /etc/init.d/apache2 restart
20. 完成
參考來源:
Debian Linux Apache2 + SVN 配置
Debian Linux 架設 Subversion(SVN)
OS : ( Debian6.0.1- 6.0.3) + apache2(2.2.16)+ HTTPS/SSL + Subversion(1.6.12)
需求 : 建立程式碼版本控制服務,使用 subversion
1. 安裝 svn
svn-server 套件
$ apt-get install subversion libapache2-svn apache2
svn-client 套件
$ apt-get install subversion-tools
2. 建立 svn 目錄(/home/svn/repository),配置目錄所有者(www-data)跟 權限
$ mkdir /home/svn
$ chown www-data:www-data -R /home/svn
$ chmod 770 -R /home/svn
3. 建立 svn 用戶 admin 密碼 /etc/apache2/dav_svn.passwd
$ /usr/bin/htpasswd -c /etc/apache2/dav_svn.passwd admin
New password:
Re-type new password:
Adding password for user admin
# 建立一般用戶的帳號 密碼
$ /usr/bin/htpasswd /etc/apache2/dav_svn.passwd fifi.chen
$ cat /etc/apache2/dav_svn.passwd
admin:OlOpE5W7gXLis
user1:W7zVH8zz13KgA
user2:qQ7eb81zSZ2.g
4. 建立 svn 目錄權限配置文件:/etc/apache2/dav_svn.authz
$ vim /etc/apache2/dav_svn.authz
[groups]
admin=admin
guest=user1,user2
#新建每一個版本庫都需要再設一各權限配置
[test1:/] # 版本庫 test1 權限配置
# *= # 默認禁止所有用戶訪問
@admin=rw # admin 組有 rw 權限
user1=r # 用戶 user1 有 r 權限
[test2:/] # 版本庫 test2 權限配置
@admin=rw # admin 組有 rw 權限
user2=r # 用戶 user2 有 r 權限
5. 修訂 /etc/apache2/mods-available/dav_svn.conf
建立 svn location,指定 svn 目錄,認證方式,認證信息;
指定 dav_svn.passwd 用戶密碼配置文件路徑;
指定 dav_svn.authz 目錄權限配置文件路徑。
$ cp /etc/apache2/mods-available/dav_svn.conf /etc/apache2/mods-available/dav_svn.conf.bak
$ vim /etc/apache2/mods-available/dav_svn.conf
<Location /svn>
DAV svn
SVNParentPath /home/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
Require valid-user
</Location>
6. 建立 svn 版本庫(test1、test2)
$ su www-data
$ svnadmin create /home/svn/test1
$ svnadmin create /home/svn/test2
7. 重新啟動 apache2
$ su root
$ /etc/init.d/apache2 restart
8. 打開瀏覽器,輸入 http://domain/svn/test1
9. SVN Clinet 端操作
Windows下, 使用 Tortoise 來存取 版本庫
[Tortoise]
Linux 下 , 使用 svn 存取 , checkout(co)/commit(ci)/update(up).
例如 svn co http://domain/svn/test1
匯入程式檔案
$ svn import /testtmp http://IP&Domain/svn/test1/tmp
打開 brwoser , 輸入 http://IP&Domain/svn/test1/
就可以看到剛剛匯入的 tmp
測試取出匯入檔案
$ cd /tmp/
$ mkdir checkout
$ cd checkout
$ svn co http://domain/svn/test1/tmp ( 在遠端server指令 )
or
$ svn co /home/svn/test1/tmp ( 在localhost指令 )
10. 建立用戶改為 sha 加密(htpasswd SHA 加密方法,參數:-s)
密碼文件默認加密方法:CRYPT encryption,密碼文件格式:用戶名:密碼
基於安全考慮,建議加密方法使用 SHA encryption:htpasswd -s 用戶名
$ sudo /usr/bin/htpasswd -s /etc/apache2/dav_svn.passwd 用戶名
11. 刪除 svn 用戶
$ sudo vim /etc/apache2/dav_svn.passwd查找指定用戶名:/用戶名
刪除用戶指定行:dd
保存退出::wq
12. 安装 SSL 設定
$ apt-get install openssl13. 創建 ssl 目錄,用于存放 ssl pem 証書文件
$ mkdir -p /etc/apache2/ssl
14. 創建 ssl 証書(svn.pem),保存到 ssl 目錄(/etc/apache2/ssl)
-days 365 証書有效時間一年,可依需求自行定義。
$ RANDFILE=/dev/random openssl req $@ -new -x509 -days 365 -nodes \
-out /etc/apache2/ssl/svn.pem \
-keyout /etc/apache2/ssl/svn.pem
15. 配置 ssl証書(svn.pem),包括國家,州(省),市,組織,姓名,E-mail地址
Generating a 1024 bit RSA private key
.......++++++
........++++++
writing new private key to '/etc/apache2/ssl/svn.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:GZ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Reistlin.com
Organizational Unit Name (eg, section) []:Reistlin.com
Common Name (eg, YOUR name) []:reistlin
Email Address []:admin@reistlin.com
16. 証書創建完成後,請配置証書的 root 權限設定(重要!)
$ chmod 600 /etc/apache2/ssl/svn.pem
17. 創建 apache2 svn ssl 設定
$ cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-available/svn
啟用 SSL Engine,並指定 /etc/apache2/ssl/svn.pem ssl-key存放的位置
並設定 apache2 日誌 svn_error.log 和 svn_access.log
$ vim /etc/apache2/sites-available/svn
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/svn.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/svn_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/svn_access.log combined
</VirtualHost>
18. apache2 svn ssl 配置(a2ensite),啟動 apache2 ssl mod(a2enmod)
$ cd /etc/apache2/sites-available
$ a2ensite svn
Enabling site svn.
Run '/etc/init.d/apache2 reload' to activate new configuration!
$ a2enmod ssl
Module ssl enabled
19. 配置完成,重新 apache2
$ /etc/init.d/apache2 restart
20. 完成
打開 brwoser , 輸入 https://IP&Domain/svn/test1/
參考來源:
Debian Linux Apache2 + SVN 配置
Debian Linux 架設 Subversion(SVN)
訂閱:
文章 (Atom)