每月彙整: 2012 年 5 月

如何變更VNCSERVER解析度(How to re-define the resolution of vncserver in Linux?)

我在家中時,經常使用WIN7工作站,使用VNC CLIENT連入遠端LINUX SERVER操控
I always used to control my remote linux server via VNC client when I am home.

但內定的解析度太低,大概只有1024*768,視窗太小
If you adopt the default setting of VNCSERVER, it’s only about the resolution of 1024*768, it’s too narrow to operation.

如果不夠大,需要在LINUX啟動VNCSERVER時,輸入以下指令
If you would like to enlarge it, you should input the command as below when you try to enable VNCSERVER service.

vncserver -geometry 1280×960 -depth 16 -dpi 100 :1

如何設定MYSQL資料庫複製(How To setup MYSQL Replication)

最近,我所設立的BLOG,在測試及正式環境下,都得手動同步資料,挺麻煩的
Recently, it’s really troublesome to sync the data between testing and production server.

於是想起MYSQL的資料庫複製功能
it made me think about MYSQL REPLICATION.

我的正式環境為LINUX FEDORA OS, MYSQL為5.5.20版,測試環境為WINDOWS 7, MYSQL則為WAMP裡的5.5.16版本.不過經過測試,一樣可以同步資料
My production environment is running on the LINUX FEDORA OS, and MYSQL version number is 5.5.20, testing environment is windows 7 and mysql is 5.5.16, although it’s different OS and MYSQL version, it still can be replicated between each other.

說真的設定也沒有很難
Actually, the setting is not very difficult.

但在設定的過程中也不是沒有遇到困難,提醒
Despite it’s easy, still need to remind something as below, those were what i encountered.

1.注意權限(SLAVE機台要有連入MASTER主機的權限): 我一開始一直卡在這裡,後來才發現我手殘設錯一個小數點,我原來要192.168.1.0/24都能開放權限,應設192.168.1.但我少加了小數點,後來直接把IP也加上,縮小點也算安全一點,才使同步的錯誤解除

1. notice the access right(slave mysql need to have the access right to reach the master one): at the beginning I did not notice about this, when I was trying to enable the access right to 192.168.1.0/24, I lost a decimal dot behind 192.168.1. when i found this mistake, just add the specific ip address on it, it also meet the security principle in the network world. after completing this, I just resolve this problem.

2.注意語法: 我曾還到CHANGE MASTER那一段指令,有一個單括號漏了,結果那些設定出了點問題,我也花了點時間確認
但總計來看,MYSQL的資料庫複製功能好用又不太難設定.

2. notice the setting of CHANGE MASTER section, I lost a single brackets,and then i encountered the trouble again, and also take me for a while to confirm about this. anyway, MYSQL REPLICATION is a good function and also easy for setting.

主要參考自以下連結內的文章介紹
mainly refer to the paper URL as below.
http://www.hackosis.com/how-to-setup-mysql-replication/

MySQL is the relational database system of choice for open sourcers. Replication is the process of replicating data from one MySQL database server (the master) into another (the slave). We?ll go into why you would want to replicate a MySQL database in another article.

MySQL Replication

Using the master-slave configuration mentioned above, only the changes made to the master are replicated in the slave. Changes made to the slave do not affect the master.

If you follow the steps below, you can set up MySQL replication in a matter of minutes.

Open the my.cnf or my.ini file (depending on whether you are running Linux or Windows).
Type in the following, somewhere below ?[mysqld]?

log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
Restart MySQL on the master server.
Create a new user on the master server with the ?REPLICATION SLAVE? privelege. You don?t need to assign any other priveleges to this user. In the following commands, replace X.X.X.X with the IP address of the slave server.

CREATE USER ?user?@ ?X.X.X.X? IDENTIFIED BY ?password?;
GRANT REPLICATION SLAVE ON *.* TO ?user?@’X.X.X.X? IDENTIFIED BY ?password?;
Execute ?FLUSH TABLES WITH READ LOCK;? on the master to prevent writing to the databases.
Execute ?SHOW MASTER STATUS;? on the master and note down the values because we?ll use these later.
Execute ?UNLOCK TABLES;? on the master.
Open the my.cnf or my.ini on the slave server.
Enter somewhere below ?[mysqld]? on the slave server:

server-id=2
Save the file and restart mysqld.
Execute the following on the slave server (adjust values according to user setup in step 4 and values retrieved from step 6):

CHANGE MASTER TO
MASTER_HOST=?X.X.X.X?,
MASTER_USER=?user?,
MASTER_PASSWORD=?password?,
MASTER_PORT=3306,
MASTER_LOG_FILE=?mysql-bin.000001?,
MASTER_LOG_POS=98,
MASTER_CONNECT_RETRY=10;
Execute the following on the slave server:

START SLAVE;
Check the mysql log on the slave to ensure that the connection to the master has been successful. You should see a line similar to the following:
091104 8:42:02 [Note] Slave I/O thread: connected to master ?root@X.X.X.X:3306?, replication started in log ?mysql-bin.000001? at position 98
Now you should have successfully configured master-slave MySQL replication.

Something you might want to consider is limiting the binary log files retentions with the expire_logs_days on the master, otherwise the replicated date will just grow and grow.

如何在LINUX APACHE中設定虛擬主機(How to setup the virtual web server in Linux APACHE)

上一篇介紹了如何在WAMP中設定虛擬網站/主機,現在介紹在LINUX中如何設定?
Last post I demo how to setup the virtual servers in WAMP, now give the example for LINUX APACHE.

在LINUX中的設定,我想應該比WAMP容易些,只要更新一個檔案即可.
It’s easier than WAMP, I think, only one configuration file needs to be updated.

請編輯在/etc/httpd/conf下的httpd.conf,並將以下的設定更新到該檔下.(如圖)
please edit your httpd.conf where located at /etc/httpd/conf, and updated some configuration as below (as screenshot)

最後建議您更新/etc/下的hosts檔案
and the last step I will suggest is to update your hosts file where is located at /etc directory.

在虛擬主機的架構下,APACHE是靠完整的網域名稱解析來決定要如何導下內部設定的那一個虛擬主機.以這個例子而言,我的BLOG完整網域名稱為blog.urcloud.biz,當USER在瀏覽器輸入FQDN時,APACHE即以此為依據去尋找在httpd.conf中virtualhost裡設定的SERVERNAME來對應,如果找到了,就將您引導到適當的首頁.所以,在virtualhostL裡設定正確的servername是非常重要的.你也必須確認在DNS中的設定也是正確的.
in such architecture, apache will identify your FQDN to decide which virtual web site will be redirected. for this example, my domain name of BLOG is blog.urcloud.biz, when you guys input the FQDN on your browser, and then apache will search for the setting of virtual server in httpd.conf, and then forward to the right index page for clients. so, it’s very important when you set up a servername in your virtualhost setting of httpd.conf, you also need to make sure it can be correctly work fine on your DNS setting.

簡言之,此例,假設未在DNS設定正確的FQDN,使用者將無法找到虛擬站台.所以如果你的作業平台為LINUX請試著用nslookup或dig指令,如是WINDOWS,請用nslookup試著查看看,你設定servername是否有正確的解譯名稱.
in short, in this case, if you did not set up a right FQDN on your DNS server, users will not find your virtual web site. to make sure your dns setting is ok, please try to nslookup or dig in your linux or using nslookup in your windows OS.

WAMP 虛擬主機設定 (How to set up virtual web server on WAMP)

My testing BLOG web site installed on win7 platform, also function as backup site.
我的BLOG在WIN7工作站上,還架了一個測試站台,另有備份功能

I installed WAMP on win7, but production server was installed on LINUX. It’s no impact on the BLOG service I provided between each other.
WIN7上裝的是WAMP, 但BLOG是架在LINUX上的,但這其實沒有什麼影響

To edit the file of httpd-vhosts.conf in the directory of C:wampbinapacheApache2.2.21confextra
在目錄C:wampbinapacheApache2.2.21confextra下,編輯httpd-vhosts.conf

< VirtualHost *:80 >
ServerAdmin webmaster@urcloud.biz
DocumentRoot “c:/vhosts/blog”
ServerName blog.urcloud.biz
ErrorLog “logs/blog.urcloud.biz-error.log”
CustomLog “logs/blog.urcloud.biz-access.log” common
< /VirtualHost >

< VirtualHost *:80>
ServerAdmin webmaster@urcloud.biz
DocumentRoot “E:/LAB/phpcs5”
ServerName phpcs5
ErrorLog “logs/phpcs5-error.log”
CustomLog “logs/phpcs5-access.log” common
< /VirtualHost>

APACHE上(httpd.conf)
增加虛擬目錄的實體路徑上去
after completing the setting as above, you need to add the physical directory of virtual host on the configuration file of APACHE (httpd.conf)

< Directory C:/vhosts>
Order Deny,Allow
Allow from all
< /Directory>

< Directory "e:/lab/phpcs5">
Order Deny,Allow
Allow from all
< /Directory>

And then, remember to enable the setting of virtual server on APACHE.
把虛擬主機的設定打開
# Virtual hosts
Include conf/extra/httpd-vhosts.conf <---把#號刪除掉 (to delete the #) It's done, very simple. 大致上這樣,就能把虛擬主機的設定搞定囉..很簡單

LINUX備份遇到的問題

最近,為了將LAB備份好,決定用LINUX裡的DUMP指令,DUMP一份到我另一台WINDOWS 7裡的分享資料夾

於是我在我的WIN7工作站,用我剛買的3TB硬碟(外接在USB 3.0上)來做為備份硬碟,於是我啟動檔案共享

然後在LINUX裡輸入以下指令

mount.cifs -o username=your_username,password=your_password,uid=your_uid,gid=your_gid //win7_ipaddress(ex:192.168.1.1)/shared_directory /mnt/backup

(如果要使用以上指令,要替換成你自己的設定)

做完以上指令後,在LINUX,閱覽MOUNT起的目錄沒有問題…

接著問題發生在備份執行後,因DUMP指令是將一大堆檔案及目錄備份成一個副檔名dump的大檔案,只要檔案太大,接著便發生DUMP指令卡在最後完成100%,無去回到console,就hang在那裡,如果開另一個console連入,去閱覽那掛載的目錄就會出現以下的錯誤:

mount error(12): Cannot allocate memory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

接著我找到兩篇文章,連結如下:


照著以上編修win7 registry(機碼)後,似乎稍有改善,但仍時不時會出現一樣的錯誤…

但在重啟 LanmanServer服務(net stop lanmanserver)後,立刻dump可以執行完畢…

這個問題雖未全解,我只能先做完備份,改天再追蹤…(也有可能老花機碼又看錯,回家再檢查一次好了)