A Linux blog by ioMeWeekly, includes tutorials, news, help, programming, tips and how-to guides for opensource applications.
Monday, 30 March 2015
Automatic WAN failover (Multiple WAN) using ClearOS
In this tutorial, we look into how to configure Automatic Failover of 2 WAN Network using ClearOS.
Setup:
2 Internet Links (WAN)
1 LAN Link
Note: For ClearOS, you will need to have at least 1GB of ram.
Insert the DVD rom and lets start:
Install or upgrade an existing system
Install with Basic Storage Device.
Enter your root password twice.
It will take a while to copy the system files.
After it is done, let it reboot.
Login using the root credentials setup earlier.
At install wizard,click on next,and select Gateway Mode,click next.
eth0: External,DHCP,isp1.domain.lan
eth1: External,DHCP,isp2.domain.lan
eth2: LAN,Static,192.168.4.1,255.255.255.0,Enable DHCP Server
DNS Servers: Next,configure your DNS.
Select Support Edition: You can choose Community Edition or Professional Edition.
Software updates: Let it update its latest software.
System Registration: If you have an account, enter the login details. If you do not have, you can create an account.
Internet domain: Enter your domain.
Hostname: Enter your hostname.
Date and Time: Sync your time
Getting Started: Click Next
App Selection: Click Next
App Review: Click Next
Down and Install: Click Next
After above setup, the LAN link will act as a gateway, routing thru active link 1 or 2.
Have a try and let me know if it works for you.
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.
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
rebootLets 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 haproxyAt Webserver create a test page.
vi /var/www/html/p.html
192.168.1.9 (To display Webserver IP address)
systemctl restart httpdTo access the statistic page, navigate to the HAProxy ip/stats,login with the username and pass as states in haproxy.cfg.
Labels:
Centos7
,
HAproxy
,
install
,
LoadBalancer
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.repoIf 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=1else for 32-bit system, use:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/ gpgcheck=0 enabled=1To install the latest stable version of MongoDB, issue the following command:
yum install -y mongodb-orgInstall php,mongo driver:
pecl install mongocreate a mongo (php) ini
vi /etc/php.d/mongo.iniAnd include the driver:
extension=mongo.soEnable mongod on startup
systemctl enable mongodstart mongod:
service mongod startOpen mongo client to test.
mongocreate database test:
use testLets 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.serviceWe 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
Tuesday, 17 February 2015
Benchmark redis 2.8.19 with memcache 1.4.22
Having read a few articles on comparing redis with memcache. I decided to benchmark myself.
My setup:
Fedora 21,Nginx 1.6.2,redis 2.8.19,memcache 1.4.22,php-fpm 5.6.4.
My Benchmark script(php)
<?php ################# redis ################################################### $k=0; $t_time=0; echo "Benchmark redis : "; $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $original_string = 'abcdefghijklmnopqrstuvwxyz'; for ($i=0;$i<=10000;$i++){ $random_string = get_random_string($original_string, 10); $random_string2 = get_random_string($original_string, 10); $a1[$i]=$random_string; $a2[$random_string]=$random_string2; } $tstart=timer_start(); for ($i=0;$i<=10000;$i++){ $redis -> set($a1[$i],$a2[$a1[$i]]); } $t_time=timer_end($tstart); echo "Total Set time: ".$t_time."
"; for ($j=0;$j<10;$j++){ $tstart=timer_start(); for ($i=0;$i<=10000;$i++){ $value=$redis -> get($a1[$i]); } $t_time=timer_end($tstart); echo "Loop $j (Get) time: ".$t_time."
"; $k=$k+$t_time; } echo "Total 10 loop Get time $k
"; ################# memcache ################################################### $k=0; $t_time=0; echo "Benchmark memcache : "; $memcache = new Memcache; $memcache->connect('127.0.0.1', 11211) or die ("Cannot connect"); $original_string = 'abcdefghijklmnopqrstuvwxyz'; for ($i=0;$i<=10000;$i++){ $random_string = get_random_string($original_string, 10); $random_string2 = get_random_string($original_string, 10); $a1[$i]=$random_string; $a2[$random_string]=$random_string2; } $tstart=timer_start(); for ($i=0;$i<=10000;$i++){ $memcache->set($a1[$i], $a2[$a1[$i]], false, 20) or die ("Cannot save data"); } $t_time=timer_end($tstart); echo "Total Set time: ".$t_time."
"; for ($j=0;$j<10;$j++){ $tstart=timer_start(); for ($i=0;$i<=10000;$i++){ $value = $memcache->get($a1[$i]); } $t_time=timer_end($tstart); echo "Loop $j (Get) time: ".$t_time."
"; $k=$k+$t_time; } echo "Total 10 loop Get time $k
"; function timer_start() { $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; return $time; } function timer_end($start) { $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; return $time-$start; } function get_random_string($valid_chars, $length) { $random_string = ""; $num_valid_chars = strlen($valid_chars); for ($i = 0; $i < $length; $i++) { $random_pick = mt_rand(1, $num_valid_chars); $random_char = $valid_chars[$random_pick-1]; $random_string .= $random_char; } return $random_string; } ?>
Benchmark redis : Total Set time: 0.12764096260071 Loop 0 (Get) time: 0.175616979599 Loop 1 (Get) time: 0.18264698982239 Loop 2 (Get) time: 0.13450312614441 Loop 3 (Get) time: 0.1352870464325 Loop 4 (Get) time: 0.13448214530945 Loop 5 (Get) time: 0.13312005996704 Loop 6 (Get) time: 0.15526604652405 Loop 7 (Get) time: 0.40630602836609 Loop 8 (Get) time: 0.13408994674683 Loop 9 (Get) time: 0.13564801216125 Total 10 loop Get time 1.726966381073 Benchmark memcache : Total Set time: 0.14455795288086 Loop 0 (Get) time: 0.12623596191406 Loop 1 (Get) time: 0.13038897514343 Loop 2 (Get) time: 0.1564610004425 Loop 3 (Get) time: 0.11394095420837 Loop 4 (Get) time: 0.11402487754822 Loop 5 (Get) time: 0.11300802230835 Loop 6 (Get) time: 0.11119389533997 Loop 7 (Get) time: 0.1115710735321 Loop 8 (Get) time: 0.11155104637146 Loop 9 (Get) time: 0.19941091537476 Total 10 loop Get time 1.28778672218322The results shows for simple Set and Get, redis is faster. For SET, redis is faster by 12% For GET, memcache is faster by 25% For other functions,more extensive tests/benchmarks have to perform on both.
Monday, 16 February 2015
Install phpredis
After installing redis, let further install the php package for apache or nginx.
To download and compile phpredis:
git clone https://github.com/phpredis/phpredis cd phpredis phpize ./configure make && make installInclude the compiled extension to php.ini:
touch /etc/php.d/redis.ini echo extension=redis.so > /etc/php.d/redis.iniIf you use Apache (httpd), restart by:
systemctl restart httpd.serviceIf you use nginx, restart it by:
systemctl restart php-fpm.service systemctl restart nginx.service
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.gzuntar/unzip the package
tar -xzvf redis-2.8.19.tar.gzcompile the bundle
cd redis-2.8.19 makeIt 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 tclRun make test:
make testIf functionality test passed it will show:
\o/ All tests passed without errors!Lets install the excutables into /usr/local/bin/.
make installFor 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.targetMove sample redis.conf to /etc.
cp /root/download/redis-2.8.19/redis.conf /etc/redis.confCreate 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 NOSAVEEnable and start redis service.
systemctl enable redis.service systemctl start redis.serviceLets 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.serviceInstall php-fpm
# yum install php-fpm -yEnable and start php-fpm service:
# systemctl enable php-fpm.service # systemctl start php-fpm.serviceTo install Nginx
# yum install nginx -yEnable and start Nginx service
# systemctl enable nginx.service # systemctl start nginx.serviceTest 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.confSet 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.serviceTest PHP Create a sample “phpinfo.php” file in the nginx document root folder:
# vi /usr/share/nginx/html/phpinfo.phpAppend the lines as shown below:
Save and close the file. Restart Nginx service:
# systemctl restart nginx.serviceNavigate to http://localhost/testphp.php (example). It will display all the details about PHP,build,setups.
Subscribe to:
Posts
(
Atom
)