在CentOS8上部署Opensip SIP服务器

一、安装MySQL数据库(本文用的是MySQL8.0.21)
1、通过以root用户或具有sudo特权的用户身份使用CentOS软件包管理器来安装MySQL 8.0服务器:

sudo dnf install @mysql

@mysql模块将安装MySQL及其所有依赖项。

2、安装完成后,通过运行以下命令来启动MySQL服务并使它在启动时自动启动:

 sudo systemctl enable --now mysqld

要检查MySQL服务器是否正在运行,请输入:

sudo systemctl status mysqld

3、运行mysql_secure_installation脚本,该脚本执行一些与安全性相关的操作并设置MySQL根密码:

sudo mysql_secure_installation

系统将要求你配置VALIDATE PASSWORD PLUGIN(验证密码插件),该插件用于测试MySQL用户密码的强度并提高安全性,密码验证策略分为三个级别:低、中和强,如果你不想设置验证密码插件,请按Enter。
在下一个提示符下,将要求你设置MySQL root用户的密码,完成此操作后,脚本还将要求你删除匿名用户,限制root用户对本地计算机的访问,并删除测试数据库,你应该对所有问题回答“是”,最后询问你是否刷新权限表,按Y回车。如下面所示:

[root@localhost ~]# sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: 
Please set the password for root here.

New password: 
Sorry, you can't use an empty password here.

New password: 

Re-enter new password: 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@localhost ~]# 

4、开启root的远程访问权限(不是必须的,如果需要远程登录,才做这一步)

mysql -u root -p

输入刚才设置的密码,登录。

use mysql;												// 使用mysql库
select user,authentication_string,host from user;		//查看user表

从user表中,可以看到,默认都是localhost,所有要update一下,让远程也可以访问

update user set host = '%' where user = 'root';

此时root的host是所有都可以了
然后刷新修改,这步一定要做,否则无法生效。

FLUSH PRIVILEGES;

5、提前创建好opensip的用户,直接给root权限好了;

CREATE USER 'opensips'@'localhost' IDENTIFIED BY 'opensipsrw';
FLUSH PRIVILEGES;

6、quit退出数据库,重启一下数据库:

systemctl restart mysqld

7、开启防火墙放行3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

二、安装依赖库

yum install gcc gcc-c++ -y
yum install make -y
yum install flex bison ncurses ncurses-devel -y
yum install mysql mysql-server mysql-libs mysql-devel -y
yum install openssl-devel -y

三、安装Opensips

下载并解压并选择模块

cd /usr/local/src
wget https://opensips.org/pub/opensips/2.4.9/opensips-2.4.9.tar.gz
tar zxvf opensips-2.4.9.tar.gz
cd opensips-2.4.9
make menuconfig

进入到菜单选取模块(右左键进入返回,空格键选中,回车键确定),选择步骤:Configure Compile Options => Configure Excluded Modules => db_mysql,然后按左键返回上一菜单,选择Save Change。

回到主菜单:选择 Compile And Install Opensips,开始安装!

安装后开始配置数据库信息:

cd /usr/local/etc/opensips/
nano opensipsctlrc

配置 opensips:

cd /usr/local/sbin/
osipsconfig

依次选择 => Generate OpenSIPS Script => Residential Script => Configure Residential Script 选中

[*] USE_AUTH
[*] USE_DBACC
[*] USE_DBUSERLOC
[*] USE_DIALOG

返回后选择 Generate Residential Script 回车,生成新的配置文件(路径:/usr/local/etc/opensips)。
拷贝和替换原有配置文件:

cd /usr/local/etc/opensips/
mv opensips.cfg opensips.cfg.backup
mv opensips_residential_2021-3-19_16\:13\:22.cfg opensips.cfg

修改opensips.cfg:

nano opensips.cfg
// 修改配置项
listen=udp:192.168.25.130:5060

修改完相关配置后使用opensipsdbctl新建数据库:

cd /usr/local/sbin
opensipsdbctl create

最后激动的时刻来了,启动 opensips:

opensipsctl start

添加用户

opensipsctl add 1001 1001

最后就是开启防火墙的5060端口了!

firewall-cmd --zone=public --add-port=5060/udp --permanent
firewall-cmd --reload

到这里结束了!!电脑端测试可以用MicroSIP:
https://www.microsip.org/downloads

手机端可以用linphone,安卓APP的,可能需要翻墙
https://new.linphone.org/

参考文章:
https://blog.csdn.net/weixin_44205009/article/details/106519809

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

୧⍢⃝୨ LonelyCoder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值