美文网首页
centos6.5编译安装lnmp环境

centos6.5编译安装lnmp环境

作者: xiasix | 来源:发表于2016-01-21 13:22 被阅读0次

    啊 公司要开始新项目 移动的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

    相关文章

      网友评论

          本文标题:centos6.5编译安装lnmp环境

          本文链接:https://www.haomeiwen.com/subject/aamlkttx.html