====== Setup Performexa ====== ===== Software Versions ===== ruby : 2.2.3 rubygems : 2.4.5 rails : 4.2.4 ===== Install Default developer packages ===== Add below mentioned both entrys 127.0.0.1 server url server url #This was tested in CentOS 6.5. yum install epel-release -y yum update -y yum groupinstall "Development Tools" -y yum groupinstall "Additional Development" -y yum install gcc gcc-c++ make wget libtool libxml libxml-devel libxslt libxslt-devel subversion curl-devel java-1.7.0-openjdk java-1.7.0-openjdk-devel git-core openssl-devel -y yum install ImageMagick ImageMagick-devel -y yum install gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel -y ===== Add appuser ===== useradd -m expdev01 vi /etc/sudoers expdev01 ALL=(ALL) NOPASSWD: ALL ##add this line su - expdev01 ===== Ruby & Rubygems ===== === Using rbenv === a) Install rbenv # Check out rbenv into ~/.rbenv. git clone https://github.com/sstephenson/rbenv.git ~/.rbenv # Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility. echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile # Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile. echo 'eval "$(rbenv init -)"' >> ~/.bash_profile # Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) # Now check if rbenv was set up - type rbenv #=> "rbenv is a function" b) Install rbenv-build git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build c) Install ruby 2.2.3 rbenv install 2.2.3 d) Update rubygems to 2.4.5 rbenv global 2.2.3 #make this version of ruby global rbenv rehash #reload shims gem -v #check the gem version (Most likely this will be 2.4.5.1) gem install rubygems-update update_rubygems gem update --system '2.4.5' mkdir -p ~/.rbenv/plugins git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo ===== Installing MYSQL 5.6.x ===== yum install wget -y wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm rpm -ivh mysql-community-release-el6-5.noarch.rpm yum install mysql-community-server.x86_64 -y /etc/init.d/mysqld start mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit ===== Installing NGINX and Phusion Passenger ===== Install Passenger and Nginx passenger-install-nginx-module copy the nginx.conf file from "/opt/nginx/conf/nginx.conf" from existing machine to the new machine on the same location and change "server_name" and "passenger_pre_start" server_name newqa01.performexa.com; passenger_pre_start "http://newqa01.performexa.com/"; vi /opt/nginx/conf/nginx.conf worker_processes 3; events { worker_connections 4096; multi_accept on; use epoll; } http { passenger_root /home/expdev01/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/passenger-5.0.18; passenger_ruby /home/expdev01/.rbenv/versions/2.2.3/bin/ruby; passenger_min_instances 1; passenger_max_pool_size 3; passenger_pre_start "http://newqa01.performexa.com/"; client_body_buffer_size 10K; client_header_buffer_size 1k; client_max_body_size 8m; large_client_header_buffers 4 32k; client_body_timeout 10; client_header_timeout 10; send_timeout 12; server_tokens off; gzip on; gzip_comp_level 2; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/x-javascript text/xml text/css application/xml; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 15; server { listen 80; server_name newqa01.performexa.com; rewrite ^/?(.*) https://$host/$1 redirect; } server { listen 443 ssl; server_name newqa01.performexa.com; ssl_certificate /opt/nginx/ssl/server.crt; ssl_certificate_key /opt/nginx/ssl/server.key; ssl_prefer_server_ciphers on; ssl_dhparam /etc/pki/tls/private/dhparam.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; passenger_enabled on; passenger_app_env staging; root /deploy/performance/current/public; open_file_cache max=2000 inactive=20s; open_file_cache_valid 60s; open_file_cache_min_uses 5; open_file_cache_errors off; location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } } } ===== SSL Configuration ====== copy the ssl folder from existing machine to the new machine ( which contain ssl certificates) zip -r ssl.zip /opt/nginx/ssl put it into ftp login to the new machine cd /opt/nginx connect to ftp and download the ssl.zip file unzip ssl.zip copy the nginx.conf file from "/opt/nginx/conf/nginx.conf" from existing machine to the new machine on the same location change the old machine name with the newone ===== Installing Ejabberd ===== Download the latest version of Ejabberd from www.process-one.net website, at the time of writing this document 15.07 was the latest. wget "https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/15.07/ejabberd-15.07-linux-x86_64-installer.run" chmod 751 ejabberd-15.07-linux-x86_64-installer.run ./ejabberd-15.07-linux-x86_64-installer.run Do you accept this license? [y/n]: y Installation Directory [/opt/ejabberd-15.07]: ejabberd server domain [newqa01.performexa.com]: newqa01.performexa.com (Specify the Fully qualified name - Hostname) Administrator username [admin]: Administrator password [********] : Retype password [********] : Cluster [y/N]: n Do you want to continue? [Y/n]: y ---------------------------------------------------------------------------- Please wait while Setup installs ejabberd on your computer. Installing 0% ______________ 50% ______________ 100% ######################################### ---------------------------------------------------------------------------- cd /opt/ejabberd-15.07/bin cp ejabberd.init /etc/init.d/ejabberd /etc/init.d/ejabberd start === Configure ejabberd === 1. Change the config settings. Config file can be found in your ejabberd directory under conf (ex - /opt/ejabberd-15.07/conf/ejabberd.yml) Change "register:" (around line 481) register: all: allow registration_timeout: infinity Change "registration_timeout:" (around line 494) registration_timeout: infinity //(yaml file level) Enable "mod_ping" mod_ping: send_pings: true ping_interval: 250 timeout_action: none 2. Start/Restart ejabberd 3. Create a shared roster for every one. {{:shared_roster_all.png|Screenshot with information}} 4. Add a host entry for the IP pointing to the URL. ====== ejjaberd configuration ============ vi /opt/ejabberd-15.07/conf/ejabberd.yml 1) insert the below lines on line number 161 under "http_bind: true" ( search for "http_bind: true") ******************************************************************************************************* tls: true certfile: "/opt/ejabberd-15.07/conf/server.pem" 2) uncomment and do the changes in Line No: 171 from "optional" to "required" ****************************************************************************** s2s_use_starttls: required 3) uncomment the below mentioned line in Line No: 176 ********************************************************* s2s_certfile: "/opt/ejabberd-15.07/conf/server.pem" 4) set the value for "max_fsm_queue: 25000" in Line No : 375 ************************************************************** max_fsm_queue: 25000 5) search for "register:" in Line No: 483 and place the below line under "all: allow" *************************************************************************************** registration_timeout: infinity 6) search for "By default the frequency of account registrations from the same IP is limited to 1 account every 10 minutes. To disable, specify: infinity" and place the below mentioned line in Line No:496 ******************************************************************************************************************************* registration_timeout: infinity 7) search for "mod_ping:" and do the below changes in Line No: 574 ( Hint : remove "[]" in mod_ping ) ******************************************************************************************************* mod_ping: send_pings: true ping_interval: 120 timeout_action: none ============ ejjaberd SSL certificate update ============ Generate the server.pem file **************************** cd /opt/nginx/ssl cat server.crt server.key > server.pem cd /opt/ejabberd-15.07/conf mv server.pem ejabbert-original-server.pem cp /opt/nginx/ssl/server.pem . cd /opt/ejabberd-15.07/conf chmod 640 server.pem chown -R ejabberd:root server.pem ===== Install the gems used by the application ===== gem install capistrano -v 3.4.0 gem install capistrano-bundler -v 1.1.4 gem install capistrano-ext -v 1.2.1 gem install capistrano-log_with_awesome -v 0.0.2 gem install capistrano-passenger -v 0.2.0 gem install capistrano-rails -v 1.1.6 gem install capistrano-rbenv -v 2.0.4 gem install capistrano-stats -v 1.1.1 gem install god -v 0.13.7 mkdir /var/run/god/ chown -R expdev01:expdev01 /var/run/god To Install mysql2 (Interface) ******************************** gem install mysql2 -v '0.3.20' The Application uses bundler gem to manage the gem dependencies. Install the bundler gem first. sudo gem install bundler Once the bundler gem is installed, from the application directory (eg: /deploy/crossbow/current), run bundle install This would install all the necessary gems required by the application. === Deploy Application: === mkdir -p /deploy/performance/current cd /deploy mkdir systasks cd /deploy/performance mkdir backups mkdir shared mkdir releases cd /home/expdev01 Issue the command from /home/expdev01 to download the configuration files from SVN for performexa staging site **************************************************************************************************************** svn co https://repos.exphosted.com/svnrepos/tools/scripts/performexa/deployment/staging/performance/ cp -r /home/expdev01/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0 /deploy/performance/shared/bundle/ruby/ cd /home/expdev01/performance ./runcap.sh copy the build folder from "/home/expdev01/" to "/deploy/performance/releases/" ( eg "1.0.9.0-JACK" folder) ************************************************************************************************************** cp -r /home/expdev01/1.0.9.0-JACK /deploy/performance/releases/ cd /deploy/performance ln -s current /deploy/performance/releases/1.0.9.0-JACK/ cd /deploy/performance/releases/1.0.9.0-JACK/config mv api.yml bkp-api.yml mv newrelic.yml bkp-newrelic.yml mv database.yml bkp-database.yml mv chat.yml bkp-chat.yml mv environments bkp-environments copy the following files from "/deploy/performance/releases/1.0.9.0-JACK/config" directory to "/deploy/performance/shared/config" ********************************************************************************************************************************* cd /deploy/performance/releases/1.0.9.0-JACK/config cp api.yml /deploy/performance/shared/config cp database.yml /deploy/performance/shared/config cp chat.yml /deploy/performance/shared/config cp newrelic.yml /deploy/performance/shared/config cp -r environments /deploy/performance/shared/config Add the following in "api.yml" ( e.g - In my case it is staging ) ****************************************************************** vi api.yml staging: doorkeeper_token_expire_time: <%= 30.days %> enabled_for_subsites: false enabled: true Change the Database name and credentials for staging ***************************************************** default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: Expertus1@ host: localhost production: <<: *default database: production staging: <<: *default database: performance_staging development: <<: *default database: performance_development01 #test: # <<: *default # database: performance_development Do the changes (server, bosh , websocket , admin_jid and admin_password in staging block in chat.yml) ***************************************************************************************************** staging: server: https://newqa01.performexa.com:5280 bosh: https://newqa01.performexa.com:5280/http-bind websocket: wss://newqa01.performexa.com:5280/websocket domain: newqa01.performexa.com enabled: true create_xmpp_user: true reconnect_timeout: 10000 admin_jid: admin@newqa01.performexa.com admin_password: Expertus1@ push_notifications: true stun: { host : 'stun.services.mozilla.com', port : 3478, transport : 'udp' } test: server: http://qa01.performexa.com:5280 websocket: ws://qa01.performexa.com:5280/websocket domain: qa01.performexa.com bosh: http://qa01.performexa.com:5280/http-bind enabled: false create_xmpp_user: false production: server: http://qa01.performexa.com:5280 websocket: ws://qa01.performexa.com:5280/websocket domain: qa01.performexa.com bosh: http://qa01.performexa.com:5280/http-bind enabled: false create_xmpp_user: false Do the changes in "/deploy/performance/releases/1.0.9.0-JACK/config/environments/staging.rb" ********************************************************************************************* APP_URL = "https://newqa01.performexa.com" API_URL = "https://newqa01.performexa.com" AUTHENTICATION_URL = "https://newqa01.performexa.com" Create a symlink from "/deploy/performance/shared/config" directory ******************************************************************** cd /deploy/performance/shared/config/ ln -s /deploy/performance/shared/config/api.yml ln -s /deploy/performance/shared/config/database.yml ln -s /deploy/performance/shared/config/chat.yml ln -s /deploy/performance/shared/config/newrelic.yml ln -s /deploy/performance/shared/config/environments ===== god configuration ===== copy "/etc/init.d/god" script from qa01.performexa.com and paste into the same location with "newqa01.performexa.com" and changed the ownership of the file file to "expdev01" chown -R expdev01:expdev01 /etc/init.d/god chmod 755 /etc/init.d/god check out the god.sh from the below svn link execute the below command from /deploy/systasks cd /deploy/systasks svn co https://repos.exphosted.com/svnrepos/tools/scripts/performexa/services/staging/god.sh . change the ownership and permission chown -R expdev01:expdev01 /deploy/systasks/god.sh chmod 755 /etc/init.d/god start the god service /etc/init.d/god start ===== Install the gems used by the application ===== The Application uses bundler gem to manage the gem dependencies. Install the bundler gem first. sudo gem install bundler Once the bundler gem is installed, from the application directory (eg: /deploy/crossbow/current), run bundle install This would install all the necessary gems required by the application. bundle install will end with this message: Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. ===== Database creation and loading seed data ===== Modify the database.yml file to reflect proper DB settings in development and test section and then run following rake task to create all the databases. bundle exec rake db:create:all Once the DBs are created run the migrations to create necessary tables using following command. bundle exec rake db:migrate bundle exec rake db:migrate RAILS_ENV=test Run rake db:seed to create the default company and related data (This is just one time task) bundle exec rake db:seed The default company will be created with name 'Performexa' and subdomain as 'default'. No subdomain in url will refer to default company. e.g. http://dev01.performexa.com will take default company as a context. An admin user for the default company will also be created. The username for admin user is 'admin@performexa.com' and password is 'pforperformance'.