一、VoIP拓撲
PBX是程控交換機,程控交換機有實體交換機和軟件模擬的交換機。
軟件模擬的交換機,即交換機服務器,常用開源的sip服務器有asterisk,freepbx, opensip, freeswitch等,商用的minisipserver也不錯,也不貴。
PSTN網關是接入電信運營商網絡需要的,暫時不需要。
測試的SIP客戶端工具比較多zoiper, microSIP, X-lite, Yate, eyeBeam, Linphone等。
可以推薦一些基於Sip協議的開源IP電話客戶端嗎?
https://www.zhihu.com/question/20093472?sort=created
二、VoIP服務器部署
為了避開網絡穿透的問題,我將SIP服務器裝在了阿里雲(百度雲 / vultr的vps也都行)主機上,也就是NAT之后,如果裝在本地(NAT之前),就需要stun/tun服務器來協助穿透。
1、minisipserver裝在阿里雲ECS的windows 2012 r2服務器主機上
注意
*關閉windows 2012 r2防火牆,先保持網絡通暢,調完了在配置防火牆端口。
*不需要配置nat,只需要把NAT內網映射到外網,因為阿里雲服務器主機分配了公網,並且在nat之后,minisipserver默認配置就行。
*端口必須映射,在網絡和安全組里設置,常用的ssh是22號端口,sip默認的語音數據端口是5060,我為了調試方便開通了所有端口。
2、 minisipserver裝在vultr vps的windows 2012 r2服務器上
同樣需要注意
*關閉windows 2012 r2防火牆,先保持網絡通暢,調完了在配置防火牆端口。
*不需要配置nat,只需要把NAT內網映射到外網,因為vps是公網,並且在nat之后,minisipserver默認配置就行。
*端口必須映射,在網絡和安全組里設置,常用的ssh是22號端口,sip默認的語音數據端口是5060,我為了調試方便開通了所有端口。
3、FreePBX安裝在阿里雲ECS的centos 7.2主機上
minisipserver雖然簡單,但功能單一,不支持創建電話會議,所以這里將VoIP服務器換成開源的freepbx。
freepbx安裝手冊
https://wiki.freepbx.org/display/FOP/Installing+FreePBX+14+on+CentOS+7
https://wiki.freepbx.org/display/FOP/Installing+FreePBX+14+on+Ubuntu+18.04
1) 一鍵安裝freepbx的腳本很方便
http://freepbx.org.cn/wiki/index.php?title=FreePBX
腳本的有些軟件包失效了,比如asterisk-14-current.tar.gz,沒有current版本,在腳本文件提供的網站里找到有效的版本,安裝沒報錯就正常了。
2) 同樣特別注意
*關閉centos 7.2防火牆,先保持網絡通暢,調完了在配置防火牆端口。
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)
*端口必須映射,在網絡和安全組里設置,常用的ssh是22號端口,sip默認的語音數據端口是5060,我為了調試方便開通了所有端口。
*不需要配置nat,只需要把NAT內網映射到外網,因為阿里雲服務器主機分配了公網,並且在nat之后

*NAT本地IP到公網IP映射
設置--->Asterisk SIP設置--->NAT設置
掃描一下Detect Network Settings就行,我習慣性的把服務器本地IP也添上
配置好,添加分機,就可以用客戶端工具連接了
新安裝的freepbx可能模塊加載不完全,最好重啟一下freepbx
fwconsole start/restart
3) freepbx/asterisk( freepbx是帶web ui的asterisk )常用指令
https://www.cnblogs.com/operationhome/p/9149171.html
4、freepbx安裝到vultr的VPS上
裝的FreePBX 14.0.5.2
https://www.freepbx.org/downloads/
1) vps安裝freepbx
2) 同樣的配置
設置--->高級設置--->sip nat 配置成never或者no
設置--->Asterisk SIP設置--->NAT設置
掃描一下Detect Network Settings就行,我習慣性的把服務器本地IP也添上
同樣 新安裝的freepbx可能模塊加載不完全,最好重啟一下freepbx
fwconsole start/restart
5、freeswitch
5.1、freeswitch安裝
1) freeswitch一鍵安裝腳本
https://blog.csdn.net/gredn/article/details/75393207
默認的配置注冊不上,報403 Forbidden(Invalid domain in From: header)
2018-12-31 22:19:12.061220 [WARNING] sofia_reg.c:1792 SIP auth challenge (REGISTER) on sofia profile 'internal' for [1001@182.61.56.247] from ip 119.131.168.166
2018-12-31 22:19:12.121205 [WARNING] sofia_reg.c:1737 SIP auth failure (REGISTER) on sofia profile 'internal' for [1001@182.61.56.247] from ip 119.131.168.166
https://www.cnblogs.com/yoyotl/p/6552891.html
2) 快速安裝
wget https://www.freeswitch.org.cn/Makefile && make install
找不到Makefile,地址已經失效了
3) 官網的安裝手冊也不一定靠譜,系統版本,各種依賴庫一堆問題,下面是驗證的可行的。
yum install -y http://files.freeswitch.org/freeswitch-release-1-6.noarch.rpm epel-release
yum install -y freeswitch-config-vanilla freeswitch-lang-* freeswitch-sounds-*
systemctl enable freeswitch
freeswitch
4) freeswitch v1.0在阿里雲centos 7.03上的安裝
https://blog.csdn.net/MoSee/article/details/77945546
5.2、freeswitch配置
以上默認能撥通,但是沒聲音,30秒左右就自動斷線了,明顯跟freepbx一樣是NAT的故障
我偷懶用yun install安裝的freeswitch,配置文件在/etc/freeswitch目錄,安裝文件比較分散
/var/lib/yum/repos/x86_64/7/freeswitch
/var/lib/freeswitch
/var/cache/yum/x86_64/7/freeswitch
/var/log/freeswitch
/usr/lib64/freeswitch
/usr/share/freeswitch
/usr/bin/freeswitch
/run/freeswitch
/etc/sysconfig/freeswitch
/etc/freeswitch
1) 修改internal.xml
cd /etc/freeswitch/sip_profiles
vi internal.xml
<param name="ext-rtp-ip" value="auto-nat"/>
<param name="ext-sip-ip" value="auto-nat"/>
將atto-nat改成雲服務器公網IP
2) 關閉centos 7.2防火牆,先保持網絡通暢,調完了在配置防火牆端口。
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)
重啟freeswitch
freeswitch -stop
freeswitch
測試rtp已經通了
5.3、freeswitch測試
sample sipp scenarios for testing freeswitch
https://github.com/os11k/sipp2freeswitch
5.4、FreeSwitch默認只支持音頻,為支持視頻,修改vars.xml如下:
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=PCMU,PCMA,GSM,H264,H263-1998,H263"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMU,PCMA,GSM,H264,H263-1998,H263"/>
5.5、杜金房的個人網站
6、VoIP客戶端工具配置
1)android客戶端連接,用zoiper注冊,填如下幾項就可以了
2) x-lite
3) tSIP與tSIP之間撥號
4) tSIP與eyebeam撥號
5) microsip與eyebeam撥號
三、網絡穿透
雖然將服務器安裝到公網主機上避免了網絡穿透,但是網絡問題是不得不面對的。因為國情,導致翻牆,打洞也成為了一門科學。
1、FireWall和NAT(防火牆和網絡地址與端口轉換)
具體細節參考Cisco VoIP
2、SIP穿越 NAT
1) NAT經常使用的分類例如以下:
Full Cone NAT(全然圓錐型)
Address Restricted Cone NAT(地址限制圓錐型 )
Port Restricted Cone NAT(port限制圓錐型)
Symmetric NAT(對稱型)
https://www.cnblogs.com/jhcelue/p/7258803.html
2) NAT拓撲檢測
A Python STUN client for getting NAT type and external IP (RFC 3489)
https://pypi.org/project/pystun/
辦公司網路NAT類型是Address Restricted Cone NAT
3) stun/turn server穿越NAT
stun官網http://www.stunprotocol.org/
stun詳解以及部分公用stun服務器 https://www.voip-info.org/stun
turn server安裝 http://turnserver.open-sys.org/downloads/v3.2.4.4/INSTALL
3、網絡跨域實戰
stun server搭建與測試
https://blog.csdn.net/zhenzhen2014/article/details/45871397
http://nil.uniza.sk/sip/installing-and-configuring-restund-stunturn-server
https://www.cnblogs.com/jhcelue/p/7258803.html
免費的stun服務器
http://wiki.tomocha.net/SIP_STUNserver.html
基於pjsip實現p2p語音對講
https://blog.csdn.net/voidreturn/article/details/65634390?locationNum=1&fps=1
四、其他開源VoIP服務器方案調研
1、Asterisk
Asterisk安裝
https://blog.csdn.net/yuesichiu/article/details/41693577
Asterisk : Hello world 打通第一個電話
http://www.hiastar.com/doc/asterisk_cn/6914124.html
自己動手搭建免費VoIP服務器
https://blog.csdn.net/yuesichiu/article/details/41693577
在VPS上建asterisk server
其他補充
service httpd restart
service asterisk restart
service network restart
amportal restart
https://blog.csdn.net/liuxiao723846/article/details/79585897
https://blog.csdn.net/brandon2015/article/details/51811914
2、opensip安裝
sudo apt-get update
sudo apt-get install build-essential bison flex libncurses5 libncurses5-dev perl libdbi-perl libdbd-mysql-perl libdbd-pg-perl libfrontier-rpc-perl libterm-readline-gnu-perl libberkeleydb-perl
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysqlclient-dev
make menuconfig
參考https://blog.csdn.net/croop520/article/details/79096516
1)編譯
默認目錄機構如下:
配置文件位置:/usr/local/etc/opensips/
mysql 數據庫表創建sql語句:/usr/local/share/opensips/mysql/
安裝模塊目錄:/usr/local/lib/opensips/modules/
opensips 控制台模板:/usr/local/lib/opensips/opensipsctl/
程序運行路徑:/usr/local/sbin/
2)測試
#/usr/local/sbin/opensipsctl start
#/usr/local/sbin/opensipsctl stop
#/usr/local/sbin/opensipsctl restart
#/usr/local/sbin/opensipsdbctl create
#/usr/local/sbin/opensipsctl add <username>@opensips_address <password>
#/usr/local/sbin/opensipsctl add 100@172.18.97.146 100
#/usr/local/sbin/opensipsctl add 101@172.18.97.146 101
#/usr/local/sbin/opensipsctl ul show
root@iZwz9ic9ggky8kwzyfkfayZ:/usr/local/sbin# sudo opensipsctl add 100 100
sudo: unable to resolve host iZwz9ic9ggky8kwzyfkfayZ
new user '100' added
root@iZwz9ic9ggky8kwzyfkfayZ:/usr/local/sbin# sudo opensipsctl add 101 101
sudo: unable to resolve host iZwz9ic9ggky8kwzyfkfayZ
new user '101' added
root@iZwz9ic9ggky8kwzyfkfayZ:/usr/local/sbin# sudo opensipsctl add 102 102
sudo: unable to resolve host iZwz9ic9ggky8kwzyfkfayZ
new user '102' added
root@iZwz9ic9ggky8kwzyfkfayZ:/usr/local/sbin# sudo opensipsctl add 103 103
sudo: unable to resolve host iZwz9ic9ggky8kwzyfkfayZ
new user '103' added
3)配置
/usr/local/etc/opensips/
3、阿里雲部署freeswitch
https://blog.csdn.net/MoSee/article/details/77945546?locationNum=4&fps=1
http://bbs.freeswitch.org.cn/t/freeswitch/2093
vultr端口檢測
https://www.vultrcn.com/11.html
在VPS上建asterisk server
vps,EC2比較
4、其他
SipDroid +miniSIPServer搭建SIP局域網語音通話
http://www.cnblogs.com/poe-blog/p/3553888.html
openmeetings
http://blog.51cto.com/jiangzhi2013/1218491
https://blog.csdn.net/ying357/article/details/10076967
https://blog.csdn.net/ying357/article/category/1342860
其他方案收集
1、resiprocate使用入門:內網搭建基於repro的sipproxy測試環境
https://blog.csdn.net/c359719435/article/details/54619139