LNMP & Redis & git

1.更新依赖包
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers patch




MYSQL 安装

yum install -y gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison

MYSQL 下载地址     http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.7-rc.tar.gz

groupadd mysql

useradd -r -g mysql mysql

编译

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql   -DMYSQL_DATADIR=/data/mysql    -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFALUT_CHARSETS=all  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306  -DWITH_DEBUG=0

编译通过安装
make && make install

cp support-files/my-medium.cnf /etc/my.cnf          #复制配置文件
cp support-files/mysql.server /etc/init.d/mysqld    #复制启动脚本
chmod 755 /etc/init.d/mysqld
cd /usr/local/webserver/mysql                                                #进入安装目录
./scripts/mysql_install_db --user=mysql --ldata=/data/mysql    #初始化数据库
/etc/init.d/mysqld start   

chkconfig --add mysqld                                 #添加系统服务
chkconfig mysqld on                                     #添加开机启动
export PATH=$PATH:/usr/local/webserver/mysql/bin    #添加环境变量 
echo 'PATH=$PATH:/usr/local/webserver/mysql/bin' >> /etc/profile
service mysqld start/stop

编译参数解释
cmake . \                          #开始编译
-DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \      #安装到/usr/local/mysql目录
-DMYSQL_DATADIR=/data/mysql \                  #数据存放到/data/mysql目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \    #sock存放到/data/mysql目录
-DWITH_INNOBASE_STORAGE_ENGINE=1 \             #innoDB引擎
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \                       #字符集
-DDEFALUT_CHARSETS=all \                       #支持所有字符集
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \          #字符集校验
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0\




2.安装php

下载 需要的依赖包

创建一个软件目录

Libmcrypt 下载地址 wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
MHash 下载地址 wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
libiconv 下载地址 wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.8.tar.gz
Memcache 下载地址 wget http://pecl.php.net/get/memcache-3.0.6.tgz
MYSQL_POD 下载地址 wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
ImageMagick 下载地址 wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.8.5-5.tar.gz
imagick 下载地址 wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz
wget http://unmp.googlecode.com/files/mcrypt-2.6.8.tar.gz
安装libiconv
tar zxvf libiconv-1.8.tar.gz
cd libiconv-1.8/
./configure --prefix=/usr/local
make
make install
cd ../

安装Libmcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

安装MHash
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../


ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

安装mcrypt
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

安装PHP


groupadd fpm
useradd --shell /sbin/nologin -g fpm fpm

wget http://cn2.php.net/distributions/php-5.3.18.tar.gz
tar -zxf php-5.3.18.tar.gz

cd php-5.3.18/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini
cd ../

安装Memcache 扩展
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
cd ../

安装eaccelerator
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

安装PDO MYSQL
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ../
安装ImageMagick
tar zxvf ImageMagick-6.8.0-4.tar.gz
cd ImageMagick-6.8.0-4/
./configure
make
make install

ldconfig /usr/local/lib

cd ../

安装imagick
yum install gtk+-devel
export PKG_CONFIG_PATH=/usr/local/etc/ImageMagick
export PKG_CONFIG_PATH=/usr/local/etc/ImageMagick/lib/pkgconfig

wget http://pecl.php.net/get/imagick-3.0.1.tgz
wget http://pecl.php.net/get/imagick-3.1.0RC1.tgz
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

修改php.ini文件
  手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
  修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"
  并在此行后增加以下几行,然后保存:
  extension = "memcache.so"
  extension = "pdo_mysql.so"
  extension = "imagick.so"

  再查找output_buffering = Off
  修改为output_buffering = On

  再查找; cgi.fix_pathinfo=0  去掉;
  并且修改为cgi.fix_pathinfo=1    打开pathinfo支持 

  自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:

sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/webserver/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/webserver/php/etc/php.ini
sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/webserver/php/etc/php.ini
sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=1#g" /usr/local/webserver/php/etc/php.ini


配置eAccelerator加速PHP:

mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini

  文件的最末尾,加上以下配置信息:

=================================================================================================================
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

===================================================================================================================



安装Nginx

创建www用户和组
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /webroot/htdocs/mysql
chmod +w /webroot/htdocs/mysql
chown -R www:www /webroot/htdocs/mysql
mkdir -p /webroot/htdocs/www
chmod +w /webroot/htdocs/www
chown -R www:www /webroot/htdocs/www


1、安装Nginx所需的pcre库:

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
tar zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure
make && make install
cd ../

安装 nginx

wget http://nginx.org/download/nginx-1.3.8.tar.gz

tar zxvf nginx-1.3.8.tar.gz
cd nginx-1.3.8/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../





 3、创建Nginx日志目录

mkdir -p /nginxdata/logs
chmod +w /nginxdata/logs
chown -R www:www /nginxdata/logs


  4、创建Nginx配置文件
  ①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:

rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

输入
user  www www;

worker_processes 2;

error_log  /nginxdata/logs/nginx_error.log  crit;

pid        /usr/local/webserver/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
  use epoll;
  worker_connections 65535;
}

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

  #charset  gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

  #limit_zone  crawler  $binary_remote_addr  10m;

  server
  {
    listen       80;
    server_name  www.webroot.c;
    index index.html index.htm index.php;
    root  /webroot/htdocs/www;

    #limit_conn   crawler  20;   
                            
    location ~* .*\.php($|/){
        include  fcgi.conf;
    }
   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }   

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /nginxdata/logs/access.log  access;
      }

  server
  {
    listen       80;
    server_name  mysql.webroot.c;
    index index.html index.htm index.php;
    root  /webroot/htdocs/mysql;

    location ~* .*\.php($|/){

        include  fcgi.conf;
    }

    log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
    access_log  /nginxdata/logs/wwwlogs.log  wwwlogs;
  }


}


=====================编辑cgi配置文件==============
vi /usr/local/webserver/nginx/conf/fcgi.conf
输入:

if ($request_filename ~* (.*)\.php) {
            set $php_url $1;
      }
      if (!-e $php_url.php) {
            return 403;
      }


fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;

set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
        set $real_script_name $1;
        set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
## 以上是支持pathinfo的重点部分

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

#fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
#fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;


启动nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
配置开机自启动
vi /etc/rc.local
输入
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
mysql start

创建php-fpm 启动脚本
#! /bin/sh

# Description: Startup script for php-fpm on Debian. Place in /etc/init.d and
# run 'update-rc.d php-fpm defaults'.
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
#php-fpm路径
DAEMON=/usr/local/webserver/php/bin/$NAME
#配置文件路径
CONFIGFILE=/usr/local/webserver/php/etc/php-fpm.conf
#PID文件路径(在php-fpm.conf设置)
PIDFILE=/usr/local/webserver/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
  $DAEMON -y $CONFIGFILE || echo -n " already running"
}

d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() {
  kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        d_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC: $NAME"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
  *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
         exit 3
        ;;
esac

exit 0



安装TCL8.5
wget http://downloads.sourceforge.net/tcl/tcl8.5.12-src.tar.gz
tar -xf tcl8.5.12-src.tar.gz
cd tcl8.5.12-src

./configure --prefix=/usr \ --enable-threads \--mandir=/usr/share/man &&  make && sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \  -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \ -i tclConfig.sh

make install && make install-private-headers && ln -v -sf tclsh8.5 /usr/bin/tclsh && chmod -v 755 /usr/lib/libtcl8.5.so



安装redis

wget http://download.redis.io/redis-stable.tar.gz
tar -zxvf redis-stable.tar.gz

cd redis-stable

make
make test
make install

useradd redis
mkdir -p /var/lib/redis
mkdir -p /var/log/redis

vi /etc/redis.conf

#文件放在这里,需要修改redis.conf

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis
[root@localhost redis-stable]# mkdir -p /var/log/redis

# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/log/redis/redislog

----------------------------------------
更改目录拥有者
chown redis.redis /var/lib/redis
chown redis.redis /var/log/redis


建立redis 启动脚本
vim /etc/init.d/redis

#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL



---------------------------------------
增加开机自启动
chmod 755 /etc/init.d/redis
chkconfig --add redis
chkconfig --level 345 redis on
chkconfig --list redis

启动
service redis start






安装git
yum install curl
yum install curl-devel
yum install zlib-devel
yum install openssl-devel
yum install perl
yum install cpio
yum install expat-devel
yum install gettext-devel

wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
tar xzvf git-latest.tar.gz
cd git-2011-11-30 #你的目录可能不是这个
autoconf
./configure --prefix=/usr/local/git
make
make install
git --version

修改/etc/profile文件,在文件中追加:
GIT_HOME=/usr/local/git
PATH=$GIT_HOME/bin:$PATH

source /etc/profile

你可能感兴趣的:(redis,nginx,mysql,PHP)