เทคนิคการรัน MonAst มากกว่า 1 โพรเซสบนเครื่องเดียวกัน

Asterisk Opensource IP Pbx

เทคนิคการรัน MonAst มากกว่า 1 โพรเซสบนเครื่องเดียวกัน

โพสต์โดย nuiz » 20 เม.ย. 2010 12:29

บทความนี้ต่อเนื่องจากบทความการ มอนิเตอร์ Asterisk ผ่านเว็บด้วยโปรแกรม MonAst นะครับ ซึ่งเป็นเทคนิคการรัน MonAst มากกว่า 1 โพรเซสบนเครื่องเดียวกัน ผมทำแบบนี้เพราะต้องการแยก Web Interface กันหน่ะครับว่า ถ้าเข้าเว็บนี้ เช่น http://x.x.x.x/monast1 ก็จะเห็นเฉพาะ Extension 100 - 109 และถ้าเข้าเว็บนี้ http://x.x.x.x/monast2 ก็จะเห็นเฉพาะ Extension 110 - 119 อย่างนี้เป็นต้นครับ มาลงมือทำกันเลยดีกว่า เอาสัก 3 โพรเซสนะครับ

1. สร้างไดเร็คตอรี่เว็บของ MonAst เพิ่ม ให้เป็น 3 เว็บ
เดิมทีผมมีแค่ไดเร็คตอรี่เดียว เช่น /var/www/html/monast ผมสร้างใหม่ (จะไม่ใช้ /var/www/html/monast แล้ว) เป็น monast-1, monast-2 และ monast-3

โค้ด: เลือกทั้งหมด
cp -rf /var/www/html/monast /var/www/html/monast-1
cp -rf /var/www/html/monast /var/www/html/monast-2
cp -rf /var/www/html/monast /var/www/html/monast-3


2. สร้างไฟล์คอนฟิก /etc/monast.conf เพิ่ม
สร้างให้เป็น 3 ไฟล์ ผมตั้งชื่อเป็น monast-1.conf, monast-2.conf และ monast-3.conf

cp /etc/monast.conf /etc/monast-1.conf
cp /etc/monast.conf /etc/monast-2.conf
cp /etc/monast.conf /etc/monast-3.conf

และแก้ไขแต่ละไฟล์ ดังนี้
ไฟล์ /etc/monast-1.conf

[global]
hostname = localhost
hostport = 5038
username = monast
password = monastpassword

bind_host = 127.0.0.1
bind_port = 5039
default_context = from-internal
transfer_context = default
meetme_context = default
meetme_prefix =

[users]
sortby = callerid
default = hide

SIP/100 = show
SIP/101 = show
SIP/102 = show
SIP/103 = show
SIP/104 = show
SIP/105 = show
SIP/106 = show
SIP/107 = show
SIP/108 = show
SIP/109 = show

ไฟล์ /etc/monast-2.conf

[global]
hostname = localhost
hostport = 5038
username = monast
password = monastpassword

bind_host = 127.0.0.1
# อย่าให้พอร์ตของ MonAst ของแต่ละโพรเซสซ้ำกัน
bind_port = 5040
default_context = from-internal
transfer_context = default
meetme_context = default
meetme_prefix =

[users]
sortby = callerid
default = hide

SIP/110 = show
SIP/111 = show
SIP/112 = show
SIP/113 = show
SIP/114 = show
SIP/115 = show
SIP/116 = show
SIP/117 = show
SIP/118 = show
SIP/119 = show

ไฟล์ /etc/monast-3.conf

[global]
hostname = localhost
hostport = 5038
username = monast
password = monastpassword

bind_host = 127.0.0.1
# อย่าให้พอร์ตของ MonAst ของแต่ละโพรเซสซ้ำกัน
bind_port = 5041
default_context = from-internal
transfer_context = default
meetme_context = default
meetme_prefix =

[users]
sortby = callerid
default = hide

SIP/120 = show
SIP/121 = show
SIP/122 = show
SIP/123 = show
SIP/124 = show
SIP/125 = show
SIP/126 = show
SIP/127 = show
SIP/128 = show
SIP/129 = show

3. แก้ไขไฟล์ Daemon ของ MonAst
เนื่องจากจะมี MonAst รันพร้อมๆกันในเครื่องเดียวกันตั้ง 3 โพรเซส ซึ่งในไฟล์ /etc/monast-x.conf เราได้กำหนดให้มันรันคนละ Port กันแล้ว ต่อมาเราต้องแยกไฟล์ .pid, .log และบอกว่าให้มันดูคอนฟิกจากไฟล์ชื่ออะไรในไดเร็คตอรี่ /etc (ซึ่งเรามี 3 ไฟล์คือ monast-1.conf, monast-2.conf, monast-3.conf)

cd /var/www/html/monast-1/pymon
แก้ไขไฟล์ monast.py ทั้งหมด 3 แห่งดังนี้

ค้นหาคำว่า monast.pid แก้ไขเป็น monast-1.pid
ค้นหาคำว่า monast.cfg แก้ไขเป็น monast-1.cfg
ค้นหาคำว่า monast.log แก้ไขเป็น monast-1.log

โค้ด: เลือกทั้งหมด
cd /var/www/html/monast-2/pymon

แก้ไขไฟล์ monast.py ทั้งหมด 3 แห่งดังนี้

ค้นหาคำว่า monast.pid แก้ไขเป็น monast-2.pid
ค้นหาคำว่า monast.cfg แก้ไขเป็น monast-2.cfg
ค้นหาคำว่า monast.log แก้ไขเป็น monast-2.log

โค้ด: เลือกทั้งหมด
cd /var/www/html/monast-3/pymon

แก้ไขไฟล์ monast.py ทั้งหมด 3 แห่งดังนี้

ค้นหาคำว่า monast.pid แก้ไขเป็น monast-3.pid
ค้นหาคำว่า monast.cfg แก้ไขเป็น monast-3.cfg
ค้นหาคำว่า monast.log แก้ไขเป็น monast-3.log

4. แก้ไขไฟล์คอนฟิกของ Web Interface ของ MonAst
เพื่อบอกว่าให้คอนเน็คกับ MonAst ที่พอร์ตอะไร เพราะตอนนี้ MonAst มีทั้งหมด 3 พอร์ต (จากไฟล์ /etc/monast-x.conf)

โค้ด: เลือกทั้งหมด
cd /var/www/html/monast-1/lib

เว็บนี้จะคอนเน็ค MonAst ที่พอร์ต 5039 ไม่ต้องแก้ไขอะไรในไฟล์ config.php ยกเว้นต้องการปิดไม่ให้เห็นบางเมนู

โค้ด: เลือกทั้งหมด
cd /var/www/html/monast-2/lib

แก้ไขไฟล์ config.php
ค้นหาบรรทัดนี้
define("HOSTPORT", 5039);
แก้ไขเป็น
define("HOSTPORT", 5040);

โค้ด: เลือกทั้งหมด
cd /var/www/html/monast-3/lib

แก้ไขไฟล์ config.php
ค้นหาบรรทัดนี้
define("HOSTPORT", 5039);
แก้ไขเป็น
define("HOSTPORT", 5041);

5. สตาร์ท MonAst Daemon
ให้ kill โพรเซส monast เดิมก่อนนะครับ แล้วค่อยสตาร์ทใหม่

โค้ด: เลือกทั้งหมด
/usr/bin/python -u /var/www/html/monast-1/pymon/monast.py --daemon
/usr/bin/python -u /var/www/html/monast-2/pymon/monast.py --daemon
/usr/bin/python -u /var/www/html/monast-3/pymon/monast.py --daemon


เช็ค Process ดูด้วยนะครับว่ารันได้หรือเปล่า แล้วก็เช็ค Port ดูว่ามีพอร์ต TCP 5039, 5040, 5041 รันหรือเปล่า ใช้คำสั่ง
netstat -ln | grep 5039
netstat -ln | grep 5040
netstat -ln | grep 5041

6. เข้าเว็บ MonAst
เข้าทีละเว็บเลยครับ แล้วสังเกตุ User/Peer ที่โชว์
http://x.x.x.x/monast-1
http://x.x.x.x/monast-2
http://x.x.x.x/monast-3
** หากมีปัญหากับอุปกรณ์ที่ซื้อมาเองหรือบริการที่ทำขึ้นมาเอง ให้โพสต์ถามในเว็บบอร์ดนี้นะครับ **
** งานเร่งด่วนติดต่อว่าจ้างที่เบอร์ 08-5161-9439 อีเมล์ iamaladin@gmail.com ไลน์ NuizVoip ครับ **
nuiz
Diamond Member
 
โพสต์: 6995
ลงทะเบียนเมื่อ: 24 มี.ค. 2010 09:33

ย้อนกลับไปยัง Asterisk SIP Server

ผู้ใช้งานขณะนี้

่กำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และ บุคคลทั่วไป 1 ท่าน

cron