您的位置:首页 > 运维架构 > Nginx

centos5.6 安装mysql+php+nginx

2012-05-08 08:47 761 查看
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel

centos5.6下
MySQL 5.5.23 CMake 安装笔记

mysql 最新的版本都需要cmake编译安装,估计以后的版本也会采用这种方式,所以特地记录一下安装步骤及过程,以供参考。

注意:此安装是默认centos下已经安装了最新工具包,比如GNU make, GCC, Perl, libncurses5-dev,如果在编译安装过程中发现有缺失的工具包,先yum install 单独下载安装再继续即可。

以下安装中涉及的几点需要提前说明的问题:

1. 所有下载的文件将保存在 /usr/local/src/ 目录下

2. mysql 将以mysql用户运行,而且将加入 service 开机自动运行

3. mysql 将被安装在 /usr/local/mysql/ 目录下

4. mysql 默认安装使用 utf8 字符集

5. mysql 的数据和日志文件保存在 /var/mysql/ 对应目录下

6. mysql 的配置文件保存于/var/mysql/my.cnf

一. Centos 用 wget 下载需要的软件,保存到目录 /usr/local/src/ 下

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.23.tar.gz/from/http://mysql.he.net/

wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz

wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz

wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz 

==============================过程可能出现的错误=====================================

安装Mysql5.5之前先卸载CentOS自带的Mysql5.0:

[root@localhost ~]# yum remove mysql  

编译安装cmake

下载cmake源码包cmake-2.8.4.tar.gz,mv到/usr/local/src目录下

[root@localhost ~]# cd /usr/local/src/  

[root@localhost src]# tar xzvf cmake-2.8.7.tar.gz   

[root@localhost src]# cd cmake-2.8.7 

[root@localhost cmake-2.8.4]# ./bootstrap   

---------------------------------------------  

CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.  

---------------------------------------------  

Error when bootstrapping CMake:  

Cannot find appropriate C compiler on this system.  

Please specify one using environment variable CC.  

See cmake_bootstrap.log for compilers attempted.  

  

---------------------------------------------  

Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log  

---------------------------------------------  

报错:缺少C的编译器。

 

安装gcc编译器

可以从Linux系统的安装盘中安装,也可以简单地用yum安装

[root@localhost ~]# yum install gcc  

 

继续cmake的安装

[root@localhost cmake-2.8.4]# ./bootstrap   

---------------------------------------------  

CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.  

C compiler on this system is: cc   

---------------------------------------------  

Error when bootstrapping CMake:  

Cannot find appropriate C++ compiler on this system.  

Please specify one using environment variable CXX.  

See cmake_bootstrap.log for compilers attempted.  

---------------------------------------------  

Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log  

---------------------------------------------  

再次报错:缺少C++编译器。

 

安装gcc-c++编译器

同样可以从Linux系统的安装盘中安装,或者简单地用yum安装

[root@localhost ~]# yum install gcc-c++  

 

重复上面的操作

[root@localhost cmake-2.8.4]# ./bootstrap   

 

没有报错后,编译安装

[root@localhost cmake-2.8.4]# gmake  

[root@localhost cmake-2.8.4]# gmake install  

 

开始正式安装Mysql

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

二. 安装 cmake

cd /usr/local/src

tar zxvf cmake-2.8.7.tar.gz

cd cmake-2.8.7

./bootstrap

gmake

gmake install

cd ../

tar zxvf bison-2.5.tar.gz

cd bison-2.5

./configure

make

make install

cd ../

#编译mysql ./configure时error:no curses/termcap library found

tar zxvf ncurses-5.6.tar.gz

cd ncurses-5.6

./configure

make

make install

cd ../

三. 编译安装 MySQL 5.5.23

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

chmod 777 /var/mysql/data

tar xvf mysql-5.5.23.tar.gz

cd mysql-5.5.23/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data

make && make install

chmod +w /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql

ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16

mkdir -p /var/mysql/

mkdir -p /var/mysql/data/

mkdir -p /var/mysql/log/

chown -R mysql:mysql /var/mysql/

cd support-files/

cp my-large.cnf /var/mysql/my.cnf (注意:my-large.cnf适用于1G内存左右的服务器,可以根据自己配置情况选用my-large.cnf 或 my-huge.cnf 等不同配置)

cp mysql.server /etc/init.d/mysqld

四. 配置启动MySQL 5.5.23

1. 若有需要请先修改 mysql 的配置 my.cnf

vi /var/mysql/my.cnf

2. mysql 初始化安装

/usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/var/mysql/my.cnf \

--basedir=/usr/local/mysql \

--datadir=/var/mysql/data \

--user=mysql

即系一行

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/var/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/var/mysql/data --user=mysql

3. 将 mysql 加入开机启动

chmod +x /etc/init.d/mysqld

vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)

basedir=/usr/local/mysql

datadir=/var/mysql/data

chkconfig --add mysqld

chkconfig --level 345 mysqld on

/usr/local/mysql/bin/mysqladmin -u root password new
password

 ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

Test:

mysql -u root -p

4. 启动 mysql

service mysqld start

//至此,mysql安装已经完成

php-5.3.8-fpm安装记录 

cd /usr/local/src/

tar jxvf php-5.3.8.tar.bz2

cd php-5.3.8

./configure --prefix=/usr/local/php-5.3.8 --enable-fpm --with-libxml-dir --with-openssl --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --with-curlwrappers --with-db4 --with-cdb --enable-dom --enable-exif
--enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash
--enable-intl --with-icu-dir=/usr/local/icu --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --with-mysql --with-mysql-sock --with-mysqli --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite
--with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-libexpat-dir --with-iconv-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support
--with-pear

make ZEND_EXTRA_LIBS='-liconv'

make test

make install

cp usr/local/src/php-5.3.8/php.ini  /usr/local/php-5.3.8/etc

cd /usr/local/php-5.3.8

cp php-fpm.conf.default php-fpm.conf <========复制一份并重命名

/usr/local/php-5.3.8/sbin/php-fpm ========启动php-fpm

启动错误解决:

ALERT: [pool www] pm.min_spare_servers(0) must be a positive value

编辑php-fpm.conf找到pm.min_spare_servers 去除;号,注意非注释内容pm.min_spare_servers

ALERT: [pool www] pm.max_spare_servers(0) must be a positive value

编辑php-fpm.conf找到pm.max_spare_servers 去除;号,同样非注释内容pm.max_spare_servers

WARNING: [pool www] pm.start_servers is not set. It's been set to 20.

编辑php-fpm.conf找到pm.start_servers 去除;号,同样非注释内容pm.start_servers

netstat  -alnp|grep  php

查看进程,有N多进程

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

#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
#tar -zxvf libiconv-1.13.1.tar.gz

#cd libiconv-1.13.1

# ./configure --prefix=/usr/local/libiconv

# make

# make install

再检查php,指定 iconv的位置  --with-iconv=/usr/local/libiconv

tar jxvf php-5.3.8.tar.bz2

cd php-5.3.8

//del --enable-intl --with-icu-dir=/usr/local/icu 

./configure --prefix=/usr/local/php-5.3.8 --enable-fpm --with-libxml-dir --with-openssl --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --with-curlwrappers --with-db4 --with-cdb --enable-dom --enable-exif
--enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash
--enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite
--with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-libexpat-dir --with-iconv-dir==/usr/local/libiconv --with-xsl
--enable-zip --enable-mysqlnd-compression-support --with-pear

finaly show 

Thank you for using PHP.

make 

make install

last show:

ln -s -f /usr/local/php-5.3.8/bin/phar.phar /usr/local/php-5.3.8/bin/phar

Installing PDO headers:          /usr/local/php-5.3.8/include/php/ext/pdo/

cp php-fpm.conf.default php-fpm.conf <========复制一份并重命名

/usr/local/php-5.3.8/sbin/php-fpm ========启动php-fpm

FPM 配置文件为php-fpm.conf

pm.max_children = 50

pm.start_servers = 20 

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

去掉分号

ln -s /usr/local/php-5.3.8/sbin/php-fpm /bin/php-fpm

cp php.ini-producsion /usr/local/php-5.3.8/etc/php.ini

ngnix1.0.5安装记录

 tar zxvf nginx-1.0.5.tar.gz

cd nginx-1.0.5

 useradd www   #添加www nginx运行账户

 usermod -s /sbin/nologin -g www www #将www加入www组并禁止www登录shell

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_rewrite_module --with-http_ssl_module --with-pcre && make && make install

 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #启动nginx,nginx启动成功。

报错 error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

Fixed:ln -s  /usr/local/lib/libpcre.so.1  /lib

/usr/local/nginx/sbin/nginx -s reload

ifconfig eth0:1 192.168.0.245 broadcast 192.168.0.255 netmask 255.255.255.0 up

route  add -host 192.168.0.245 dev  eth0:1

扩展memcache

rpm一、源码包准备

服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-v1.4.4 。

下载:http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz

另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,

libevent的最新版本是libevent-1.4.13-stable。(如果你的系统已经安装了libevent,可以不用安装)

官网:http://www.monkey.org/~provos/libevent/

下载:http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

准备Memcached的PHP扩展的源码安装包:

官网:http://pecl.php.net/get/memcache-2.2.5.tgz

Linux指令下载:

wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
wget http://pecl.php.net/get/memcache-2.2.5.tgz
二、安装与配置

1、先安装libevent

tar zxvf libevent-1.4.13-stable.tar.gz

cd libevent-1.4.13-stable

./configure –prefix=/usr

make

make install

2、测试libevent是否安装成功

ls -al /usr/lib | grep libevent

libevent-1.1a.so.1

libevent-1.1a.so.1.0.2

libevent-1.4.so.2

libevent-1.4.so.2.1.3

libevent.a

libevent_core-1.4.so.2

libevent_core-1.4.so.2.1.3

libevent_core.a

libevent_core.la

libevent_core.so

libevent_extra-1.4.so.2

libevent_extra-1.4.so.2.1.3

libevent_extra.a

libevent_extra.la 

libevent_extra.so

libevent.la

libevent.so

版本不同,可能文件列表不同。

3、安装memcached,同时需要安装中指定libevent的安装位置

tar zxvf memcached-1.4.4.tar.gz

cd memcached-1.4.4

./configure –with-libevent=/usr

make && make install

安装完成后会把memcached 自动放到 /usr/local/bin/memcached

4、测试是否成功安装memcached

ls -al /usr/local/bin/mem*

-rwxr-xr-x 1 root root 201869 12-14 21:44 /usr/local/bin/memcached

5、安装Memcache的PHP扩展

①安装PHP的memcache扩展

tar vxzf memcache-2.2.5.tgz

cd memcache-2.2.5

/usr/local/php-5.3.8/bin/phpize

./configure -enable-memcache -with-php-config=/usr/local/php-5.3.8/bin/php-config -with-zlib-dir

make

make install

②上述安装完后会有类似这样的提示:

Installing shared extensions: /usr/local/php-5.3.8/lib/php/extensions/no-debug-non-zts-20090626/

③把php.ini中的extension_dir = “./”修改为

extension_dir = “/usr/local/php-5.3.8/lib/php/extensions/no-debug-non-zts-20090626/”

④添加一行来载入memcache扩展

三、memcached的基本设置

1.启动Memcache的服务器端:

memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid

参数说明:

-d选项是启动一个守护进程,

-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,

-u是运行Memcache的用户,我这里是root,

-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址202.207.177.177,

-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,

-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,

-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

2.如果要结束Memcache进程,执行:

kill `cat /tmp/memcached.pid`

也可以启动多个守护进程,不过端口不能重复。

3.检查Memcached是否启动

netstat -ant

tcp        0      0 127.0.0.1:11211       0.0.0.0:*                   LIST

11211端口已经打开,说明Memcached已正常启动。

4.重启CentOS

reboot

四、Memcache环境测试

运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始你的Memcache的征途吧!

<?php

 

$mem = new Memcache;

$mem->connect("127.0.0.1", 11211);

$mem->set('key','This is a test!', 0, 60);

$val = $mem->get('key');

echo $val;

 

?>

著名的PHPCMS同样支持Memcached扩展:

<?php

 

//MemCache服务器配置

//define('MEMCACHE_HOST', 'localhost'); //MemCache服务器主机

//define('MEMCACHE_PORT', 11211); //MemCache服务器端口

//define('MEMCACHE_TIMEOUT', 1); //S,MemCache服务器连接超时

class cache

{

 var$memcache;

 

    function__construct()

    {

  $this->memcache = &newMemcache;

  $this->memcache->pconnect(MEMCACHE_HOST, MEMCACHE_PORT, MEMCACHE_TIMEOUT);

    }

 

    functioncache()

    {

  $this->__construct();

    }

 

 functionget($name)

    {

        return$this->memcache->get($name);

    }

 

    functionset($name,$value, $ttl= 0)

    {

         return$this->memcache->set($name,$value, 0, $ttl);

    }

 

    functionrm($name)

    {

        return$this->memcache->delete($name);

    }

 

    functionclear()

    {

        return$this->memcache->flush();

    }

}

?>

安装leveldb
http://code.google.com/p/leveldb/source/checkout
git clone https://code.google.com/p/leveldb/
git clone http://code.google.com/p/leveldb/             //work!!

2012-05-01 http://xingqiba.sinaapp.com/?p=172
git clone http://code.google.com/p/leveldb/
cd leveldb

make //编译后在/home/lyc/leveldb/Leveldb路径下会出现一个库文件libleveldb.a,这个可以用在自己的项目中

cd ../

git clone git://github.com/arraypad/php-leveldb.git

cd php-leveldb

/usr/local/php-5.3.8/bin/phpize

./configure --with-leveldb=/usr/local/src/leveldb --with-php-config=/usr/local/php-5.3.8/bin/php-config

make

make install

注意修改php.ini增加extension = leveldb.so并重启php

安装ICE

wget http://www.zeroc.com/download/Ice/3.4/Ice-3.4.2.tar.gz
wget http://www.zeroc.com/download/Ice/3.4/ThirdParty-Sources-3.4.2.tar.gz
tar zxvf ThirdParty-Sources-3.4.2.tar.gz

cd ThirdParty-Sources-3.4.2

#安装Berkeley DB

tar zxvf db-4.8.30.NC.tar.gz

cd db-4.8.30.NC/build_unix/

../dist/configure --prefix=/usr --enable-cxx

make

make install

cd ../../

#安装 bzip2-1.0.6.tar.gz

tar zxvf bzip2-1.0.6.tar.gz

cd bzip2-1.0.6

make

make install

cd ../

#expat-2.0.1.tar.gz

tar zxvf expat-2.0.1.tar.gz

cd expat-2.0.1

./configure

make

make install

cd ../

#安装openssl-0.9.8d.tar.gz

cd ../

tar zxvf openssl-0.9.8r.tar.gz

cd openssl-0.9.8r

./config --prefix=/usr --openssldir=/usr/openssl

make

make install

cd ../

#安装mcpp

tar zxvf  mcpp-2.7.2.tar.gz

cd mcpp-2.7.2

patch -p0 < ../mcpp/patch.mcpp.2.7.2

./configure CFLAGS=-fPIC --enable-mcpplib --disable-shared

make

make install

cd ../

#安装Ice

ca /usr/local

tar zxvf Ice-3.4.2.tar.gz    //最好解压到安装目录,解压到哪个目录就最好安装到哪个目录下,避免文件缺失

cd Ice-3.4.2/cpp

export LD_LIBRARY_PATH=/usr/local/Ice-3.4.2/lib        

==>找到cpp/config/Make.rules.Linux,在最显眼的地方【143行】在最后加上一个 -liconv,再编译

make

make install

cd /usr/local/Ice-3.4.2/php

vim php/config/Make.rules.php

USE_NAMESPACES          ?= yes

PHP_HOME                ?= /usr/local/php-5.3.8

cd /usr/local/Ice-3.4.2/php

make 

make install

cd /opt/Ice-3.4.2/php

如果是在linxu下安装IcePHP的话,则需要在Ice源文件下的php目录下编译源码,然后执行makeinstall安装IcePHP扩展,一般Ice会安装到opt/Ice-3.4.1目录下(这里假设版本号为3.4.1),然后在php.ini中定义:

extension_dir = /opt/Ice-3.4.1/php

extension = IcePHP.so

include_path = /opt/Ice-3.4.1/php

4.安装过程中出现的一些错误,及解决方法:

     4.1)错误提示:/usr/lib.ld:Error:cannot find -lmcpp   --->解决方法:应该是mcpp之前没有安装成功,将mcpp重新安装成功后就行

     4.2)错误提示:fatal error:db_cxx.h:No such file or directory   -->解决方法:之前没有把db-4.8.3安装成功,重新安装一遍

     4.3)安装Ice完成后,运行例子错误提示:error while loading shared libraries: libIce.so.34: cannot open shared object file: No such file or directory  -->解决办法:应该是之前编译Ice某些目录配置不对;使用命令 export LD_LIBRARY_PATH=/opt/Ice-3.4.2/lib重新来导出动态链接库目录即可。(共享库搜索顺序一般是$LDLIBRARY_PATH,/etc/ld.so.cache,
/usr/lib, /lib)

     4.4)安装Ice后,发现系统不能识别slice2cpp命令。原因及解决办法:应该是安装过程中没有把slice2cpp可执行文件复制到/ur/bin目录下面,或者是链接环境没有设置好;来到/opt/Ice-3.4.2/bin下面将slice2cpp复制到/usr/bin目录下即可。

4.5)libiconv.so.2: cannot open shared object file解决办法:

解决办法如下:

1.在/etc/ld.so.conf中加一行/usr/local/lib,

 2.然后运行/sbin/ldconfig,文件解决,没有报错了~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息