8.7 初始化安装数据库
# /usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/var/mysql/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
8.8 将 mysql 加入开机启动
# chmod +x /etc/init.d/mysqld
# vi /etc/init.d/mysqld
查找并修改:
basedir=/usr/local/mysql
datadir=/var/mysql/data
8.9 添加为系统服务
# chkconfig --add mysqld
# chkconfig --level 2345 mysqld on
8.10 启动mysql 设置 root 密码
# service mysqld start
# /usr/local/mysql/bin/mysqladmin -u root password "123456"
错误一:
mysqladmin, mysql ... 命令无法执行:
# export PATH=/usr/local/mysql/bin:$PATH
错误二:
Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
# yum install ncurses-devel
8.11 添加并发优化
# vi /usr/local/mysql/bin/mysqld_safe
在 executing mysqld_safe 的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
启动 mysql:
# service mysqld restart
使用lsof命令查看tcmalloc是否起效:
# /usr/sbin/lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0
9. 开始安装 PHP
9.1 下载 php 和相关软件包
# cd /mydata/soft
wget http://cn2.php.net/get/php-5.4.8.tar.gz/from/this/mirror
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.8.0-2.tar.gz
wget http://sourceforge.net/projects/imagemagick/files/old-sources/6.x/6.6/ImageMagick-6.6.9-10.tar.gz
wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz
wget http://pecl.php.net/get/memcache-3.0.7.tgz
wget https://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz
wget https://launchpad.net/libmemcached/1.0/1.0.13/+download/libmemcached-1.0.13.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
wget http://pecl.php.net/get/memcached-2.1.0.tgz
wget https://github.com/eaccelerator/eaccelerator/tarball/master
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
9.2 安装 php 相关的软件
这部分代码安装过好多太服务器几乎没有什么问题,可以直接全部复制粘贴到ssh就好了,我就不打 # 号了
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make && make install
cd ../
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 ../../
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
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
ln -sv /usr/lib64/libldap* /usr/lib/
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install
cd ../
9.3 新建扩展配置目录
# mkdir -p /usr/local/php/etc/php.d/
9.4 开始安装 PHP 5.4.8
# tar xvzf php-5.4.8.tar.gz
# cd php-5.4.8/
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql/ --with-iconv-dir=/usr/local --enable-fpm \
--disable-phar --with-fpm-user=www --with-fpm-group=www --with-pcre-regex \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir \
--enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir \
--enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt \
--enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip \
--enable-bcmath --with-snmp --disable-ipv6 --with-xmlrpc --with-ldap --with-ldap-sasl --enable-exif \
--enable-soap --enable-pdo --with-pdo-mysql --enable-sysvsem --enable-inline-optimization --with-curlwrappers
# make ZEND_EXTRA_LIBS='-liconv'
# make test
# make install
# cp php.ini-production /usr/local/php/etc/php.ini
# PATH=/usr/local/php/bin:$PATH
# PATH=/usr/local/php/sbin:$PATH
提示:
--enable-fastcgi --enable-force-cgi-redirect PHP 5.3以后已经强制开启了 fastcgi 了,具体查看官方说明:
https://bugs.php.net/bug.php?id=50840&edit=1 最下面 FastCGI is now always enabled and cannot be disabled.
错误:
configure: error: Cannot find ldap libraries in /usr/lib.
解决办法:
ln -sv /usr/lib64/libldap* /usr/lib/
注意 make test 的时候可能会出现 :
/mnt/sun/php-5.4.8/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
32位系统
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
64位系统
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
9.5 开机启动 php-fpm
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --level 2345 php-fpm on
# cd ../
9.6 关于php-fpm 的操作说明与添加系统服务
PHP5.3.3以上版本的php-fpm重启、停止命令已经不是php-fpm start|stop|reload了,
需要使用信号控制:
详细内容查看该文章
PHP 5.4.8 添加系统服务命令
http://www.zhouz.me/post/2012-10-24/40041265730
9.7 安装 PHP 扩展
9.7.1 服务器版 memcached
memcached 把我搞晕了,有两个 memcached,我也不是很清楚具体区别,
按我的理解应该是分为 服务器版 和 php 扩展版
一开始用 服务器版来编译 php 扩展,搞了半天都没弄出来,后来才发现居然有两个,晕死了
安装依赖包:
# tar zxvf libevent-2.0.20-stable.tar.gz
# cd libevent-2.0.20-stable
# ./configure --prefix=/usr/local/libevent
# make && make install
# cd ../
# tar xvzf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure --enable-64bit --enable-threads --with-libevent=/usr/local/libevent
# make && make install
# cd ../
检测是否安装成功:
# ls -al /usr/local/bin/memcached
# mkdir -p /var/run/memcached/
启动 memcached:
# /usr/local/bin/memcached -d -m 128 -u root -l 22.11.5.91 -p 11211 -c 256 -P /var/run/memcached/memcached.pid
# ps aux|grep memcached
关闭 memcached:
# kill `cat /var/run/memcached/memcached.pid`
新建启动和关闭脚本并赋执行权限:
# cp memcached-1.4.15/scripts/memcached.sysv /etc/init.d/memcached
# chmod 755 /etc/init.d/memcached
修改配置:
# vi /etc/init.d/memcached
修改:
PORT=11212
USER=root
OPTIONS=""
查找:
daemon memcached -d -p ....
修改为:
daemon /usr/local/bin/memcached -d -p ....
添加下面两行:
chown $USER /usr/local/bin/memcached
/usr/local/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcache/memcached.pid $OPTIONS
添加到系统服务:
# chkconfig --add memcached
# chkconfig --level 2345 memcached on
# chkconfig --list memcached
测试启动 检测 关闭:
# service memcached start
# ps aux|grep memcached
# service memcached stop
开启防火墙外网访问(单机可忽略该设置):
# iptables -I INPUT -p tcp --dport 11211 -j ACCEPT
# iptables -I OUTPUT -p tcp --sport 11211 -j ACCEPT
# iptables-save
# service iptables save
9.7.2 安装php扩展版 memcached
依赖库:
# tar zxvf libmemcached-1.0.13.tar.gz
# cd libmemcached-1.0.13
# ./configure --prefix=/usr/local/libmemcached
# make && make install
# cd ../
安装 memcached
# tar vxzf memcached-2.1.0.tgz
# cd memcached-2.1.0
# /usr/local/php/bin/phpize
# ./configure --enable-memcached --with-libmemcached-dir=/usr/local/libmemcached --with-php-config=/usr/local/php/bin/php-config
# make && make install
# cd ..
9.7.3 安装 memcache
# tar zxvf memcache-3.0.7.tgz
# cd memcache-3.0.7/
# /usr/local/php/bin/phpize
# ./configure --prefix=/usr/local/memcache --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make && make install
# cd ../
9.7.4 安装图片处理软件 可取代 gd
# tar zxvf ImageMagick-6.8.0-2.tar.gz
# cd ImageMagick-6.8.0-2/
# export CFLAGS='-fPIC'
# ./configure --prefix=/usr/local/ImageMagick --with-quantum-depth=8 --enable-share --enable-static
# make && make install
# cd ../
# tar zxvf imagick-3.1.0RC2.tgz
# cd imagick-3.1.0RC2/
# /usr/local/php/bin/phpize
# export PKG_CONFIG_PATH=/usr/local/ImageMagick/lib/pkgconfig/
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/ImageMagick
# make && make install
# cd ../
9.7.5 安装 eaccelerator 给 php 编译加速+缓存
# wget https://github.com/eaccelerator/eaccelerator/tarball/master
# mv master eaccelerator-eaccelerator-42067ac.tar.gz
# tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz
# cd eaccelerator-eaccelerator-42067ac/
# /usr/local/php/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
# make && make install
# cd ../
新建目录:
# mkdir /tmp/eaccelerator_cache
# chmod 0777 /tmp/eaccelerator_cache
9.7.6 配置扩展
打开自动扫描的扩展目录:
# cd /usr/local/php/etc/php.d
--------------------------------忽略分割线------------------------------
# vi eaccelerator.ini
写入:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
eaccelerator.shm_size="20"
eaccelerator.cache_dir="/tmp/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"
--------------------------------忽略分割线------------------------------
# vi memcache.ini
写入:
extension = "memcache.so"
memcache.chunk_size = 32768
--------------------------------忽略分割线------------------------------
# vi memcached.ini
写入:
extension = "memcached.so"
--------------------------------忽略分割线------------------------------
# vi imagick.ini
写入:
extension = "imagick.so"
--------------------------------忽略分割线------------------------------
修改php配置:
# vi /usr/local/php/etc/php.ini
查找并修改:
cgi.fix_pathinfo=0
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"
expose_php = Off
allow_url_fopen = Off
open_basedir = /tmp/:/var/www/
disable_functions = exec,system,passthru,chroot,scandir,chgrp,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
date.timezone = Asia/Shanghai
拷贝 php-fpm 配置:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vi /usr/local/php/etc/php-fpm.conf
查找并修改:
以下为示例数值,按自己服务器实际性能配置:
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10240
rlimit_files = 65535
10. 设置开机启动
# vi /etc/rc.local
写入:
ulimit -SHn 65535
service mysqld start
service php-fpm start
service memcached start
service nginx start
11. 配置完成
弄了好几天,每天都熬到凌晨3点,终于弄完了,搞服务器真要累死人。。。
写这个不容易,转载请注明出处啊,谢谢!
神神的蜗牛 http://www.zhouz.me/post/2012-10-24/40041265730