A2B 與多個 Asterisk/FreePBX 連接

    版本為 13:22, 3 Oct 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    A2B 可以與多個 Asterisk 做連接,這樣的架構有以下好處:

    1. A2B 與 Asterisk 安裝在不同的主機上
    2. 各自運作的效能提升,硬體資源使用不會互相影響
    3. 如果有使用 FreePBX,它的 DB 不會與 A2B 的 DB 放在同一部主機,資料安全性較高
       

    主機的配置及架構

    總共需要兩部獨立的 Linux 主機,分別為主機 A,B。

    主機 A) A2B 主管理系統

    1. A2B 網站主程式
    2. A2B 資料庫
    3. Asterisk (不需要 FreePBX,主要用作 A2B 的 outbound/inbound trunk,並且給所有的 FreePBX 做外撥路由使用)

    用途:

    • A2B 會用到 inbound/outbound trunks
    • 所有 A2B 的 SIP account 註冊的主機

     

    主機 B) FreePBX 系統 (可連接多個 FreePBX 系統)

    1. FreePBX
    2. FreePBX 資料庫
    3. Asterisk
    4. A2B 的 AGI 及 dialplans

    用途:

    • FreePBX 的 SIP account 透過 account code 也可做撥出計費。
    • 撥出時統一經由 A2B 的 outbound trunk 路由出去。

    步驟開始

    在主機A: A2B 網站)
    1. 先安裝好Asterisk & A2B
    2. 確認 A2B 網站可以正常操作
    3. 設定 MySQL Server 可接收遠端 FreePBX 主機的存取
    4. 編輯 sip.conf,新增一個 SIP Outbound Trunk 用來做主要的外撥路由
    5. 編輯 extensions.conf,新增一個外撥的撥號規則,詳細如下
    6. 將 A2B 的AGI等檔案複製到 FreePBX 主機上
      • /etc/asterisk/a2billing.conf
      • /etc/asterisk/extensions_a2billing_1_6.conf
      • /usr/src/a2billing/addons/sounds
      • /var/lib/asterisk/agi-bin
        • a2billing.php
        • a2billing_monitoring.php
        • lib/
    7. 在 A2B Admin UI 新增一些資料
      • Trunk:
        • Label: ccnet
        • Add Prefix: 991 <與 extensions.conf 規則要呼應>
        • Provider TECH: SIP
        • Provider IP: <A2B 內部 IP>
    8. 設定 Inbound DID (選用)
      • 編輯 sip.conf,新增一個 SIP Inbound Trunk 用來做 DID 進線路由

     

    設定 MySQL Server 可接收遠端的存取權限
    編輯 /etc/mysql/my.cnf

    將這行註解
    #bind-address           = 127.0.0.1
    

    修改資料庫權限

    mysql -uroot -p <<-END_SQL
      CREATE USER 'a2billinguser'@'%' IDENTIFIED BY 'a2billingpass';
      GRANT ALL PRIVILEGES ON mya2billing.* TO 'a2billinguser'@'%';
      flush privileges;
    END_SQL
    

    extensions.conf:

    [out-all]
    exten => _991XXX.,1,Noop(This is outbound call)
    exten => _991XXX.,n,Dial(SIP/ccnet/${EXTEN:3})
    exten => _991XXX.,n,Hangup
    
    exten => _992XXX.,1,Noop(This is outbound call)
    exten => _992XXX.,n,Dial(SIP/voxbeam/${EXTEN:3})
    exten => _992XXX.,n,Hangup
    
    [from-freepbx]
    include => out-all
    
     

    Notes:

    如果來自 FreePBX 的電話,號碼開頭是 991 的,路由到 ccnet

    如果來自 FreePBX 的電話,號碼開頭是 992 的,路由到 voxbeam

    sip.conf:
    1. 當遠端 FreePBX 要外撥時,會經由這進入到 A2B 主機的 Asterisk

    ;Inbound Trunks
    ; Incoming Calls from FreePBX
    [PBX1]
    type=peer
    host=<FreePBX#1 內部 IP>
    context=from-freepbx
    qualify=yes
    insecure=port,invite
    canreinvite=no
    nat=no
    

    Tips:

    當有新增其他的 FreePBX 主機時,這裡要增加新主機的 SIP 連線資訊,例如 PBX2, PBX3,...

    2. 這個連結到 SIP Provider 做 Outbound Trunk

    ;Outbound trunks
    ;this is for test
    [ccnet]
    defaultuser=070XXXXXXX
    type=friend
    secret=123456
    port=7890
    insecure=port,invite
    host=210.202.244.130
    qualify=yes
    nat=yes
    fromuser=070XXXXXXX
    context=no-incoming
    

    3. [選用] 需要做 Inbound DID 時的 Inbound Trunk

    ; Inbound Trunk for DIDs from Voxbeam
    ;Voxbeam
    [voxbeam-in-1]
    type=peer
    qualify=yes
    nat=yes
    insecure=port,invite
    host=95.211.119.240
    dtmfmode=rfc2833
    disallow=all
    context=a2billing-did
    canreinvite=no
    allow=alaw
    allow=ulaw 
    

    註:a2billing-did 是 A2Billing 內建的 dialplan。

    在主機B: FreePBX)

    流程如下:

    1. 安裝好 FreePBX & Asterisk
    2. 確認 mysql 指令可存取遠端 A2B 的 DB 資料
      1. 執行 mysql -ua2billinguser -p -h <A2B IP>
      2. telnet <A2B IP> 3306
    3. 設定 A2B AGI 及相關檔案
      • /etc/asterisk/a2billing.conf,建立連結到 /etc/a2billing.conf
      • /etc/asterisk/extensions_a2billing_1_6.conf
      • /var/lib/asterisk/agi-bin
        • a2billing.php
        • a2billing_monitoring.php
        • lib/
      • 修改以上檔案目錄權限為 asterisk 可存取
      • 安裝 A2B 語音檔
    4. [選用] 設定 Asterisk Real-Time 可讀取遠端 A2B DB 的 sip_buddies
      •  Asterisk 必須 1.6.2 以上版本
      • 修改 res_config_mysql.conf
      • 修改 extconfig.conf
         

     

    編輯 extensions_custom.conf (註: 以 FreePBX 為例)

    加上這一行
    ;this is for A2B
    #include extensions_a2billing_1_6.conf
    

    編輯 /etc/a2billing.conf

    修改 A2B DB 的連線資訊
    [database]
    hostname = <A2B DB Host>
    ; port for postgres is 5432 by default
    port = 3306
    user = a2billinguser
    password = <DB password>
    dbname = mya2billing
    ; dbtype setting can either be mysql or postgres
    dbtype = mysql 
    

    安裝A2B語音檔

    cd sounds/
    sh install_a2b_sounds.sh
    
    chown -R asterisk:asterisk /var/lib/asterisk/sounds/ 
    

    註: 如果預設語音檔目錄不是 /var/lib/asterisk/sounds,必須修改 script 檔。

    Powered by MindTouch Core