美文网首页
Centos 7 下安装opensips详细流程

Centos 7 下安装opensips详细流程

作者: 009419b5a3fd | 来源:发表于2018-05-03 14:34 被阅读1188次

    1.mysql安装(因opensips添加鉴权用户需使用mysql存储)
    <下载资源文件都放在 /usr/src/为例>
    命令:

    wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum install mysql-community-server
    

    安装后启动:

    service mysqld restart
    

    登陆mysql:

    mysql -u root 
    

    修改密码:

    set password for 'root'@'localhost' =password('password***');
    

    注:最好不要修改mysql端口。

    2.安装opensips

    安装依赖库:

    yum install mysql mysql-server mysql-libs mysql-devel
    yum install gcc make
    yum install flex bison ncurses libncurses-dev ncurses-devel
    

    下载并解压opensips的源码(最新版本2.4.3,如果发现版本已更新可以去官网查看最新版本路径):

    cd /usr/src
     wget http://opensips.org/pub/opensips/latest/opensips-2.4.3.tar.gz
     tar zxvf opensips-2.4.3.tar.gz
     cd opensips-2.4.3
    

    切换到root用户:

    su
    

    启动配置菜单:

    make menuconfig
    

    重点:很多教程都没表明这个选择步骤:Configure Compile Options -> Configure Excluded Modules -> db_mysql
    按照此顺序选择db_mysql (空格键为选择键方向键为前进后退和确定)
    选择db_mysql后一定要save。
    最后选择”Compile And Install Opensips” 等待安装完毕。

    安装完成后:

     cd /usr/local/etc/opensips/
     vi opensipsctlrc
    

    编辑配置数据库信息:(需要修改的要按照自己情况修改比如 host password等)

    SIP_DOMAIN= YOUR_PC_IP   //此处写本机地址,如果有代理填写proxy地址
    #数据库 MYSQL ORACLE PGSQL DB_BERKELEY DBTEXT均可
    
    DBENGINE=MYSQL
    
    #数据库所在服务器主机名/IP均可
    
    DBHOST=localhost
    
    #数据库名称,默认使用opensips,可配置其它名称
    
    DBNAME=opensips
    
    #数据库访问用户,主要用于数据的读写,请在mysql添加用户
    
    DBWUSER=opensips
    
    #数据库访问密码,密码必须为DBWUSER对应用户的密码
    
    DBWPW=“123456”
    
    #数据库管理用户,用于数据库、表创建与数据读写等,默认使用root,如有需要可以自行配置mysql用户权限
    
    DBROOTUSER=“root”
    

    配置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.old
    mv opensips_residential_2018-5-3_1\:13\:3.cfg opensips.cfg
    

    修改opensips.cfg

    vi opensips.cfg
    

    listen=udp:127.0.0.1:5060 修改为listen=udp:本机ip:5060

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

    cd /usr/local/sbin
    opensipsdbctl create
    

    增加用户(add后第一个是用户名第二个是密码):

    opensipsctl add 101 101
    opensipsctl add 102 102
    

    启动opensipsctl

    opensipsctl start
    

    此时可以使用sip客户端检查下server运行情况。

    error:
    1.opensipsdbctl create 时出现:

    ERROR: could not load the script in /usr/local//lib64/opensips/opensipsctl/opensipsdbctl.mysql for database engine MYSQL
    ERROR: database engine not loaded - tried 'MYSQL'
    

    因为没有在配置make menuconfig时选择db_mysql可以使用以下命令或者重新做一次配置。

         cd /usr/local/lib/opensips/opensipsctl/
         cp 你的opensips目录/scrips/opensipsdbctrl.mysql  ./
         mkdir mysql
         cp  你的opensips目录/scrips/mysql/*.sql ./
    

    2.启动opensips后抓包发现服务器返回sip 408 Request Timeout。
    修改

     cd /usr/local/etc/opensips/
     vi opensipsctlrc
    

    编辑配置数据库信息:(需要修改的要按照自己情况修改比如 host password等)

    SIP_DOMAIN= YOUR_PC_IP   //此处写本机地址
    

    3.启动时候出现

    ERROR: PID file /var/run/opensips.pid does not exist -- OpenSIPS start failed
    

    检查/var/log/messages
    具体的指令:tail -100 /var/log/messages
    错误信息

    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: NOTICE:core:main: version: opensips 2.4.3 (x86_64/linux)
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:main: using 32 Mb of shared memory
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:main: using 2 Mb of private process memory
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:init_reactor_size: reactor size 1024 (using up to 0.03Mb of memory per process)
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:evi_publish_event: Registered event <E_CORE_THRESHOLD(0)>
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:evi_publish_event: Registered event <E_CORE_SHM_THRESHOLD(1)>
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:evi_publish_event: Registered event <E_CORE_PKG_THRESHOLD(2)>
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:tm:mod_init: TM - initializing...
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:sl:mod_init: Initializing StateLess engine
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: NOTICE:signaling:mod_init: initializing module ...
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:rr:mod_init: rr - initializing
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:maxfwd:mod_init: initializing...
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:sipmsgops:mod_init: initializing...
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:evi_publish_event: Registered event <E_MYSQL_CONNECTION(3)>
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:db_mysql:db_mysql_connect: driver error(1045): Access denied for user 'opensips'@'localhost' (using password: YES)
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:db_mysql:db_mysql_new_connection: initial connect failed
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:core:db_do_init: could not add connection to the pool
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:uri:mod_init: Could not connect to database
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:core:init_mod: failed to initialize module uri
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: ERROR:core:main: error while initializing modules
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: INFO:core:cleanup: cleanup
    Nov 16 14:09:42 localhost /usr/local/sbin/opensips[22770]: NOTICE:core:main: Exiting....
    Nov 16 14:09:42 localhost opensips: INFO:core:daemonize: pre-daemon process exiting with -1
    

    解决方法:

    打开mysql

    mysql -u root -p
    mysql> grant all privileges on opensips.* to opensips@localhost identified by 'opensipsrw';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    

    重新启动OpenSIPS
    目录(cd /usr/local/sbin)

    opensipsctl start
    

    相关文章

      网友评论

          本文标题:Centos 7 下安装opensips详细流程

          本文链接:https://www.haomeiwen.com/subject/denkrftx.html