ลองสั่ง free -m แล้วเอามาแปะไว้ให้ช่วยกันวิเคราะห์ได้ครับ
แต่อาการปกติของ Cache Proxy Server คือ ใช้ RAM ในการทำ Hot Object ครับ ลองตรวจสอบขนาด cache_dir ดูครับ ถ้าตั้งไว้เยอะมาก ก็จำเป็นต้องใช้ RAM เยอะด้วยเช่นกัน แต่ถ้ากังวลเรื่อง RAM ไม่คืนนี่ ลอง
# sync
# echo 1 > /proc/sys/vm/drop_caches
แล้วลอง free -m อีกทีครับ น่าจะเห็น RAM กลับมาบ้าง ![]()
บางทีเราอาจจะกังวลมากไปครับ ตอนนี้ผมใช้ AMD Athlon X2 4000+ กับ RAM 4GB ทำ Squid Cache Proxy ใช้ไปสักพักใหญ่ (ระบบใหญ่ครับ ผู้ใช้ 100+ คน) ก็เหลือ RAM ไม่ถึง 25 MB เหมือนกันครับ แต่ระบบก็ทำงานได้ไม่มีปัญหาครับ ก็เผื่อ ๆ ไว้ครับ ก็ Run เจ้า สองคำสั่งข้างบนนี้ไว้ใน crontab ทุก ๆ วัน ก็มี RAM คืนมาให้สบายใจเล่น ๆ แล้วหละครับ แต่อย่าลืมว่ากระบวนการ Cache นี่ช่วยให้การทำงานของระบบมีประสิทธิภาพขึ้น เคลียร์บ่อย ๆ น่าจะไม่ใช่ทางออกที่ดี ให้ระบบจัดการตัวเอง
As you may know, there are many tools for file synchronization between servers that can suit your needs, but Csync2 (Website and Paper) was specially designed for Cluster File Synchronization, which makes it a great tool to synchronize config files and folders.
Now, I’ll show you a simple way of configuring it, by having a master server (where we can make changes to the config files) and one or multiple slave servers, where the files will be synchronized. First of all, we have to install it along with other packages:
:~# sudo apt-get install csync2 sqlite3 openssl xinetd
After having everything installed, we have to create the certificates that will allow Csync2 authenticate between servers so that the files can be synchronized. To do that we do this:
:~# openssl genrsa -out /etc/csync2_ssl_key.pem 1024
:~# openssl req -new -key /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.csr
:~# openssl x509 -req -days 600 -in /etc/csync2_ssl_cert.csr -signkey /etc/csync2_ssl_key.pem -out /etc/Csync2_ssl_cert.pem
So after having all the certificates, we have to create the Csync2 key by issuing the following:
:~# csync2 -k /etc/csync2_ssl_cert.key
Once all the keys and certificates have been generated, we have to copy them from the master server to the slaves. To do this we can use whatever method you are more familiarized with.
Now, we have to configure xinetd so that Csync2 can work, because it works as an xinetd service. To do this we create a Csync2 file on /etc/xinetd.d/ and edit it like this:
:~# vim /etc/xinetd.d/Csync2
service Csync2
{
disable = no
protocol = tcp
socket_type = stream
wait = no
user = root
server = /usr/sbin/csync2
server_args = -i
}
and then we have to add the port number to /etc/services, by doing this:
:~# echo “Csync2 30865/tcp” >> /etc/services
After having done everything, we are now going to configure Csync2 so that we can determine which files are going to be synchronized. For this example, we are going to synchronize /etc/apache2 and /etc/mysql. For that we open /etc/csync2.cfg and we configure it like this:
group testing #group name, we can have multiple groups
{
host node1; #master server
host (node2); #slave server
host (node3);
key /etc/csync2_ssl_cert.key;
include /etc/apache2/;
include /etc/mysql/;
backup-directory /var/backups/csync2;
backup-generations 3;
auto none; #no automatic sync
}
Note: This tool does not just synchronize files but issues commands (such as restarting services) after the synchronization process is finished, but, I’ll let you find out how
. We can also have multiple groups with different servers on it. For further information you can refer to its Paper.
Then, we create the Csync2 backup directory:
:~# mkdir /var/backups/csync2
and we restart xinetd:
:~# /etc/init.d/xinetd restart
And finally, we do the first sync by issuing:
:~# csync -x
If errors are displayed here, just ignore them and check if the files have been synchronized. Every time we make a changes to the files in /etc/apache2 or /etc/mysql on the master server, we have to synchronize the changes by issuing the command above.
Posted in How-To, Planet, Ubuntu. Tags: cluster, csync2, How-To, synchronization, tool, Ubuntu. Leave a Comment »
The ability to drag and drop content on a page and have it save the order can make for a great user interface and is actually relatively easy to execute with a few lines of jQuery. You’ll need to include the jQuery user interface library which you can find here: Jquery Google API. All the files needed to get this up and running are in the download at the bottom of this post.
In this tutorial we’re going to be looking at 2 main PHP pages. the index.php page which contains the contents and functionality to perform the drag and drop and the updateList.php file which is a simple piece of code to update the listOrder column in the database using PHP and MySQL. Additionally you will need to add your database details to the connect.php file in the download package.
$(document).ready(function(){
function slideout(){
setTimeout(function(){
$("#response").slideUp("slow", function () {
});
}, 2000);}
$("#response").hide();
$(function() {
$("#list ul").sortable({ opacity: 0.8, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&update=update';
$.post("updateList.php", order, function(theResponse){
$("#response").html(theResponse);
$("#response").slideDown('slow');
slideout();
});
}
});
});
});
Here’s a summary of whats going on in the code above.
1. To start with we have a simple function that will slide up the ‘response’ div which contains the message once the data is saved in the database.
2. We then move to the section that enables us to drag and drop the boxes. we then set the variable ‘order’ which contains the data to be posted via ajax to our database update script.
3. Once the ajax request has been executed we then display the response in the div #response
This is the section in the index.php page that retrieves the results from the database in the correct order.
<div id="list">
<div id="response"> </div>
<ul>
<?php
include("connect.php");
$query = "SELECT id, text FROM dragdrop ORDER BY listorder ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$id = stripslashes($row['id']);
$text = stripslashes($row['text']);
?>
<li id="arrayorder_<?php echo $id;?>"><?php echo $id;?> <?php echo $text;?>
<div class="clear"></div>
</li>
<?php } ?>
</ul>
</div>
Below is the code from the ‘updateList.php’ file. Its pretty self explanatory, we have a MySQL update script wrapped with a foreach loop which adds the list order number in the database and echo’s the response.
<?php
include("connect.php");
$array = $_POST['arrayorder'];
if ($_POST['update'] == "update"){
$count = 1;
foreach ($array as $idval) {
$query = "UPDATE dragdrop SET listorder = " . $count . " WHERE id = " . $idval;
mysql_query($query) or die('Error, insert query failed');
$count ++;
}
echo 'All saved! refresh the page to see the changes';
}
?>
Load-Balanced MySQL Cluster
สืบเนื่องมาจากการทำ MySQL Cluster เสร็จแล้ว เราลองมาต่อยอดด้วยการทำ Load-Balance สำหรับ MySQL Cluster กันดู
ลักษณะการทำงานของ Load Balance
คือ การจัดกลุ่มของคอมพิวเตอร์หลายๆตัวเพื่อแบ่งงานกัน หรือกระจาย load การใช้งานของ user ไปยังคอมพิวเตอร์ภายในกลุ่ม เพื่อให้สามารถรับจำนวน user ที่เข้ามาใช้งานได้มากขึ้น หรือสามารถรับงานที่เข้ามาได้มากขึ้น นอกจากนั้นยังมีคุณสมบัติของ Fail Over คือหากมีคอมพิวเตอร์ภายในกลุ่มไม่สามารถทำงานได้ เช่น Down อยู่ หรือไม่สามารถรับงานหรือ user เพิ่มได้เนื่องจาก resource ที่ใช้ทำงานไม่พอ ตัว Load Balancer ที่เป็นตัวแจก load ให้คอมพิวเตอร์ภายในกลุ่มก็จะส่ง load ไปยังคอมพิวเตอร์เครื่องอื่นๆแทน จนกว่าคอมพิวเตอร์เครื่องนั้นจะกลับมาใช้งานได้ใหม่
ตัว load balancer อาจเกิดปัญหา bottleneck แล้วจะเกิดอะไรขึ้นถ้า load balancer fail ขึ้นมา ดังนั้นในที่นี้เราจะให้มี load balancer 2 ตัว โดย load balancer ทั้ง 2 ตัวจะมีตัวใดตัวหนึ่งมีสถานะเป็น active และตัวที่เหลือจะมีสถานะเป็น passive ซึ่งหมายความว่าจะมีหนึ่ง active load balancer และอีกตัวหนึ่งเป็น hot-standby load balancer โดยจะกลายเป็น active เมื่อตัวที่เป็น active fail
หมายเหตุ ขอปรับเปลี่ยน API node ให้เป็น Load Balancer ตัวที่2 แทน เนื่องจากในการทำ load balance ไม่จำเป็นที่จะต้องใช้ API node ซึ่งขั้นตอนการปรับเปลี่ยน API node เพื่อเตรียมเป็น Load Balancer 2 มีดังนี้
ขั้นตอนที่ 1 ทำการตรวจสอบสถานะของ cluster บน MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4) ดังนี้
sqlmang:192.168.0.4 ndb_mgmndb_mgm> show; Cluster Configuration ——————— [ndbd(NDB)] 2 node(s) id=2 @192.168.0.1 (Version: 5.0.38, Nodegroup: 0) id=3 @192.168.0.2 (Version: 5.0.38, Nodegroup: 0, Master) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.0.4 (Version: 5.0.38) [mysqld(API)] 3 node(s) id=4 @192.168.0.2 (Version: 5.0.38) id=5 @192.168.0.1 (Version: 5.0.38) id=6 @192.168.0.3 (Version: 5.0.38)
ขั้นตอนที่ 2 ลบ [MYSQLD] ออกจาก file /var/lib/mysql-cluster/config.ini บน MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4) ดังนี้
sqlmang:192.168.0.4 cd /var/lib/mysql-cluster pico config.ini
ขั้นตอนที่ 3 แก้ไข file /etc/mysql/my.cnf บน sqlload:192.168.0.3 ดังนี้
sqlload:192.168.0.3 cd /etc/mysql pico my.cnf
#ใส่เครื่องหมาย # หน้าบรรทัด ndbcluster และ ndb-connectstring=192.168.0.4
#ndbcluster #ndb-connectstring=192.168.0.4 [MYSQL_CLUSTER] #ndb-connectstring=192.168.0.4
ขั้นตอนที่ 4 restart service MySQL บน sqlload:192.168.0.3 ดังนี้
sqlload:192.168.0.3 /etc/init.d/mysql restart
ขั้นตอนที่ 5 restart cluster บน MySQL cluster management server / Load Balancer1
(sqlmang:192.168.0.4) ดังนี้
sqlmang:192.168.0.4 ndb_mgm ndb_mgm> shutdown; Node 2: Cluster shutdown initiated Node 3: Cluster shutdown initiated Node 2: Node shutdown completed. 2 NDB Cluster node(s) have shutdown. Disconnecting to allow management server to shutdown. ndb_mgm> quit; ndb_mgmd -f /var/lib/mysql-cluster/config.ini sqlnode1:192.168.0.1/sqlnode2:192.168.0.2 ndbd – initial
ขั้นตอนที่ 6 ตรวจสอบสถานะของ cluster บน MySQL cluster management server / Load Balancer1(sqlmang:192.168.0.4) อีกครั้ง ดังนี้
sqlmang:192.168.0.4 ndb_mgmndb_mgm> show; Cluster Configuration ——————— [ndbd(NDB)] 2 node(s) id=2 @192.168.0.1 (Version: 5.0.38, Nodegroup: 0, Master) id=3 @192.168.0.2 (Version: 5.0.38, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.0.4 (Version: 5.0.38) [mysqld(API)] 2 node(s) id=4 @192.168.0.2 (Version: 5.0.38) id=5 @192.168.0.1 (Version: 5.0.38) ndb_mgm> quit;
นอก จากนี้ Load balancer ทั้ง 2 จะใช้ heartbeat ในการตรวจสอบว่า load balancer อีกตัวยังทำงานได้ตามปกติหรือไม่ และ load balancer ทั้งคู่จะใช้ ldirectord เพื่อเป็นตัวแบ่งการทำงานออกไปยัง cluster node
เมื่อเรา install Ultra Monkey package ก็จะมีการ install ทั้ง heartbeat และ ldirectord ให้โดยอัตโนมัติ
สรุป การทำระบบ Load-Balanced MySQL Cluster ครั้งนี้จะใช้เครื่องทั้งหมด จำนวน 4 เครื่องดังนี้
เครื่องที่1 : เป็น storage node หรือ cluster node (sqlnode1:192.168.0.1)
เครื่องที่2 : เป็น storage node หรือ cluster node (sqlnode2:192.168.0.2)
เครื่องที่3 : เป็น Load Balancer 2 (sqlload:192.168.0.3)
เครื่องที่4 : เป็น MySQL cluster management server / Load Balancer1 (sqlmang:192.168.0.4)
และใช้ virtual IP address เป็น 192.168.0.5
Install Ultra Monkey
เริ่ม ต้นเราต้อง enable IPVS (IP Virtual Server) บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2(sqlload:192.168.0.3) ดังนี้
sqlmang:192.168.0.4/ sqlload:192.168.0.3 modprobe ip_vs_dh modprobe ip_vs_ftp modprobe ip_vs modprobe ip_vs_lblc modprobe ip_vs_lblcr modprobe ip_vs_lc modprobe ip_vs_nq modprobe ip_vs_rr modprobe ip_vs_sed modprobe ip_vs_sh modprobe ip_vs_wlc modprobe ip_vs_wrr
ในกรณีที่ต้องการให้มีการ load IPVS kernel modules ขณะที่มีการ boot เครื่อง ทำได้ดังนี้
pico /etc/modules
จากนั้นให้เพิ่ม Ultra Monkey respository ต่อท้ายของเดิมที่มีอยู่ ที่ /etc/apt/sources.list แล้ว install Ultra Monkey
sqlmang:192.168.0.4/ sqlload:192.168.0.3 pico /etc/apt/sources.list
apt-get update apt-get install ultramonkey libdbi-perl libdbd-mysql-perl libalps-heap1-dev dev
เรา ต้อง install MySQL เพื่อให้สามารถใช้งาน DBD::mysql Perl ได้ (ถ้าเครื่องไหนได้ install mysql-server แล้ว ไม่ต้องทำขั้นตอนนี้ใหม่)
sqlmang:192.168.0.4/ sqlload:192.168.0.3 cd /tmp sudo apt-get install mysql-server
จากนั้นเปิดให้มีการใช้งาน packet forwarding
sqlmang:192.168.0.4/ sqlload:192.168.0.3 pico /etc/sysctl.conf
sysctl - p
จะแสดงผล
kernel.printk = 4 4 1 7
net.ipv4.conf.default.forwarding = 1
Configure heartbeat
ใน การ configure heartbeat เราจะต้องสร้าง file ขึ้นมา 3 file บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2 (sqlload:192.168.0.3) ซึ่งได้แก่ file ha.cf file haresources และfile authkeys ดังนี้
sqlmang:192.168.0.4/ sqlload:192.168.0.3
pico /etc/ha.d/ha.cf
คำสั่งสำหรับแสดงรายชื่อ node คือ uname –n
pico /etc/ha.d/haresources
ใน file นี้เราต้องใส่ชื่อ node ของ Load Balance1 และใส่ virtual IP address ซึ่งในที่นี้ใช้ 192.168.0.5 พร้อมทั้ง netmask (27) และ broadcast address (192.168.0.31)
pico /etc/ha.d/authkeys
ซึ่ง somerandomstring คือ password ที่จะใช้เชื่อมต่อระหว่าง heartbeat บน LoadBalance1(sqlmang:192.168.0.4) และ Load Balance2 (sqlload:192.168.0.3)
จากนั้นกำหนดสิทธิ์ให้ root เท่านั้นที่สามารถอ่าน file authkeys ได้
chmod 600 /etc/ha.d/authkeys
Configure ldirectord
เริ่ม ต้นสร้าง configuration file ldirectord.cf สำหรับ ldirectord บน Load Balancer1(sqlmang:192.168.0.4) และ Load Balancer2(sqlload:192.168.0.3)
sqlmang:192.168.0.4/ sqlload:192.168.0.3
pico /etc/ha.d/ldirectord.cf
ซึ่ง ค่า login ค่า passwd ค่า database และค่า resquest ที่เรากำหนดใน file ldirectord.cf นี้ ขึ้นอยู่กับที่เราสร้างใน MySQL ซึ่งจะกล่าวถึงในหัวข้อ Create A Database Called ldirector
จาก นั้น create system startup link สำหรับ heartbeat และ remove system startup link ของ ldirectord ที่มีอยู่ออก(เพราะว่า ldirectord จะถูก start ด้วย heartbeat) ดังนี้
update-rc.d -f heartbeat remove
จะปรากฎข้อความ
Removing any system startup links for /etc/init.d/heartbeat …
/etc/rc0.d/K05heartbeat
/etc/rc1.d/K05heartbeat
/etc/rc2.d/S75heartbeat
/etc/rc3.d/S75heartbeat
/etc/rc4.d/S75heartbeat
/etc/rc5.d/S75heartbeat
/etc/rc6.d/K05heartbeat
update-rc.d heartbeat start 75 2 3 4 5 . stop 05 0 1 6 .
จะปรากฎข้อความ
Adding system startup for /etc/init.d/heartbeat …
/etc/rc0.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc1.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc6.d/K05heartbeat -> ../init.d/heartbeat
/etc/rc2.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc3.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc4.d/S75heartbeat -> ../init.d/heartbeat
/etc/rc5.d/S75heartbeat -> ../init.d/heartbeat
update-rc.d -f ldirectord remove
จะปรากฎข้อความ
Removing any system startup links for /etc/init.d/ldirectord …
Create A Database Called ldirector
เรา จะสร้าง database ชื่อ “ldirectordb” บน MySQL Cluster node ทั้งสอง (sqlnode1:192.168.0.1 และ sqlnode2:192.168.0.2) ซึ่งเป็น database ที่ load balancer ใช้ตรวจสอบว่า MySQL cluster node ยังทำงานอยู่หรือไม่
sqlnode1:192.168.0.1 mysql -u root –p GRANT ALL ON ldirectordb.* TO ‘ldirector’@’%’ IDENTIFIED BY ‘ldirectorpassword’; FLUSH PRIVILEGES; CREATE DATABASE ldirectordb; USE ldirectordb; CREATE TABLE connectioncheck (i INT) ENGINE=NDBCLUSTER; INSERT INTO connectioncheck () VALUES (1); quit;
sqlnode2:192.168.0.2 mysql -u root –p GRANT ALL ON ldirectordb.* TO ‘ldirector’@’%’ IDENTIFIED BY ‘ldirectorpassword’; FLUSH PRIVILEGES; CREATE DATABASE ldirectordb; quit;
Prepare The MySQL Cluster Nodes For Load Balancing
เรา ต้อง configure ให้ MySQL cluster node ทั้งสอง (sqlnode1:192.168.0.1 และ sqlnode2:192.168.0.2) รับการร้องขอ (request) จาก virtual IP address (192.168.0.5)
sqlnode1:192.168.0.1/ sqlnode2:192.168.0.2
apt-get install iproute
จากนั้นแก้ไข file sysctl.conf ที่ /etc/sysctl.conf (เพิ่มข้อความด้านล่างนี้ต่อท้ายของเดิม)
pico /etc/sysctl.conf
sysctl -p
จากนั้นแก้ไข interfaces สำหรับรองรับ virtual IP address (192.168.0.5)
pico /etc/network/interfaces
ifup lo:0
Start The Load Balancer
เริ่มต้น start heartbeat บน Load Balancer ทั้งสอง (sqlmang:192.168.0.4 และ sqlload:192.168.0.3) ดังนี้sqlmang:192.168.0.4/sqlload:192.168.0.3
/etc/init.d/heartbeat start
ถ้าไม่มี error เกิดขึ้น ให้ reboot load balancer ทั้งสองตัว โดยใช้คำสั่ง
shutdown – r now
ภายหลังจากที่ reboot load balancer ทั้งสองตัวเสร็จ ให้ตรวจสอบการทำงานของ load balancer โดยsqlmang:192.168.0.4/sqlload:192.168.0.3
ip addr sh eth0
จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:01:29:4b:54:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.0.4/27 brd 192.168.0.31 scope global eth0
inet 192.168.0.5/27 brd 192.168.0.31 scope global secondary eth0
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0b:cd:94:cf:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.3/27 brd 192.168.0.31 scope global eth0
sqlmang:192.168.0.4/sqlload:192.168.0.3
ldirectord ldirectord.cf status
จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 5801
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
ldirectord is stopped for /etc/ha.d/ldirectord.cf
sqlmang:192.168.0.4/sqlload:192.168.0.3
ipvsadm -L –n
จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.100.22:3306 wrr
-> 192.168.100.20:3306 Route 1 0 0
-> 192.168.100.19:3306 Route 1 0 0
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
sqlmang:192.168.0.4/sqlload:192.168.0.3
etc/ha.d/resource.d/LVSSyncDaemonSwap master status
จะปรากฎข้อความในกรณีที่เป็น active Load Balancer
master running
(ipvs_syncmaster pid: 5951)
และจะปรากฎข้อความในกรณีที่เป็น hot-standby Load Balancer
master stopped
(ipvs_syncbackup pid: 6072)
Testing (การทดสอบ)
สำหรับ การทดสอบ เราจะให้มีการเรียก connect database จากเครื่องอื่นที่อยู่ภายในวง network เดียวกัน ผ่านทาง virtual IP address (192.168.0.5) ที่เรากำหนดไว้ ดังนี้
C:\Documents and Settings\Administrator>mysql -h 192.168.100.22 -u ldirector –p
Enter password: *****************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 917500 to server version: 5.0.38-Ubuntu_0ubuntu1-log
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
หมายเหตุ
1. เมื่อมีการ run คำสั่ง ip addr sh eth0 แล้วปรากฎ inet6 fe80:20b:cdff:fe94:of06 /64 scope link(ให้แก้ไขที่ Load Balance ทั้ง 2 ตัว)
- pico /etc/modprobe.d/aliases
- ให้หาบรรทัด alias net-pf-10 ipv6 แล้วแก้ไขเป็น alias net-pf-10 off
- ให้ save file และทำการ reboot โดยใช้คำสั่ง “ifdown -a” และตามด้วย “ifup -a”
2. ในกรณีใช้คำสั่ง ipvsadm –L –n แล้วตรง ส่วน Route ไม่แสดงเลข 1 แนะนำให้ไปตรวจสอบ bindaddress และ usr % (สำหรับ Load Balancer)
Reference :
[1] www.narisa.com/forums/index.php?showtopic=6466
[2] http://www.howtoforge.com/loadbalanced_mysql_cluster_debian
Drag and drop sorting on a web application? This thought is so far fetched several years ago - and now everybody is or can do that easily with jQuery. Looking at the tutorials and documentation in jQuery’s website, it lays out a simple method to call to make our list to become sortable.
$(function() {
$("#sortable").sortable();
$("#sortable").disableSelection();
});
With our corresponding HTML:
<ul id="sortable">
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>
Here is a demo on how that works.
Now what if we are using TABLE instead of UL or OL??
Easy - Use TBODY tag. So using the example above, let’s convert the list into a table:
<table id=anothersortable>
<tbody class=content>
<tr><td>one</td></tr>
<tr><td>two</td></tr>
<tr><td>three</td></tr>
<tr><td>four</td></tr>
</tbody>
</table>
[sourcecode]
Then our jQuery to be as such:
[sourcecode language="php"]
$(function() {
$("#anothersortable tbody.content").sortable();
$("#anothersortable tbody.content").disableSelection();
});
[sourcecode]
Click for demo for the simple table.
You can even make this having sub-sort - or with children sorting. Like this:
[sourcecode language="php"]
<table id=subsortsortable>
<tbody class=content>
<tr><td>one</td></tr>
<tr><td>two</td></tr>
<tr><td>
<table><tbody class=subcontent>
<tr><td>three.one</td></tr>
<tr><td>three.two</td></tr>
</tbody></table>
</td></tr>
<tr><td>four</td></tr>
</tbody>
</table>
Adjust our jQuery to be as such:
$(function() {
$("#subsortsortable tbody.content").sortable();
$("#subsortsortable tbody.content").disableSelection();
$("tbody.subcontent").sortable();
$("tbody.subcontent").disableSelection();
});
Click for demo of this one.
12 Jul
Posted by: admin in: jquery
While we were working on http://www.duettographics.com Administration control panel, they required the ability to sort their images in easy way, so after some googeling we find many separate tutorials for this. So, we decided to write one simple tutorial that can describe the whole thing.
In this tutorial, we’ll work on sorting menu items.
Requirements : sortable jQuery UI, PHP & MySQL server support.
CREATE TABLE IF NOT EXISTS `menu` ( `id` int(11) NOT NULL auto_increment, `title` int(11) NOT NULL, `sort` int(2) NOT NULL, PRIMARY KEY (`id`) )
Create new php file called “menu_list.php”, this file will be our main file to sort the menu items .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sorting Items on the fly using jQuery UI, PHP &amp;amp;amp; MySQL</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script>
$(document).ready(
function() {
$("#sortme").sortable({
update : function () {
serial = $('#sortme').sortable('serialize');
$.ajax({
url: "sort_menu.php",
type: "post",
data: serial,
error: function(){
alert("theres an error with AJAX");
}
});
}
});
}
);
</script>
</head>
<body>
<h1>Menu List</h1>
<ul id="sortme">
<?php
// Connecting to Database
mysql_connect($hostname, $user_name, $password) or die ('Cant Connceto to MySQL');
// Selecting Database
mysql_select_db($db_name) or die ('Cant select Database');
// Getting menu items from DB
$result = mysql_query("SELECT * FROM `menu` ORDER BY `sort` ASC") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo '<li id="menu_' . $row['id'] . '">' . $row['title_en'] . "</li>\n";
}
?>
</ul>
</body>
</html>
Create a new file for AJAX purpose to update sorting called “sort_menu.php”
<?php
// Connecting to Database
mysql_connect($hostname, $user_name, $password) or die ('Cant Connceto to MySQL');
// Selecting Database
mysql_select_db($db_name) or die ('Cant select Database');
$menu = $_POST['menu'];
for ($i = 0; $i < count($menu); $i++) {
mysql_query("UPDATE `menu` SET `sort`=" . $i . " WHERE `id`='" . $menu[$i] . "'") or die(mysql_error());
}
?>
Finally, this should works fine with you, but If you faced any
Statistics