Redhat6.2下安装 nginx php mysql memcached mongoDB及相关扩展

来源:互联网 发布:闲鱼淘宝介入的客服 编辑:程序博客网 时间:2024/05/28 03:02
Redhat6.2下yum安装 nginx php mysql 及相关扩展
参考:http://blog.s135.com/nginx_php_v6/

参考:http://kerry.blog.51cto.com/172631/857461

参考:http://www.cnblogs.com/sink_cup/archive/2012/09/14/web_server.html

利用Centos的源来安装,使用163.com的Centos6的REPO文件,yum makecache


sudo -s
LANG=C
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 gd gd-devel


yum中的相关库名称
libcurl-devel libcurl
zlib-devel zlib
libxslt-devel libxslt
libzip-devel libzip
libxml2-devel libxml2
libjpeg-devel libjpeg 
libpng-devel libpng 
freetype-devel freetype
bzip2-devel bzip2
libzip-devel libzip
libxpm-devel libxpm
Redhat6.2 没有 mcrypt的php扩展


wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?ts=1348197028
wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?ts=1348196976
下载mhash
wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2?ts=1348198184&use_mirror=cdnetworks-kr-1


libmcrypt
./configure
make && make install
/sbin/ldconfig
使用libmcrypt需要用到ltdl,要不编译php时会报错
安装路径/usr/local/lib/
http://yangsiwei.com/usr-bin-ld-cannot-find-lltdl-%E9%94%99%E8%AF%AF%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../


编译ImageMagick
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.7.9-6.tar.xz
tar xvf ImageMagick-6.7.9-6.tar.xz -C /tmp
cd /tmp/ImageMagick-6.7.9-6
./configure
make && make install


为了让动态连接库为系统共享
需要运行/sbin/ldconfig命令,也可以在/etc/ld.so.conf.d/加一个custome.conf的文件,添加上自己的库地址




cd mhash-0.9.9.9
./configure
make && make install




解决mcrypt编译时的查找文件路径问题
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
./configure --with-libmcrypt-prefix=/usr/local
make && make install


*******************************************
安装mysql二进制包
*******************************************


wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.27-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
我们并不完全了解mysql,与其自己模式还不如先用一个编译好的,然后放到一个我们指定的目录下
修改了/app目录 为/data目录
tar xzvf mysql-5.5.27-linux2.6-x86_64.tar.gz
mv mysql-5.5.27-linux2.6-x86_64 /data/opt/mysql
建立数据目录,可以把data、binlog、relaylog 数据分开在独立的目录中
mkdir /data/databases
mkdir /data/databases/binlog


cd /data/opt/mysql
./scripts/mysql_install_db --basedir=/data/opt/mysql --datadir=/data/databases --user=mysql


修改配置文件/etc/my.cnf
[client]
character-set-server = utf8
port    = 3306
socket  = /tmp/mysql.sock


[mysqld]
character-set-server = utf8
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /data/opt/mysql
datadir = /data/databases
log-error = /data/databases/mysql_error.log
pid-file = /data/databases/mysql.pid
open_files_limit    = 1024
back_log = 600
max_connections = 200
max_connect_errors = 200
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
#query_cache_size = 512M
#query_cache_limit = 2M
#query_cache_min_res_unit = 2k
#default-storage-engine = MyISAM
#thread_stack = 192K
#transaction_isolation = READ-COMMITTED
#tmp_table_size = 246M
#max_heap_table_size = 246M
#long_query_time = 3
#log-slave-updates
#log-bin = /data0/mysql/3306/binlog/binlog
#binlog_cache_size = 4M
#binlog_format = MIXED
#max_binlog_cache_size = 8M
#max_binlog_size = 1G
#relay-log-index = /data0/mysql/3306/relaylog/relaylog
#relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
#relay-log = /data0/mysql/3306/relaylog/relaylog
#expire_logs_days = 30
#key_buffer_size = 256M
#read_buffer_size = 1M
#read_rnd_buffer_size = 16M
#bulk_insert_buffer_size = 64M
#myisam_sort_buffer_size = 128M
#myisam_max_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
#
#interactive_timeout = 120
#wait_timeout = 120
#
#skip-name-resolve
##master-connect-retry = 10
#slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#
##master-host     =   192.168.1.2
##master-user     =   username
##master-password =   password
##master-port     =  3306
#
#server-id = 1
#
#innodb_additional_mem_pool_size = 16M
#innodb_buffer_pool_size = 512M
#innodb_data_file_path = ibdata1:256M:autoextend
#innodb_file_io_threads = 4
#innodb_thread_concurrency = 8
#innodb_flush_log_at_trx_commit = 2
#innodb_log_buffer_size = 16M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120
#innodb_file_per_table = 0
#
##log-slow-queries = /data0/mysql/3306/slow.log
##long_query_time = 10
#
#[mysqldump]
#quick
#max_allowed_packet = 32M
                                     
通过bin/mysql 链接mysql报错
bin/mysql: unknown variable 'character-set-server=utf8'
看到网上的文章有人通过用character_set_server=utf8来取代 default-character-set=utf8,解决了类似报错问题
我把结果反过来,也解决了我的问题
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION IDENTIFIED BY 'mainone%123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION IDENTIFIED BY 'mainone%123';




*******************************************
编译安装php5.3.17
*******************************************


wget http://php.net/get/php-5.3.17.tar.bz2/from/cn2.php.net/mirror
关于inline编译优化
http://stackoverflow.com/questions/6791564/what-does-enable-inline-optimization-do-when-compiling-php
精确的数学计算
--enable-bcmath
php.ini配置文件地址
with-config-file-path
Disable passing additional runtime library
--disable-rpath
内存共享操作函数
--enable-shmop
enable System V semaphore support compile PHP with the option
--enable-sysvsem
使用CURL做为url stream的函数
--with-curlwrappers
使用宽字符集的正则匹配
--enable-mbregex
fork子进程的功能
--enable-pcntl 
http://blog.csdn.net/lgg201/article/details/5996444


Generating phar.phar
chmod: 无法访问"ext/phar/phar.phar": 没有那个文件或目录
make: [ext/phar/phar.phar] 错误 1 (忽略)


解决动态链接libmysqlclient.so.18找不到问题,两个办法,最好是做软连接
1、export LD_LIBRARY_PATH="/data/opt/mysql/lib:$LD_LIBRARY_PATH"
2、ln -s /data/opt/mysql/lib/libmysqlclient_r.so.18 /usr/lib


./configure --prefix=/data/opt/php --with-config-file-path=/data/opt/php  --enable-mysqlnd --with-mysql=/data/opt/mysql --with-mysqli=/data/opt/mysql/bin/mysql_config --with-libxml-dir=/usr/include/libxml2 --with-gd=/usr/include --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib --with-mcrypt=/usr/local/lib/libmcrypt --with-mhash --with-curl=/usr/include/curl --enable-gd-native-ttf --enable-sockets --enable-mbstring --with-libxml-dir=/usr/include --enable-xml --disable-rpath --enable-fpm --with-curlwrappers --enable-pcntl --enable-soap --with-xmlrpc --enable-zip


配置php-fpm
http://ideas.spkcn.com/technology/php-technology/133.html
cp php5.3.17/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cd /data/opt/php/etc
cp php-fpm.conf.default php-fpm.conf


修改配置php-fpm.conf
pid = run/php-fpm.pid
user=www-data
group=www-data
pm.start_servers = 20
pm.max_children = 64


pm.start_servers = 12
pm.min_spare_servers = 3
pm.max_spare_servers = 20


rlimit_files = 65535
catch_workers_output = yes
配置结束


shell设置文件打开数量
ulimit -SHn 65535


chkconfig --add php-fpm
chkconfig php-fpm on


安装完后修改php.ini
date.timezone = "Asia/Shanghai"
expose_php = Off // 禁止在HTTP header中显示php信息
short_open_tag = On // 开启短标记




下载php优化扩展
wget http://pecl.php.net/get/APC-3.1.9.tgz
cd APC-3.1.9
/data/opt/php/bin/phpize
./configure --with-php-config=/data/opt/php/bin/php-config
make && make install
php扩展路径 /data/opt/php/lib/php/extensions/no-debug-non-zts-20090626/


编译imagemagick扩展
wget http://pecl.php.net/get/imagick-2.3.0.tgz
tar xzvf imagick-2.3.0.tgz
cd imagick-2.3.0
编译安装和上面APC一样


设置 php.ini 的扩展目录
extension_dir = "/data/opt/php/lib/php/extensions/no-debug-non-zts-20090626"


配置apc ,imgick
extension=apc.so
extension=imagick.so


安装mongodb扩展
wget http://pecl.php.net/get/mongo-1.2.12.tgz
tar xvf mongo-1.2.12.tgz
cd %
phpize
./configure
make && make install
extension=mongo.so


编译安装 memcached
http://www.yongblog.com/archives/386.html
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
tar xvf memcached-1.4.15.tar.gz
cd %
./configure --prefix=/usr/local/memcached
make && make install
暂时的启动方案
/usr/local/memcached/bin/memcached -u root


编译安装libevent
由于rhel6.2带的libevent还是1.4的,在编译libmemcached1.0series时有问题,所以安装一个新版的库
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
./configure --prefix=/usr/local/libevent




编译安装libmemcached 
wget https://launchpad.net/libmemcached/1.0/1.0.10/+download/libmemcached-1.0.10.tar.gz
tar xvf libmemcached-1.0.10.tar.gz
./configure --prefix=/usr/local/libmemcached -with-memcached
make && make install
在编译libmemcached1.0.10版时报编译example下文件错误
example/memcached_light.cc:596: undefined reference to `event_init'等
没有找到合适的解决办法,故换成1.0.4的版本
wget https://launchpad.net/libmemcached/1.0/1.0.10/+download/libmemcached-1.0.4.tar.gz
其他过程一样,编译通过


编译安装php_memcached
memcached-2.1.0 的版本要求libmemcached-1.0.11的版本
wget http://pecl.php.net/get/memcached-2.0.1.tgz
tar xvf memcached-2.0.1.tgz
./configure --with-libmemcached-dir=/usr/local/libmemcached
make && make install
编译没有问题
添加extension=memcached.so到php.ini文件


编译安装php_memcache,这个与memcached的扩展是不一样的
这个扩展在windows下可以用,但是功能没有上面的好,配置一样就不写了


*******************************************
安装配置nginx
*******************************************
yum 安装, 这次没有编译


--with-http_stub_status_module 是为了启用 nginx 的 NginxStatus 功能,用来监控 Nginx 的当前状态。 安 装成功后 /opt/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。


--http-client-body-temp-path=PATH  set path to store http client request body temporary files 指定http客户端请求缓存文件存放目录的路径
--http-fastcgi-temp-path set path to store http fastcgi temporary files 指定http FastCGI缓存文件存放目录的路径
--http-proxy-temp-path set path to store http proxy temporary files 指定http反向代理缓存文件存放目录
--http-uwsgi-temp-path set path to store http uwsgi temporary files 指定http uwsgi缓存文件存放目录的路径
--http-scgi-temp-path set path to store http scgi temporary files 指定http sigi缓存文件存放目录的路径
--with-http_ssl_module enable ngx_http_ssl_module
--with-http_realip_module enable ngx_http_realip_module 当作为代理服务器使用时,设置后端获取的真实IP值通过 X-Real-IP or X-Forwarded-For header值
--with-http_addition_module enable ngx_http_addition_module 在响应之前或之后添加文本的一个过滤器
--with-http_sub_module enable ngx_http_sub_module This module can search and replace text in the nginx response.
--with-http_dav_module  enable ngx_http_dav_module This module adds the HTTP and WebDAV methods PUT, DELETE, MKCOL, COPY and MOV
--with-http_flv_module  enable ngx_http_flv_module This module provides the ability to seek within FLV (Flash) files using byte-based offsets.
--with-http_mp4_module  enable ngx_http_mp4_module This module enables mp4 streaming with seeking ability
--with-http_gzip_static_module  enable ngx_http_gzip_static_module Before serving a file from disk to a gzip-enabled client, this module will look for a precompressed file in the same location that ends in ".gz
--with-http_random_index_module    enable ngx_http_random_index_module Pick a random file from a directory and use it as the index file.
--with-http_secure_link_module     enable ngx_http_secure_link_module This module checks request URLs for a required security token
--with-http_stub_status_module     enable ngx_http_stub_status_module  This module provides the ability to get some status from nginx.
--with-mail                        enable POP3/IMAP4/SMTP proxy module  Mail Proxy Configuration
--with-file-aio                    enable file AIO support Kernel Asynchronous I/O (AIO) Support 


修改nginx.conf
user www-data www-data








*******************************************
mongodb 安装
*******************************************
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/
修改dbpath=/data/mongo