Setting up a lab for CGRateS

Setting up a lab for CGRateS

It’s useful to set up a lab to explore CGRateS. I’m providing some notes for this, although you should also make yourself familiar with the CGRateS Documentation.

We are building this on Ubuntu 14.04 within a VM. If you use a different OS, you will have to adjust things accordingly. I’m assuming you’ve done all of the usual base OS configuration and updates. Also, this is based off the most current package of CGRateS at the time of writing, which is v0.9.1 rc8.

Also, as this is a lab setup, we aren’t going to bother with any security configuration, resilience, etc. as it is assumed this is being installed in a secure, controlled environment, and we don’t want incorrect security getting in the way of getting it working.

CGRateS can use various databases including Redis, MySql, PostgreSQL and MongoDB. I’m using MongoDB as that supports storing both the runtime data with things like accounts and stats (data_db) and the offline data such as tariff plans and CDR storage (stor_db). Ubuntu has MongoDB in it’s repositories, but we will need a newer version, so we should add the MongodDB repositories:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update

We can now install MongoDB and start it:

sudo apt-get install mongodb-org
sudo service mongodb start

We can now install CGRateS, as follows:

wget http://www.cgrates.org/tmp_pkg/cgrates_0.9.1~rc8_amd64.deb
dpkg -i cgrates_0.9.1~rc8_amd64.deb

Before we can start CGRates, we have to set up the database. This is done using a script supplied by the CGRates installation:

cd /usr/share/cgrates/storage/mongo/
./setup_cgr_db.sh

We also have to configure CGRateS itself. The main configuration file is /etc/cgrates/cgrates.json. A default file, with most sections commented out is installed with the deb. I suggest you copy this first so you have a backup in case you make an error, or want to start from scratch:

sudo cp /etc/cgrates/cgrates.json /etc/cgrates/cgrates.json.orig

We can now edit the file, uncomment the sections we want, and configure it. There are lots of sections in the configuration file, and we won’t need them all at this stage. The file is richly commented, so you may want to have a look through to see the various sections. At this point, we should uncomment the general, cache, listen, http, data_db, stor_db, and rals sections by removing the “//” at the start of each line of these sections.

We also need to configure the database to use MongoDB. This is done by changing the data_db and stor_db sections as follows (I’ve removed the default comments and inserted my own on the changed lines for clarity):

"data_db": {
 	"db_type": "mongo",	// Use MongoDB for data_db
 	"db_host": "127.0.0.1",
 	"db_port": 27017,	// MongoDB Port
 	"db_name": "10",
 	"db_user": "cgrates",
 	"db_password": "",
 	"load_history_size": 10,
},
 
 
"stor_db": {
	"db_type": "mongo",	// Use MongoDB for stor_db
	"db_host": "127.0.0.1",
	"db_port": 27017,	// MongoDB Port
	"db_name": "cgrates",
	"db_user": "cgrates",
	"db_password": "",
	"max_open_conns": 100,
	"max_idle_conns": 10,
	"cdrs_indexes": [],
},

The final thing we must do before we try to start CGRateS is to enable it. This is done by editing the file /etc/default/cgrates as follows:

# defaults file for CGRateS real-time charging system
 
# start CGRateS init.d script?
#  starts with "true"
ENABLE=true
 
# Start with specific user/group
USER=cgrates
GROUP=cgrates
 
# what extra options to give cgrates binary?
#  See cgr-engine -h for options
#DAEMON_OPTS=''
 
# Don't forget to create an appropriate config file,
# else the CGRateS system will not start.

You should now be able to start CGRateS as follows:

sudo service cgrates start

You can verify it starting up by checking /var/log/syslog where you should see something like the following
May 15 17:34:20 cgrates1 CGRateS [2507]: No enabled CDRC clients
May 15 17:34:20 cgrates1 CGRateS [2507]: enabling handler for JSON-RPC
May 15 17:34:20 cgrates1 CGRateS [2507]: enabling handler for WebSocket connections
May 15 17:34:20 cgrates1 CGRateS [2507]: start listening at
May 15 17:34:20 cgrates1 CGRateS [2507]: Starting CGRateS JSON server at .
May 15 17:34:20 cgrates1 CGRateS [2507]: Starting CGRateS GOB server at .

You should now have a minimal running CGRateS installation that you can start to play with.

Leave a Reply

Your email address will not be published. Required fields are marked *