Showing posts with label Open Source Solution. Show all posts
Showing posts with label Open Source Solution. Show all posts

Monday, February 14, 2011

How to: resize expand partition on Centos hosted by Vmplayer

when you limited size warrning, run “df-h”,  80% is used on /, we will span the /dev/mapper/volgroup00-logvol00 here.

image

display LVM , “lvdisplay”, there are one volum group volGroup00 with two logic volumes 00 and 01
image

just one disk with 10G, shut down the VM, and click the utility to expand the disk to 13G

image

run “fdisk /dev/had” to add a lvm partition to the new expended disk.
p –>print current partition
n-> add one new partition with primary partation
t-> toggle the partition type to 8e which is lvm

image

image
press W to save the partition

image
after done, Run Pvcreate to create a new LVM.

image

if you get error like disk us not found , just reboot the vm

Extend the VolGroup00 , add /dev/hda3 to the group, and extend the /dev/VolGroup00/LogVol00 to the new lvm hda3

image
run resize2fs , refresh the change.  run df –h again, you will see free space is increased.

image

Thursday, February 10, 2011

how to install and configure Nginx + PHP FPM

Building PHP with FPM Support,

# ./configure --enable-fpm --prefix=/opt/phpfpm

Make
Make Install

image

then you can run the php-fpm by run “php-fpm ”, php-fpm is located in the sbin dir
if you get error like unable to find the conf file like following ,

image

just rename /opt/phpfmp/etc/php-fpm.conf.default as php-fpm.conf , change the min/max/startserver value
image
Also copy the /tmp/php-x/php.ini-production to /opt/phpfpm/php.ini
run netstat –an |grep 9000
image

Now install nginx following install and config Nginx/PhP fastcgi on Centos
change the nginx.conf to include fpm for php backend proxy processing. just uncomment the default conf settings,

location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /opt/nginx/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

restart nginx –s restart

then create one info.php and put it under /opt/ngnix/html

<?php phpinfo();?>

Now, you can access http://localhost/info.php, you will get php info page.

image

Here is the raw traffic between Nginx and PhpFPM
image

If you get 404 error no matter how, check the nginx.conf point to the absolute path of the script

fastcgi_param  SCRIPT_FILENAME /opt/nginx/html/$fastcgi_script_name;

Wednesday, February 9, 2011

How to : install and config Nginx/PhP fastcgi on Centos

To Install Nginx, setup the prerequisites as following.

yum install GCC #C compiler
yum install pcre* # perl regular expression
yum install zlib zlib-devel
yum install openssl openssl-devel

Download Nginx From http://nginx.org/en/download.html, and extract to a source folder, I will use /tmp here

wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar
-zxvf nginx-0.8.54.tar.gz
cd /tmp/nginx-0.8.54

./configure  --prefix=/opt/nginx
make && make install

once done, you can run ./nginx –? to show all available options ,

image

for the default loading, it read the conf file which is  conf/nginx.conf 
 
to start the nginx, just run ./nginx, you will get the helloworld page.

image

here, I changed ngingx.conf a little with a New port 88, and basic proxy forward to Apache,PHP (check installation instructions, Install PHP to Apache web server)

server {
        listen       88;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

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

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
       location ~ \.php$ {
            proxy_pass  
http://127.0.0.1;
        }


if I access http://localhost:88/info.php, nginx will forward the request to http://localhost/info.php
image

But the server header is nginx Now. Also the ngnix has enabled the GZIP support now. ( a great reverse proxy, offloading those cut-off features)

image


more how-tos:

How to: install apache 2.2 on centos
How To: Install PHP to Apache web server

Tuesday, February 8, 2011

How To: Install PHP to Apache web server

After install apache 2.2 on centos , there is no PHP Module built-in, You have to do the same thing like installing apache, Download the source file , compile and put the modules to the folder that will be picked up by apache. Here is the rough steps,

  • Download and extract the tarball from php.net, http://us.php.net/get/php-5.3.5.tar.gz/from/this/mirror
    • tar –zxvf php-5.3.5.tar.gz
  • go into the uncompressed php folder and run the config
    • ./configure –with-apxs2=/opt/apache/bin/apxs –-prefix=/opt/php
    • if needed, yum install libevent-devel libxml2-devel
  • Compile and Test
    • make && make test
  • Install the module to the modules folder
    • make install
    • this will automatically upate apache’s conf/httpd.conf with
      LoadModule php5_module        modules/libphp5.so
      Add the handler of php manully.
      AddType application/x-httpd-php .php
  • restart the apache daemon

TO test, create a single line file to htdocs/test.php

<?php phpinfo();?>

when access that url , you will get the information of php settings, now you are good to go.
image

How to: Test the apache syslog with the free kiwi syslog server

Let’s say you have two OS, one in windows which will host the syslog server, and one Centos OS as the container of Apache , here is the tutorial to test the syslog logging. both on  server side (view the logs) and and client side (turn on logging to syslog)

Download and install one free version of kiwi syslog
  
  when you run, you will get the GUI to show and filter logs.

image

when the log server runs, it will listen on the UDP port 514.
image


on the Centos, OS level, to Point lone log facility to our kiwi log server

vi /etc/syslog.conf
#Add one line

localcal6.*        @192.168.209.1

#restart syslog server
service syslog restart # or killall –HUP syslogd

Now, you can test the syslog setting now, by write several logs to syslog

logger –p local6.info Hello,errorlog

from the kiwi server, you will see the log
image

For the Apache, change the httpd.conf, to point the errorlog and accesslog to our syslog facility local6

#ErrorLog "logs/error_log"
ErrorLog syslog:local6

#access Log
CustomLog "|/usr/bin/logger -p local6.info"  combined


Restart the httpd , all logs will be dispatched to our syslog server. (here both error log and access log)

image

Monday, February 7, 2011

How to: install apache 2.2 on centos

It’s pretty straightforward to install apache 2.2 on centos. download the source file and compile it, then make install.

cd /tmp
wget http://download.nextag.com/apache//httpd/httpd-2.2.17.tar.gz
tar zxvf httpd-2.2.17.tar.gz
then switch to the decompressed folder
./configure --prefix=/opt/apache
make
make install
#Done


After that, start the httpd, there is one apachectl utility to control the start/stop operation of httpd

/opt/apache/bin/apachectl start
#start the httpd daemon

then browse to localhost:80, you will get the It works page. (httpd is working and listens on port 80) 
image

you can change the index.html located in the /opt/apache/htdocs/ to something else like hello world.

run “ps -aux|grep httpd”, you will see the processes.
image

To add the httpd to  service.

ln -s /opt/apache/bin/apachectl  /etc/init.d/apache2
add two lines to the /etc/init.d/apache2
#chkconfig:3 80 80
#description:my apache web server

add it to the chkconfig
chkconfig –add apache2

now you can query chkconfig –list apache2

image

Sunday, February 6, 2011

linux putty SSH arrow key not working macbook ubantu, ^[[A

Unlike One Simple Windows, there are a lot ad-hoc on Linux. I get a strang behavior with ubantu this Moring, the arrow key to show the last command history never work any more. it shows the escaped encoding,

Always, when I press the left arrow, it returns the last command history,. But not, it returns ^[[A

image

First make sure which shell you are using, by run “echo $0”

image

I get a stupid shell –su now. now switch to the bash by run “/bin/bash”

all works now

image

is it tricky?

also we can add it to the default profile or .bashrc

Wednesday, November 10, 2010

How To : installing and testing greenplum single node edition on Centos 5.5

Download the single node edition, Here I use the version 4.0 for redhat /centos , greenplum-db-4.0.0.4-build-1-RHEL5-x86_64.bin

check OS version,

[root@localhost Desktop]# cat /etc/redhat-release
CentOS release 5.5 (Final)


if you run the installer on unmatched version of centos, will get an error, “Installer will only install on RedHat/CentOS x86_64”
here run Uname –m, It will tell the hardware spec, 386 or x86_64.


[root@localhost ~]# uname -m
x86_64

run the installer directly.


[root@localhost Desktop]# ./greenplum-db-4.0.0.4-build-1-RHEL5-x86_64.bin
make sure you have the execute permission. If not, run
chmod 722 greenplum-db-4.0.0.4-build-1-RHEL5-x86_64.bin


read and accept the agreement,
by default the bits will be put into folder /usr/local/greenplum-version.  Enter yes to accept the default settings. like folder path, once done. you will get the message like

image

source /usr/local/greenplum-db-4.0.0.4/greenplum_path.sh

Create a dedicated user to run the process , and folders to hold segments and maser data. given user the folder access permission.


Here we will create a user named gp
Create a maser folder /data/master
Create 4 segment folders /data/seg1, /data/seg2,/data/seg3/,/data/seg4
Change ownership folder of /data/* to gp

image 
Copy one instance from the sample config and change the setting like folder path , listen port.

cd /usr/local/greenplum-db-4.0.0.4/docs/cli_help
[root@localhost cli_help]# cp gp_init_singlenode_example /home/gp/
[root@localhost cli_help]# cp single_hostlist_example /home/gp/
[root@localhost cli_help]#

Switch to user gp, go to home foder, then change two files we just copied here.

gp_init_singlenode_example content change.

MACHINE_LIST_FILE=./single_hostlist_example

declare -a DATA_DIRECTORY=(/data/seg1 /data/seg2 /data/seg3 /data/seg4)
#four segment folders

MASTER_DIRECTORY=/data/master
#master diferctory

Initialize the system. (create folders and start up several postgres processes.)

[gp@localhost ~]$ gpssh-exkeys -f single_hostlist_example

gpinitsystem -c gp_init_singlenode_example
image

once done, when you run ps -aux|grep /data/, you will see 5 postgresq processes here, one master , four segment instances.

image


Now the single Node cluster is ready, we can use the psql to connect to the instance and have some fun.

Create one test database
CreateDB androidtest

psql (8.2.14)
Type "help" for help.

androidtestdb=# Create table public.test( id int primary key, state varchar(30) not null);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey" for table "test"
CREATE TABLE
androidtestdb=# \d+ public.test;
                   Table "public.test"
Column |         Type          | Modifiers | Description
--------+-----------------------+-----------+-------------
id     | integer               | not null  |
state  | character varying(30) | not null  |
Indexes:
    "test_pkey" PRIMARY KEY, btree (id)
Has OIDs: no
Distributed by: (id)


Now we just created one table test which is disturbed by id. which means if we put more data, the data will be distributed and dispatched to different segments by column iD.  let’s run a simple sql.

insert into public.test values (1,'AL') ,(2,'AK') ,(3,'AS') ,(4,'AZ') ,(5,'AR') ,(6,'CA') ,(7,'CO') ,(8,'CT') ,(9,'DE') ,(10,'DC') ,(11,'FM') ,(12,'FL') ,(13,'GA') ,(14,'GU') ,(15,'HI') ,(16,'ID') ,(17,'IL') ,(18,'IN') ,(19,'IA') ,(20,'KS') ,(21,'KY') ,(22,'LA') ,(23,'ME') ,(24,'MH') ,(25,'MD') ,(26,'MA') ,(27,'MI') ,(28,'MN') ,(29,'MS') ,(30,'MO') ,(31,'MT') ,(32,'NE') ,(33,'NV') ,(34,'nh') ,(35,'NJ') ,(36,'NM') ,(37,'NY') ,(38,'NC') ,(39,'ND') ,(40,'MP') ,(41,'OH') ,(42,'OK') ,(43,'OR') ,(44,'PW') ,(45,'PA') ,(46,'PR') ,(47,'RI') ,(48,'SC') ,(49,'SD') ,(50,'TN') ,(51,'TX') ,(52,'UT') ,(53,'VT') ,(54,'VI') ,(55,'VA') ,(56,'WA') ,(57,'WV') ,(58,'WI') ,(59,'WY') ;
INSERT 0 59


How can we tell whether the data are distributed across segments evenly.
in each table, there is one system column called gp_segment_id

select gp_segment_id, id, state from public.test;

gp_segment_id | id | state
---------------+----+-------
             3 |  2 | AK
             3 |  6 | CA
             3 | 10 | DC
             3 | 14 | GU
             3 | 18 | IN
             3 | 22 | LA
             3 | 26 | MA


you can run a basic group query

androidtestdb=# select gp_segment_id, count(*) from public.test group by gp_segment_id;
gp_segment_id | count
---------------+-------
             3 |    15
             0 |    15
             1 |    14
             2 |    15

   data is evenly distributed across four segments.

also you can run a analyze to tell the execution plan. which will also tell you the segments scan are handled in a parallel way.

androidtestdb=# EXPLAIN  select * from public.test;
                                 QUERY PLAN
-----------------------------------------------------------------------------
 Gather Motion 4:1  (slice1; segments: 4)  (cost=0.00..4.59 rows=15 width=7)
   ->  Seq Scan on test  (cost=0.00..4.59 rows=15 width=7)
(2 rows)


EXPLAIN analyze  select * from public.test;
                                                   QUERY PLAN                             
----------------------------------------------------------------------------------------------------------------
Gather Motion 4:1  (slice1; segments: 4)  (cost=0.00..4.59 rows=15 width=7)
   Rows out:  59 rows at destination with 0.515 ms to first row, 1.215 ms to end.
   ->  Seq Scan on test  (cost=0.00..4.59 rows=15 width=7)
         Rows out:  Avg 14.8 rows x 4 workers.  Max 15 rows (seg0) with 0.026 ms to first row, 0.029 ms to end.
Slice statistics:
   (slice0)    Executor memory: 139K bytes.
   (slice1)    Executor memory: 155K bytes avg x 4 workers, 155K bytes max (seg0).
Total runtime: 2.038 ms
(8 rows)




 
Locations of visitors to this page