In this tutorial I’m going to give you detailed instructions on how to deploy Telescope on your own server running Centos.
I’m doing this on a virtual machine on my server, the same procedure applies to any server like Amazon EC2, Heroku or any dedicated server running centos.
At the end of this tutorial you will be running telescope on port 3000 with nginx as proxy.
List of things we will cover in this tutorial
- Install node.js
- Install mongodb
- Install meteor
- Install meteorite
- Install telescope
- Install nginx
Before we start, lets update the system and make sure we have all the development libraries. Run the following commands as root
yum update
yum groupinstall "Development Tools"
Installing node.js and NPM on Centos
Run the following commands. Make takes time, you might wanna get some coffee 🙂
wget http://nodejs.org/dist/v0.10.23/node-v0.10.23.tar.gz
tar xvfz node-v0.10.23.tar.gz
cd node-v0.10.23
./configure
make
sudo make install
You don’t have to install NPM sperately, it’s bundled with the node.
If you get “virtual memory exhausted: Cannot allocate memory” error, try rebooting the system.
Note: You might be tempted to get the latest code from git and install it, but for some reason beyond my understanding at this time, it doesn’t work.
It throws some error related to fibers package.
Error: “pre” versions of node cannot be installed, use –nodedir flag instead
Install MongoDB
Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:
If you are running a 64-bit system, use the following configuration:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/ gpgcheck=0 enabled=1
Issue the following command (as root or with sudo) to install the latest stable version of MongoDB and the associated tools:
yum install mongo-10gen mongo-10gen-server
Install meteor
Installing meteor is very simple, just run the following command
curl https://install.meteor.com | /bin/sh
install meteorite
npm install -g meteorite
Install Telescope
git clone https://github.com/SachaG/Telescope.git
cd Telescope
mrt bundle ~/bundle.tgz
Last command bundles everything we need to run the app and saves it in your home directory.
Before we run the app, we have to reinstall fibers
cd ~/bundle/programs/server
rm -f -r node_modules/fibers
npm install fibers
Now lets start telescope
PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp_db ROOT_URL=http://myappurl.com/ node bundle/main.js
You can change the port to what ever you want, 80 if you do not want to use a proxy server.
ref: https://github.com/SachaG/Telescope
Using NGINX as proxy for Telescope Meteor app
open nginx configuration file, In Centos it’s located at /etc/nginx/nginx.conf
and add this to server section of the file and restart nginx /etc/init.d/nginx restart
location / { proxy_pass http://localhost:3000; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
Having to start the Telescope app manually when ever the system reboots is not cool, lets add it to system startup. We will use upstart for this.
Create a file called my_app.conf
at /etc/init/
and add the following content to it.
start on runlevel [2345] stop on runlevel [06] respawn respawn limit 10 5 script APP_DIR=/absolute/url/to/telescope/bundle LOG_FILE=/var/log/amyapp_log export PORT=3000 export MONGO_URL=mongodb://localhost:27017/myapp_db export ROOT_URL=http://my_app_url/ /usr/local/bin/node "$APP_DIR/main.js" 2>&1 >> $LOG_FILE end script
Are all the required programs in startup list? Lets check if mongodb and nginx are in system startup, if not lets add them.
Check it with the following command
sudo /sbin/chkconfig --list
If they are not, add them with the following command
sudo /sbin/chkconfig mongod on
sudo /sbin/chkconfig nginx on
It’s not optimal to serve static files through node, I tried to serve them with nginx but wasn’t successful. I will update the post, once I find the answer.
You should install phantomjs to make your app crawlable/searchable.
Installing Phantomjs
wget https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2
cp phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/local/bin
You can get the latest and relevant download links from phantomjs downloads page.
If you face any problems during phatomjs installation, try this tutorial
tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2
cp phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/local/bin
Though the entire process takes less than 10 minutes now ( excluding the compile time of node ), It took me more than 2 days to figure everything out. I hope this tutorial tutorial saves your time.
If you find all this complicated but want to build a site with telescope, I’m available for hire :). Shouth News is the first site I built with telescope