Showing posts with label install. Show all posts
Showing posts with label install. Show all posts

Monday 9 March 2015

Setup HAProxy (loadbalancing) on CentOS7

This guide looks into how to setup HAProxy on CentOS7. HAProxy offers load balanced services to HTTP and TCP-based services, such as internet-connected services and web-based applications.

In Apr 2013, we looked into how to Setup Load-Balancing Cluster with LVS and Piranha on Centos 6. This time round for CentOS7, we will setup HAProxy Loadbalancing Cluster as this is shipped with CentOS7.

Setup:
1. HAProxy Server at 192.168.1.3
2. LB Virtual IP to use 192.168.1.3
3. Web1 at 192.168.1.9
4. Web2 at 192.168.1.10

For all the servers, lets (temporary) remove the firewall and selinux.
systemctl stop firewalld
systemctl disable firewalld
vi /etc/selinux/config
disabled
reboot
Lets start, login to HAProxy Server:
yum install haproxy
vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend LB
   bind 192.168.1.3:80
   reqadd X-Forwarded-Proto:\ http
   default_backend LB

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend LB 192.168.1.3:80
   mode http
   stats enable
   stats hide-version
   stats uri /stats
   stats realm Haproxy\ Statistics
   stats auth admin:pass4325    # HAProxy Statistic username/password
   balance roundrobin           # Load balancing to use round-robin
   option httpchk
   option httpclose
   option forwardfor
   cookie LB insert
   server web1 192.168.1.9:80  check  # backend server.
   server web2 192.168.1.10:80 check  # backend server.
We shell enable the service and start the service:
systemctl enable haproxy
systemctl start haproxy
At Webserver create a test page.
vi /var/www/html/p.html
192.168.1.9 (To display Webserver IP address)
systemctl restart httpd
To access the statistic page, navigate to the HAProxy ip/stats,login with the username and pass as states in haproxy.cfg.

Friday 27 February 2015

Install MongoDB with PHP on Fedora

MongoDB is an open-source database used by companies of all sizes, across all industries and for a wide variety of applications. It is an agile database that allows schemas to change quickly as applications evolve, while still providing the functionality developers expect from traditional databases, such as secondary indexes, a full query language and strict consistency.

This tutorial looks into how to install latest MongoDB with PHP on Fedora.

Create a /etc/yum.repos.d/mongodb.repo file:
vi /etc/yum.repos.d/mongodb.repo
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
else for 32-bit system, use:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1
To install the latest stable version of MongoDB, issue the following command:
yum install -y mongodb-org
Install php,mongo driver:
pecl install mongo
create a mongo (php) ini
vi /etc/php.d/mongo.ini
And include the driver:
extension=mongo.so
Enable mongod on startup
systemctl enable mongod
start mongod:
service mongod start
Open mongo client to test.
mongo
create database test:
use test
Lets do an insert:
db.collection1.insert({"name":"desc"})
And lets do an query:
db.collection1.find();
Lets proceed with using mongodb in php. Restart php-fpm:
systemctl restart php-fpm.service
We shell create a php script:
<?php
$connection = new Mongo();
$dbname = $connection->selectDB('test');
$collection = $dbname->collection1;
$arr = array(
        'name' => 'MongoDB',
        'desc' => 'MongoDB is a document database.'
);
$collection->insert($arr);
$result = $collection->find();
foreach ($result as $document) {
        echo $document["name"]."\n";
        echo $document["desc"]."\n";
}
?>
You can run above script in web server or just run:
php test_mongo.php

Monday 16 February 2015

Install latest Redis cache

Redis is an open source advanced key-value cache. It is high performance and often compared to memcached.

This post we look into how to install latest Redis cache onto (say) Fedora 21. It is quite simple, and lets start:

Goto http://redis.io/download, and download latest version using wget.
wget http://download.redis.io/releases/redis-2.8.19.tar.gz
untar/unzip the package
tar -xzvf redis-2.8.19.tar.gz
compile the bundle
cd redis-2.8.19
make
It is good to do a "make test" to test the functionality on your system. For this test you need tcl.

If you don't have tcl, install it by:
yum install tcl
Run make test:
make test
If functionality test passed it will show:
\o/ All tests passed without errors!
Lets install the excutables into /usr/local/bin/.
make install
For Fedora systemctl system, lets create a redis service script.
vi /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf --daemonize no
ExecStop=/usr/local/bin/redis-shutdown
User=redis
Group=redis

[Install]
WantedBy=multi-user.target
Move sample redis.conf to /etc.
cp /root/download/redis-2.8.19/redis.conf /etc/redis.conf
Create redis-shutdown script.
vi /usr/local/bin/redis-shutdown
#!/bin/bash
#
# Wrapper to close properly redis and sentinel
test x"$REDIS_DEBUG" != x && set -x

REDIS_CLI=/usr/local/bin/redis-cli

# Retrieve service name
SERVICE_NAME="$1"
if [ -z "$SERVICE_NAME" ]; then
   SERVICE_NAME=redis
fi

# Get the proper config file based on service name
CONFIG_FILE="/etc/$SERVICE_NAME.conf"

# Use awk to retrieve port from config file
PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE`

# Just in case, use default port
if [ "$SERVICE_NAME" = redis ]; then
    PORT=${PORT:-6379}
else
    PORT=${PORT:-26739}
fi

# shutdown the service properly
$REDIS_CLI -p $PORT SHUTDOWN NOSAVE
Enable and start redis service.
systemctl enable redis.service
systemctl start redis.service
Lets try the redis-cli. Set a key and get a key:
[root@fc21 temp]# redis-cli
127.0.0.1:6379> get key1
(nil)
127.0.0.1:6379> set key1 value1
OK
127.0.0.1:6379> get key1
"value1"

Thursday 29 January 2015

Install Nginx (and PHP) server on Fedora

Nginx [engine x] is a free high-perfomance HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev.

Lets start the installation process:
Stop and disable existing apache.

# systemctl stop httpd.service
# systemctl disable httpd.service 

Install php-fpm

# yum install php-fpm -y

Enable and start php-fpm service:

# systemctl enable php-fpm.service
# systemctl start php-fpm.service

To install Nginx

# yum install nginx -y

Enable and start Nginx service

# systemctl enable nginx.service
# systemctl start nginx.service

Test Nginx

Open up your web browser and navigate to http://localhost/ (example). You will see the default nginx welcome screen.

Configure Nginx

Open the file /etc/nginx/nginx.conf in vi

# vi /etc/nginx/nginx.conf

Set the worker_processes (No. Of CPU’s in your system you want to utilise). To see the no. Of CPU’s, you can use the command “lscpu”. For default you can set to 1.
worker_processes 1;

Example of working nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    index   index.html index.htm;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    #Change below value to suit your need:
    fastcgi_read_timeout 6000s;

    server {
        listen       80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page  404              /404.html;
        location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }

        location ~ [^/]\.php(/|$) {
           fastcgi_split_path_info ^(.+?\.php)(/.*)$;
           if (!-f $document_root$fastcgi_script_name) {
              return 404;
           }

           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           include fastcgi_params;           
        }
    }
}

Save and close the file. Restart Nginx service:

# systemctl restart nginx.service

Test PHP

Create a sample “phpinfo.php” file in the nginx document root folder:

# vi /usr/share/nginx/html/phpinfo.php

Append the lines as shown below:



Save and close the file. Restart Nginx service:

# systemctl restart nginx.service

Navigate to http://localhost/testphp.php (example). It will display all the details about PHP,build,setups.

Monday 24 November 2014

How to install an IRC server on Fedora 20 (ngircd)

Below instructions are steps to install ngircd(IRC) server on Fedora 20.

ngIRCd is a free, portable and lightweight Internet Relay Chat server for small or private networks, developed under the GNU General Public License (GPL). It is easy to configure, can cope with dynamic IP addresses, and supports IPv6, SSL-protected connections as well as PAM for authentication. It is written from scratch and not based on the original IRCd. The steps:

Install server:
[root@localhost ~]# yum install ngircd
Edit config file:
[root@localhost ~]# vi /etc/ngircd.conf
# $Id$

#
# This is a sample configuration file for the ngIRCd, which must be adepted
# to the local preferences and needs.
#
# Comments are started with "#" or ";".
#
# A lot of configuration options in this file start with a ";". You have
# to remove the ";" in front of each variable to actually set a value!
# The disabled variables are shown with example values for completeness.
#
# Use "ngircd --configtest" (see manual page ngircd(8)) to validate that the
# server interprets the configuration file as expected!
#

[Global]
        # The [Global] section of this file is used to define the main
        # configuration of the server, like the server name and the ports
        # on which the server should be listening.

        # Server name in the IRC network, must contain at least one dot
        # (".") and be unique in the IRC network. Required!
        Name = irc.the.net

        # Info text of the server. This will be shown by WHOIS and
        # LINKS requests for example.
        Info = Server Info Text

        # Global password for all users needed to connect to the server
        ;Password = abc

        # Information about the server and the administrator, used by the
        # ADMIN command. Not required by server but by RFC!
        ;AdminInfo1 = Description
        ;AdminInfo2 = Location
        ;AdminEMail = admin@irc.server

        # Ports on which the server should listen. There may be more than
        # one port, separated with ",". (Default: 6667)
        ;Ports = 6667, 6668, 6669

        # comma seperated list of IP addresses on which the server should
        # listen. Default values are:
        # "0.0.0.0" or (if compiled with IPv6 support) "::,0.0.0.0"
        # so the server listens on all IP addresses of the system by default.
        Listen = 127.0.0.1,192.168.5.51

        # Text file with the "message of the day" (MOTD). This message will
        # be shown to all users connecting to the server:
        ;MotdFile = /etc/ngircd.motd

        # A simple Phrase (<256 chars) if you don't want to use a motd file.
        # If it is set no MotdFile will be read at all.
        MotdPhrase = "Hello world!"

        # User ID under which the server should run; you can use the name
        # of the user or the numerical ID. ATTENTION: For this to work the
        # server must have been started with root privileges! In addition,
        # the configuration and MOTD files must be readable by this user,
        # otherwise RESTART and REHASH won't work!
        ServerUID = ngircd

        # Group ID under which the ngircd should run; you can use the name
        # of the group or the numerical ID. ATTENTION: For this to work the
        # server must have been started with root privileges!
        ServerGID = ngircd

        # A directory to chroot in when everything is initialized. It
        # doesn't need to be populated if ngIRCd is compiled as a static
        # binary. By default ngIRCd won't use the chroot() feature.
        # ATTENTION: For this to work the server must have been started
        # with root privileges!
        ;ChrootDir = /var/empty

        # This tells ngircd to write its current process id to a file.
        # Note that the pidfile is written AFTER chroot and switching uid,
        # i. e. the Directory the pidfile resides in must be writeable by
        # the ngircd user and exist in the chroot directory.
        PidFile = /var/run/ngircd/ngircd.pid

        # After  seconds of inactivity the server will send a
        # PING to the peer to test whether it is alive or not.
        ;PingTimeout = 120

        # If a client fails to answer a PING with a PONG within 
        # seconds, it will be disconnected by the server.
        ;PongTimeout = 20

        # The server tries every  seconds to establish a link
        # to not yet (or no longer) connected servers.
        ;ConnectRetry = 60

        # Should IRC Operators be allowed to use the MODE command even if
        # they are not(!) channel-operators?
        ;OperCanUseMode = no

        # Mask IRC Operator mode requests as if they were coming from the
        # server? (This is a compatibility hack for ircd-irc2 servers)
        ;OperServerMode = no

        # Allow Pre-Defined Channels only (see Section [Channels])
        PredefChannelsOnly = yes

        # Don't do any DNS lookups when a client connects to the server.
        ;NoDNS = no

        # try to connect to other irc servers using ipv4 and ipv6, if possible
        ;ConnectIPv6 = yes
        ConnectIPv4 = yes

        # Maximum number of simultaneous connection the server is allowed
        # to accept (0: unlimited):
        MaxConnections = 0

        # Maximum number of simultaneous connections from a single IP address
        # the server will accept (0: unlimited):
        ;MaxConnectionsIP = 5

        # Maximum number of channels a user can be member of (0: no limit):
        MaxJoins = 10

        # Maximum length of an user nick name (Default: 9, as in RFC 2812).
        # Please note that all servers in an IRC network MUST use the same
        # maximum nick name length!
        ;MaxNickLength = 9

[Operator]
        # [Operator] sections are used to define IRC Operators. There may be
        # more than one [Operator] block, one for each local operator.

        # ID of the operator (may be different of the nick name)
        ;Name = TheOper

        # Password of the IRC operator
        ;Password = ThePwd

        # Optional Mask from which /OPER will be accepted
        ;Mask = *!ident@somewhere.example.com

[Operator]
        # More [Operator] sections, if you like ...

[Server]
        # Other servers are configured in [Server] sections. If you
        # configure a port for the connection, then this ngircd tries to
        # connect to to the other server on the given port; if not it waits
        # for the other server to connect.
        # There may be more than one server block, one for each server.
        #
        # Server Groups:
        # The ngIRCd allows "server groups": You can assign an "ID" to every
        # server with which you want this ngIRCd to link. If a server of a
        # group won't answer, the ngIRCd tries to connect to the next server
        # in the given group. But the ngircd never tries to connect to two
        # servers with the same group ID.

        # IRC name of the remote server, must match the "Name" variable in
        # the [Global] section of the other server (when using ngIRCd).
        Name = irc2.the.net

        # Internet host name or IP address of the peer (only required when
        # this server should establish the connection).
        ;Host = connect-to-host.the.net

        # IP address to use as _source_ address for the connection. if unspecified,
        # ngircd will let the operating system pick an address.
        Bind = 192.168.5.51

        # Port of the server to which the ngIRCd should connect. If you
        # assign no port the ngIRCd waits for incoming connections.
        Port = 6667

        # Own password for the connection. This password has to be configured
        # as "PeerPassword" on the other server.
        ;MyPassword = def

        # Foreign password for this connection. This password has to be
        # configured as "MyPassword" on the other server.
        ;PeerPassword = ghi

        # Group of this server (optional)
        ;Group = 123

        # Set the "Passive" option to "yes" if you don't want this ngIRCd to
        # connect to the configured peer (same as leaving the "Port" variable
        # empty). The advantage of this option is that you can actually configure
        # a port an use the IRC command CONNECT more easily to manually connect
        # this specific server later.
        ;Passive = no

[Server]
        # More [Server] sections, if you like ...

[Channel]
        # Pre-defined channels can be configured in [Channel] sections.
        # Such channels are created by the server when starting up and even
        # persist when there are no more members left.
        # Persistent channels are marked with the mode 'P', which can be set
        # and unset by IRC operators like other modes on the fly.
        # There may be more than one [Channel] block, one for each channel.

        # Name of the channel
        Name = #TheName

        # Topic for this channel
        Topic = a great topic

        # Initial channel modes
        Modes = tn

        # initial channel password (mode k)
        Key =

        # maximum users per channel (mode l)
        MaxUsers = 23

[Channel]
        # More [Channel] sections, if you like ...
Enable Server on boot:
[root@localhost ~]# systemctl enable ngircd
Start irc service:
[root@localhost ~]# service ngircd start

As for IRC client to use, I am using Nettalk. It is a free (open source) IRC-client. Cheers...

Friday 24 October 2014

How To Install MySQL On CENTOS 7

Below instructions are steps to install mysql server on CentOS 7.

The default replacement for mysql server is MariaDB. MariaDB is a community-developed fork of the MySQL relational database management system. For whatever reasons you might like to install the previous MySQL server, this guide walk you through the process of the installation. The steps:

Setup MySQL repository
[root@localhost ~]# sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Install Server:
[root@localhost ~]# yum install mysql-server
Start Server:
[root@localhost ~]# systemctl start mysqld
Enable Server on boot:
[root@localhost ~]# systemctl enable mysqld
Change root password:
[root@localhost ~]# mysqladmin -u root password

Wednesday 3 April 2013

Install memcache on CENTOS6


This guide will explain how to install memcache.

To install the server:

yum search memcached
yum install memcached php-pear
chkconfig memcached on
service memcached start

To install php,pecl,memcache extension:

pecl search memcache

The latest stable version is memcache 2.2.7.

You need to install dependencies before installing memcache:
yum install php-devel gcc zlib zlib-devel
To install php extension:
pecl install memcache

Insert the extension in php.ini:
vi /etc/php.ini

Insert below line to php.ini:
extension=memcache.so


To create php test script:

vi /var/www/html/memcache.php

<?php

$memcache = new Memcache;
$memcache->;connect('127.0.0.1', 11211) or die ("Cannot connect");

$version = $memcache->getVersion();
echo "Version: ".$version."
\n"; $tmp_object = new stdClass; $tmp_object->test1 = 'value1'; $tmp_object->test2 = 472; $memcache->set('key', $tmp_object, false, 20) or die ("Cannot save data"); echo "Stored data in the memcache for 20 seconds
\n"; $get_result = $memcache->get('key'); echo "Data from the cache:
\n"; var_dump($get_result); ?>

Tuesday 2 April 2013

Install the latest mysql server on CENTOS6

How to install the latest mysql server on CENTOS6? CENTOS6 shipped with mysql server 5.1.67 version. To install latest mysql server 5.6.10, you can download the rpm from mysql official download site, and install the rpm individually.

Firstly, navigate to "http://www.mysql.com/downloads/mysql/#downloads" , choose "Oracle and Red Hat Linux 6". Download the rpms as shown below:

wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/


Then use md5sum, to check md5 hash on the download site:

md5sum MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm
md5sum MySQL-server-5.6.10-1.el6.x86_64.rpm
md5sum MySQL-shared-5.6.10-1.el6.x86_64.rpm
md5sum MySQL-client-5.6.10-1.el6.x86_64.rpm

If the md5 hash is ok, we can install the rpm in following sequence:

rpm -Uvh MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm
rpm -ivh MySQL-shared-5.6.10-1.el6.x86_64.rpm
rpm -ivh MySQL-server-5.6.10-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.10-1.el6.x86_64.rpm

To turn mysql on when boot:
chkconfig mysql on


To start the mysql service:
service mysql start


To obtain the temporary password:
cat /root/.mysql_secret


To change the mysql root password:
mysqladmin -uroot -p password


Login to the newly installed server using its client:
mysql -uroot -p
These are the steps to install latest mysql on CENTOS. Cheers!

Tuesday 26 March 2013

Upgrade mysql (5.1) to mysql55 on CENTOS6

To upgrade from mysql (default ver 5.1) to mysql55 (IUS ver 5.5):

Replace residual mysql component to mysql55:
[root@localhost ~]# yum replace mysql-libs --replace-with mysql55


Install server and client:
[root@localhost ~]# yum install mysql55-server mysql55


Start server upon reboot:
[root@localhost ~]# chkconfig mysqld on 


Start server service:
[root@localhost ~]# service mysqld start


Change root password:
[root@localhost ~]# mysqladmin -u root password

search iomeweekly