centos6.5编译安装lnmp环境

啊 公司要开始新项目 移动的app 名字叫安好 运维太坑爹了 给了个破配置 Xeon(TM) CPU 3.40GHz 4G 内存 80G硬盘,天杀的这得多穷,留一下安装笔记吧,以后估计服务器还是得我安装df -h 之后 看了下根目录最大 那直接放根目录了 不放home下了

mkdir -p /Data/tgz /Data/apps /Data/webapps /Data/logs mkdir -p /Data/backup
版本
cat /etc/redhat-release
CentOS release 6.5 (Final)

uname -a
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

一。先安装nginx
cd /Data/tgz
yum update

yum install -y wget openssl*

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 make
yum -y install gd gd2 gd-devel gd2-devel
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
ulimit -SHn 65535
wget http://ftp.exim.llorien.org/pcre/pcre-8.34.tar.gz

tar zxvf pcre-8.34.tar.gz

cd pcre-8.34

./configure --prefix=/Data/apps/pcre

make && make install

cd ..

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

tar -zxvf nginx-1.7.7.tar.gz
cd nginx-1.7.7

./configure --user=www --group=www --prefix=/Data/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/Data/tgz/pcre-8.34 --with-http_realip_module --with-http_image_filter_module --with-http_stub_status_module

make && make install

cd ..

二。二进制安装mysql

wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.12-linux-glibc2.5-x86_64 /Data/apps/mysql

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

mkdir -p /Data/data/mysql/data

sed -i "s#/usr/local/mysql#/Data/apps/mysql#g" /Data/apps/mysql/bin/mysqld_safe

cd /Data/apps/mysql

chmod +w /Data/apps/mysql

chown -R mysql:mysql /Data/apps/mysql

ln -s /Data/apps/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
yum install libaio.x86_64
cd support-files/

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

chmod +x /etc/init.d/mysqld
/Data/apps/mysql/scripts/mysql_install_db --user=mysql --basedir=/Data/apps/mysql --datadir=/Data/apps/mysql/data
vi /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)
basedir=/Data/apps/mysql
datadir=/Data/apps/mysql/data
vi /Data/apps/mysql/my.cnf
basedir=/Data/apps/mysql

datadir=/Data/apps/mysql/data
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
chkconfig --add mysqld
chkconfig --level 345 mysqld on
mkdir /var/run/mysqld/
chown -R mysql:mysql /var/run/mysqld
/Data/apps/mysql/bin/mysqld_safe &

修改密码
/Data/apps/mysql/bin/mysqladmin -u root password 你的密码

//进入MySQL服务器
/Data/apps/mysql/bin/mysql -h localhost -u root -p
use mysql;
update user set host = '%' where user = 'root' and host='localhost';

//赋予任何主机访问数据的权限
GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
//使修改生效

FLUSH PRIVILEGES;
//退出MySQL服务器

/Data/apps/mysql/bin/mysql>EXIT;

三。安装php依赖库
mkdir -p /Data/apps/libs/
cd /Data/tgz/
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9/
./configure --prefix=/Data/apps/libs --enable-shared --enable-static --prefix=/Data/apps/libs
make && make install
cd ../
wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

cd ../

wget http://cznic.dl.sourceforge.net/project/freetype/freetype2/2.4.12/freetype-2.4.12.tar.gz
tar zxvf freetype-2.4.12.tar.gz
cd freetype-2.4.12/
./configure --prefix=/Data/apps/libs
make && make install

cd ../

wget http://prdownloads.sourceforge.net/libpng/libpng-1.5.9.tar.gz
tar zxvf libpng-1.5.9.tar.gz
cd libpng-1.5.9/
./configure --prefix=/Data/apps/libs
make && make install
cd ../

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz"

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/Data/apps/libs
make && make install
cd libltdl/
./configure --prefix=/Data/apps/libs --enable-ltdl-install
make && make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure --prefix=/Data/apps/libs
make && make install
cd ../

vi /etc/ld.so.conf

添加:
/Data/apps/libs/lib
/Data/apps/mysql/lib/

然后:
ldconfig

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
export LDFLAGS="-L/Data/apps/libs/lib -L/usr/lib"
export CFLAGS="-I/Data/apps/libs/include -I/usr/include"
touch malloc.h
./configure --prefix=/Data/apps/libs --with-libmcrypt-prefix=/Data/apps/libs
make && make install
cd ../

wget http://cn2.php.net/get/php-5.6.12.tar.gz/from/this/mirror

mv mirror php-5.6.12.tar.gz

tar -zxvf php-5.6.12.tar.gz

cd php-5.6.12
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

export LD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

./configure --prefix=/Data/apps/php --with-config-file-path=/Data/apps/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/Data/apps/libs --with-jpeg-dir=/Data/apps/libs --with-png-dir=/Data/apps/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/Data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --enable-maintainer-zts

make

make install

cp php.ini-development /Data/apps/php/etc/php.ini

cd ../

ln -s /Data/apps/mysql/lib/libmysqlclient.so.18 /usr/lib
ldconfig

mv /Data/apps/php/etc/php-fpm.conf.default /Data/apps/php/etc/php-fpm.conf

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz

tar zxvf autoconf-latest.tar.gz

cd autoconf-2.69/

./configure --prefix=/Data/apps/libs

make && make install
cd ../

wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
export PHP_AUTOCONF="/Data/apps/libs/bin/autoconf"
export PHP_AUTOHEADER="/Data/apps/libs/bin/autoheader"
/Data/apps/php/bin/phpize
./configure --with-php-config=/Data/apps/php/bin/php-config
make && make install
cd ../

wget https://github.com/msgpack/msgpack-php/archive/msgpack-0.5.6.tar.gz
tar -zxvf msgpack-0.5.6.tar.gz
cd msgpack-php-msgpack-0.5.6/
/Data/apps/php/bin/phpize
./configure --with-php-config=/Data/apps/php/bin/php-config
make && make install

wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -zvxf m4-1.4.9.tar.gz
cd m4-1.4.9/
./configure
make && make install

打开 /Data/apps/php/etc/php.ini 查找 ; extension_dir = "ext" 修改为
extension_dir = /Data/apps/php/lib/php/extensions/no-debug-zts-20131226/
extension="memcache.so"
extension="msgpack.so"
查找
;date.timezone =
改成:
date.timezone = Asia/Shanghai
查找
;short_open_tag
改成
short_open_tag=On

; 开关打开
opcache.enable=1

; 可用内存, 酌情而定, 单位 megabytes
opcache.memory_consumption=256

; 对多缓存文件限制, 命中率不到 100% 的话, 可以试着提高这个值
opcache.max_accelerated_files=5000

; Opcache 会在一定时间内去检查文件的修改时间, 这里设置检查的时间周期, 默认为 2, 定位为秒
opcache.revalidate_freq=240

安装memcached
yum install memcached
启动
memcached -p 11211 -d -m 2048 -u root -c 65535 -l 0.0.0.0 -P /tmp/memcached-11211.pid

安装redis和phpredis
wget http://download.redis.io/releases/redis-3.0.3.tar.gz

tar -zxvf redis-3.0.3.tar.gz
cd redis-3.0.3
make
make install
cp redis.conf /etc/
vi /etc/redis.conf
daemonize 改成yes
masterauth 你的密码
maxmemory 你的参数
启动 /usr/local/bin/redis-server /etc/redis.conf
下载phpredis https://github.com/nicolasff/phpredis
wget https://github.com/nicolasff/phpredis/archive/master.zip -O phpredis.zip
unzip phpredis.zip
cd phpredis-master/
/Data/apps/php/bin/phpize
./configure --with-php-config=/Data/apps/php/bin/php-config
make && make install
vi /Data/apps/php/etc/php.ini
加上extension = “redis.so"

安装php框架yaf
cd /Data/tgz
wget http://pecl.php.net/get/yaf-2.3.3.tgz

tar -zxvf yaf-2.3.3.tgz
cd yaf-2.3.3

/Data/apps/php/bin/phpize

./configure --with-php-config=/Data/apps/php/bin/php-config
make && make install
结果

Installing shared extensions: /Data/apps/php/lib/php/extensions/no-debug-zts-20131226/

vi /Data/apps/php/etc/php.ini
加上

extension=yaf.so
yaf.library="/Data/webapps/lianchuangcms/library"

安装php性能监测模块XHProf

wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar -zxvf xhprof-0.9.4.tgz
cd xhprof-0.9.4/extension/

/Data/apps/php/bin/phpize

./configure --with-php-config=/Data/apps/php/bin/php-config

make && make install

mkdir -p /Data/logs/xhpof

vi /Data/apps/php/etc/php.ini
加上
extension=xhprof.so
xhprof.output_dir=/Data/logs/xhpof

安装sphinx
cd /Data/tgz/
wget -c http://sphinxsearch.com/files/sphinx-2.1.6-release.tar.gz
tar -zxvf sphinx-2.1.6-release.tar.gz
cd sphinx-2.1.6-release
./configure --prefix=/Data/apps/sphinx --with-mysql=/Data/apps/mysql/ --with-libexpat --enable-id64
make && make install vi /Data/apps/sphinx/etc/sphinx.conf 配置索引文件

/Data/apps/sphinx/bin/indexer -c /Data/apps/sphinx/etc/sphinx.conf --all 建立索引

/Data/apps/sphinx/bin/searchd -c /Data/apps/sphinx/etc/sphinx.conf 启动索引

安装分词系统 httpcws
什么是 httpcws 请看 http://blog.s135.com/httpcws_v100/
cd /Data/tgz
wget http://httpcws.googlecode.com/files/httpcws-1.0.0-x86_64-bin.tar.gz
tar -zxvf httpcws-1.0.0-x86_64-bin.tar.gz
ulimit -SHn 65535
mv httpcws-1.0.0-x86_64-bin /Data/apps/httpcws
cd /Data/apps/httpcws

/Data/apps/httpcws/httpcws -d -x /Data/apps/httpcws/dict/

自定义词库 修改dict/httpcws_dict.txt文件

安装php的sphinx扩展
mkdir /Data/apps/sphinx/sphinxclient
cd /Data/tgz/sphinx-2.1.6-release/api/libsphinxclient
./configure --prefix=/Data/apps/sphinx/sphinxclient/
make && make install
cd /Data/tgz
wget -c http://pecl.php.net/get/sphinx-1.3.0.tgz
tar -zxvf sphinx-1.3.0.tgz
cd sphinx-1.3.0
/Data/apps/php/bin/phpize
./configure --with-php-config=/Data/apps/php/bin/php-config --with-sphinx=/Data/apps/sphinx/sphinxclient/
make && make install

vi /Data/apps/php/etc/php.ini
加上
extension=sphinx.so

安装xcache
wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gztar -zxvf xcache-3.1.0.tar.gz
cd xcache-3.1.0
/Data/apps/php/bin/phpize
./configure --enable-xcache --with-php-config=/Data/apps/php/bin/php-config

make && make install
echo -n "123456" | md5sum
vi /Data/apps/php/etc/php.ini
加上
extension=xcache.so
[xcache.admin]
xcache.admin.user = "admin"
xcache.admin.pass = ""
; xcache.admin.pass = md5($your_password)
xcache.admin.enable_auth = On
[xcache]
xcache.cacher = On
xcache.size = 64M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 3600
xcache.gc_interval = 300
xcache.var_size = 0M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.readonly_protection = Off
xcache.mmap_path = “/tmp/xcache”

安装消息队列 httpsqs
cd /Data/tgz/mkdir /Data/logs/httpsqs /Data/data/httpsqs
wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gztar zxvf tokyocabinet-1.4.47.tar.gz
cd tokyocabinet-1.4.47/
./configure –prefix=/usr/local/tokyocabinet-1.4.47/
make && make install
cd ..
wget http://iweb.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.12-stable.tar.gz
tar zxvf libevent-2.0.12-stable.tar.gz
cd libevent-2.0.12-stable/
./configure --prefix=/usr/local/libevent-2.0.12-stable/
make && make install
cd ../
wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz
tar zxvf httpsqs-1.7.tar.gz
cd httpsqs-1.7/
make && make install
cd ../

启动 /usr/bin/httpsqs -d -p 5918 -t 10 -c 10000 -m 512 -x /Data/data/httpsqs/ -a kele

vim /etc/rc.local
添加
ulimit -SHn 65535
/Data/apps/nginx/sbin/nginx
/Data/apps/php/sbin/php-fpm
memcached -p 11211 -d -m 2048 -u root -c 65535 -l 0.0.0.0 -P /tmp/memcached-11211.pid
/usr/local/bin/redis-server /etc/redis.conf
/usr/bin/httpsqs -d -p 5918 -t 10 -c 10000 -m 512 -x /Data/data/httpsqs/ -a kele
/Data/apps/httpcws/httpcws -d -x /Data/apps/httpcws/dict/
保存退出

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 5918-j ACCEPT

service iptables save
chkconfig --level 2345 iptables on

linux下用ulimit设置连接数最大值,默认是1024.在高负载下要设置为更高,但最高只能为65535.

ulimit只能做临时修改,重启后失效。
可以加入
ulimit -SHn 65535
到 /etc/rc.local 每次启动启用。

终极解除 Linux 系统的最大进程数和最大文件打开数限制:
vim /etc/security/limits.conf

添加如下的行

  • soft nproc 11000
  • hard nproc 11000
  • soft nofile 655350
  • hard nofile 655350

参考文档
http://blog.s135.com/nginx_php_v7/
http://my.oschina.net/grail/blog/150464
http://www.blogjava.net/wangxinsh55/archive/2011/10/24/361913.html
http://www.oschina.net/question/12_18065

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,012评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,589评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,819评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,652评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,954评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,381评论 1 210
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,687评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,404评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,082评论 1 238
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,355评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,880评论 1 255
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,249评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,864评论 3 232
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,007评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,760评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,394评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,281评论 2 259

推荐阅读更多精彩内容