User:CSammy/Installation/CentOS/6

From diaspora* project wiki
< User:CSammy
Revision as of 16:36, 17 April 2014 by Bizna (talk | contribs) (The diaspora user needs to be created before you start the nginx service or else it would not start.)
NoteNote:This guide does not follow our preferred scheme, so don't be surprised if it's partly outdated or wrong

So, here are the steps I followed to get it up and running for CentOS 6.4. This is an entirely fresh/clean install of CentOS 6.4. Nothing else is running on this box, and this tutorial covers all that needs to be installed.

First step is to install CentOS 6.4 with the base/minimal install. Please follow other instructions to do this if you don't know how.


Perform an update to ensure you've got the latest of everything in the base package.

yum update

Install wget so you can download a few things.

yum install wget

Allow yum to locate/install redis, per this page here.

http://thoughts.z-dev.org/2013/05/27/install-redis-on-centos-6-4/

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm"

Now, install all the prerequisites

yum install tar make automake gcc gcc-c++ git net-tools libcurl-devel libxml2-devel libffi-devel libxslt-devel tcl redis ImageMagick npm mysql-server mysql-devel nginx libyaml libyaml-devel patch readline-devel libtool bison

Enable and start MySQL

chkconfig --level 3 mysqld on
service mysqld start

Secure your MySQL installation by setting a password. replace 'new-password' with your secure password.

mysqladmin -u root password 'new-password'
mysqladmin -u root -h YourHost.YourDomain.com password 'new-password'

Open up the necessary firewall ports

vi /etc/sysconfig/iptables
  copy this line.
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  and add two more with port 80 & 443 as well
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Restart the firewall

service iptables restart

Configure Nginx

Next, modify the nginx configuration based on this advice I found on here. https://github.com/diaspora/diaspora/wiki/Nginx-Configuration Be sure to follow all the FIXME instructions, including replacing "example.com" with your domain name. You may also need to create a key and csr to obtain a signed SSL certificate. That part is not covered here.

vi /etc/nginx/nginx.conf
-- contents of nginx.conf --

worker_processes 1;
user diaspora;

events {
    worker_connections 1024;
}

#
# FIXME: You may wish to modify the value of the `log_format` directive
# below if you are not using Splunk
#
http {

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    #
    # FIXME: If using thin app server, specify correct number of thin servers
    # below, otherwise comment out and replace with your own solution
    #
    # In case of unicorn - master opens a unix domain socket
    #upstream unicorn {
    #     server unix:/var/run/sockets/unicorn.sock;
    #}

    upstream thin_cluster {
        server localhost:3000;
    }

    #
    # FIXME: specify correct value(s) for `server_name` directive and
    # correct domain name in the `rewrite` directive below
    #
    server {
        listen 80;
        server_name example.com www.example.com;
        rewrite ^(.*) https://example.com$1 permanent;
    }

    #
    # FIXME: specify correct value(s) for `server_name` directive and
    # `ssl_certificate` + `ssl_certificate_key` directives below
    #
    server {
        listen 443;
        server_name example.com www.example.com;
        ## make sure you change location if you did clone into /usr/local/app
        root /home/diaspora/diaspora/public;

        ssl on;
        ssl_certificate /path/to/cert_location;
        ssl_certificate_key /path/to/key_location;
        # enable better ssl security if you like to mitigate BEAST and other exploits
        #ssl_session_cache shared:SSL:10m;
        #ssl_session_timeout 5m;
        #ssl_protocols TLSv1;
        #ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM;
        #ssl_prefer_server_ciphers on;
        #add_header Strict-Transport-Security max-age=500;
        #ssl_ecdh_curve secp521r1;

        location /uploads/images {
            expires 1d;
            add_header Cache-Control public;
        }
        location /assets {
            expires 1d;
           add_header Cache-Control public;
        }

        #
        # FIXME: modify the `rewrite` directive below to point to proper S3 bucket
        # and path or comment out if you will store images on local file system
        #
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_redirect off;
            client_max_body_size 4M;
            client_body_buffer_size 128K;

            if (-f $request_filename/index.html) {
                rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename.html) {
                rewrite (.*) $1.html break;
            }
            if (!-f $request_filename) {
                proxy_pass http://thin_cluster;
                break;
            }
            #if you switch to a s3 bucket you can redirect old links to the s3
            #rewrite ^/uploads/images/(.*)$ https://example.com/s3bucket/s3path/$1 permanent;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }

}
-- end of contents of nginx.conf --

Create the diaspora user

useradd diaspora
passwd diaspora

Enable and activate nginx web server.

chkconfig --level 3 nginx on
service nginx start

Enable and activate redis service.

chkconfig --level 3 redis on
service redis start

Run all future commands as diaspora user

su -l diaspora

Install RVM - Per instructions here. http://rvm.io/

curl -L https://get.rvm.io
vi .bashrc
-- begin add to .bashrc --
[[ -s "~/.rvm/scripts/rvm" ]] && source "~/.rvm/scripts/rvm"
-- end add to .bashrc --
:wq <- to save and exit

Logout and back into the diaspora user account

exit
su -l diaspora
$ rvm autolibs read-only
Install the version of ruby wanted by Diaspora (installing latest version will not work)
$ rvm install 1.9.3-p448

Install Diaspora*

git clone -b master git://github.com/diaspora/diaspora.git
cd diaspora

Answer y[es] to the prompt about switching to '.ruby-version'

Copy the base configuration files.

cp config/database.yml.example config/database.yml
cp config/diaspora.yml.example config/diaspora.yml

Now open config/database.yml and config/diaspora.yml in your favorite text editor and carefully review them, they are extensively commented.

Important values in config/diaspora.yml

environment.url: Set the public facing URL to your pod here, for example for https://pod.geraspora.de this would be https://pod.geraspora.de environment.certificate_authorities: You have to set this, one of the examples should fit. If the file in the example doesn't exist you're missing a package, in most cases it's named ca-certificates. server.rails_environment: You must set this to production. The server section is read by ./script/server and most alternative startup methods to setup the correct environment. environment.require_ssl: If for some reason you can't run your pod on HTTPS (we highly encourage you to do it!), set this to false to prevent a redirect from http:// to https://

It's time to install the Ruby libraries required by Diaspora:

# RAILS_ENV=production bundle install --without test development

Double check your config/database.yml looks right and run:

RAILS_ENV=production bundle exec rake db:create db:schema:load

Precompile assets

RAILS_ENV=production bundle exec rake assets:precompile

It's time to start Diaspora:

./script/server

Template:Languages