一,环境初始化:
     1,安装:git ,svn,mysql,mysql-server,mysql-devel,ncurses-devel ncurses(用于配制opensips menucofnig),perl,gcc,lynx,bison,flex(另如果需要安装其他一些模块也需要安装其他依赖包)
         特别说明:一定要确包mysql安装成功,并测试运行
         如果第一步环境没有配制好,后面可能出现一些莫名的问题
如果是在 64 位系统下,则还需要做如下处理:
64  位系统中,  /usr/lib/mysql/ 下的相关库文件无法标识,需要将  /usr/lib64/mysql  下的库来做个软链接
# ln -sf /usr/lib64/mysql/libmysqlclient.so /usr/lib/mysql/libmysqlclient.so
# ln -sf /usr/lib64/mysql/libmysqlclient.a /usr/lib/mysql/libmysqlclient.a
# ln -sf /usr/bin/ld/libmysqlclient.so /usr/lib/mysql/libmysqlclient.so

二,下载源码包,并编译安装(采用1.8长期支持版本稳定版)

1,下载

 git clone https://github.com/OpenSIPS/opensips.git -b 1.8 opensips_1_8

 或者:

svn co https://svn.code.sf.net/p/opensips/svn/branches/1.8 opensips_1_8 

 2,下载后进入 cd opensips_1_8/ 

 配置(配置时一定把自己需要的模块配置进来):

make menuconfig 

或者如果自己直接编译时加入自己需要的模块:  


make all include_modules=”db_mysql” && make prefix=/usr/local install include_modules=”db_mysql”


可能遇到问题:

curses.h:31:19: error: curses.h: No such file or directory
make[1]: *** [cfg.o] Error 1
make: *** [opensipsmc] Error 2
问题原因:

ncurses-devel ncurses 没有安装 

yum install ncurses-devel ncurses
如上安装后即可
make menuconfig 进入向导配制界面:(方向键:上,下,左,右键进行操作)
 选择:->Configure Compile Options然后根据需要进行配置:其中Configure Compile Flags 采用默认选项 Congigure Excluded Modules 选中db_mysql 选项 然后返回  保存  save Changes (如有prefix配置需要则根据自己陪孩子,本例采用/opt/opensips/)
然后返回:Compile And Install OptnSIPS
安装完成后,检查自己所有文件是否编译成功

    成功后一般四个目录:etc lib sbin share 

    然后模块目录在:lib/opensips/modules/

    应用程序目录:sbin/      

 3,修改配置:进入  (这目录在我们先前配置的profix目录下)

cd  /opt/opensips/etc/opensips
 vi opensipsctlrc


将mysql相关的注释取消掉:

# $Id$
#
# The OpenSIPS configuration file for the control tools.
#
# Here you can set variables used in the opensipsctl and opensipsdbctl setup
# scripts. Per default all variables here are commented out, the control tools
# will use their internal default values.

## your SIP domain
#SIP_DOMAIN=opensips.org

## chrooted directory
# $CHROOT_DIR="/path/to/chrooted/directory"

## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT,
## by default none is loaded
# If you want to setup a database with opensipsdbctl, you must at least specify
# this parameter.
DBENGINE=MYSQL

## database host
DBHOST=localhost

## database name (for ORACLE this is TNS name)
DBNAME=opensips

# database path used by dbtext or db_berkeley
# DB_PATH="/usr/local/etc/opensips/dbtext"

## database read/write user
DBRWUSER=opensips

## password for database read/write user
DBRWPW="opensipsrw"
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
# user name column
# USERCOL="username"

# SQL definitions
# If you change this definitions here, then you must change them
# in db/schema/entities.xml too.
# FIXME
然后::wq 保存退出  4 ,初始化数据库:   然后:
cd /opt/opensips/sbin<

运行如下命令:创建数据库:./opensipsdbctl create (注意记得先运行mysql数据库),中途两个选项全部选N

[root@lecloud sbin]# ./opensipsdbctl create
MySQL password for root:
INFO: test server charset
INFO: creating database opensips ...
INFO: Core OpenSIPS tables succesfully created.
Install presence related tables? (y/n): n
Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist? (y/n): n
[root@lecloud sbin]#

数据库安装成功后记得查看表是否初始化正确:
如下则表示初始化成功:
mysql> use opensips
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------+
| Tables_in_opensips |
+--------------------+
| acc                |
| address            |
| aliases            |
| dbaliases          |
| dialog             |
| dialplan           |
| dispatcher         |
| domain             |
| dr_carriers        |
| dr_gateways        |
| dr_groups          |
| dr_rules           |
| grp                |
| load_balancer      |
| location           |
| missed_calls       |
| nh_sockets         |
| pdt                |
| re_grp             |
| silo               |
| speed_dial         |
| subscriber         |
| uri                |
| usr_preferences    |
| version            |
+--------------------+
25 rows in set (0.00 sec)
mysql>
 5,创建我们所需的配置文件opensips.cfg
               还是在程序运行目录:/opt/opensips/sbin/
               运行:./osipsconfig
                         然后选择:Generate Opensips Script-》Residential Script->Configure Residential Script
                                            选中选项:ENABLE_TCP,USE_AUTH,USE_DBACC,USE_DIALOG,USE_MULTIDOMAIN
                                            然后返回上一级:Save Residential Script,然后 Generate Residential Script 生成新的配置文件
6,修改5,创建的配置文件: opensips_residential_2013-xx-xx_xx:xx:xx.cfg
                      如下修改:listen 地址修改,以及mpath修改: mpath:本例为:mpath=/opt/opensips/lib/opensips/modules/
                      另外需要配置一个url,是usrloc的:加入如下语句:


modparam("usrloc","db_url","mysql://opensips:opensipsrw@localhost/opensips");


7,完成后可以重启opensips服务 即可


      学习视频分享:http://pan.baidu.com/s/1ntoGOkD