阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS6 编译安装LNMP步骤

117次阅读
没有评论

共计 15403 个字符,预计需要花费 39 分钟才能阅读完成。

# 手动安装 lnmp
包含 libiconv libunwind gperftools libmcrypt mhash mcrypt libpng freetype jpeg
gd pcre libmemcached php_memcached(memcached.so)  eaccelerator ZendOptimizer
MySQL5.5 php5.3 nginx1.2.7 memcached tokyocabinet tokyotyrant
# 路径
程序存放      /data/service
lib or common /data/service/common
数据存放      /data/data
日志存放      /data/logs

# yum 源更改
rm -f CentOS6-Base-163.repo \
rm -f /etc/yum.repos.d/CentOS6-Base-163.repo
yum install -y wget   
wget -4 –no-cache http://mirrors.163.com/.help/CentOS6-Base-163.repo \
-O /etc/yum.repos.d/CentOS6-Base-163.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

yum makecache && yum update -y && rm -f /etc/yum.repos.d/CentOS-Base.repo

yum install ntp wget cpp gcc gcc-c++ gcc-g77 make unzip libtool \
libtool-ltdl-devel libc-client-devel libstdc++-devel db4-utils libcap-devel \
expat-devel perl pam-devel perl-Time-HiRes libaio-devel bzr patch bzip2-devel \
cmake bison libevent-devel ncurses-devel openssl-devel zlib-devel curl-devel \
libxml2-devel tcp_wrappers-devel nasm lemon flex libXpm-devel fontconfig-devel \
pcre-devel sqlite-devel perl-ExtUtils-Embed neon-devel

# libiconv
./configure
make && make install
echo “/usr/local/lib” >> \
/etc/ld.so.conf.d/service_lib.conf && /sbin/ldconfig

# libunwind
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC && make CFLAGS=-fPIC install

# gperftools
./configure –enable-frame-pointers
make && make install
/sbin/ldconfig

# mysql 5.5
groupadd mysql -g 1002
useradd mysql -u 1002 -g mysql -s /sbin/nologin

rm -f CMakeCache.txt
cmake \
. -DCMAKE_INSTALL_PREFIX=/data/service/mysql \
-DMYSQL_DATADIR=/data/data/mysql \
-DSYSCONFDIR=/data/service/mysql/etc \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0
make && make install

ln -s /data/service/mysql/lib /data/service/mysql/lib64
echo “/data/service/mysql/lib64/” >> \
/etc/ld.so.conf.d/service_lib.conf && /sbin/ldconfig
mkdir -p /data/service/mysql/etc && mkdir -p /data/data/mysql
cp -f support-files/my-medium.cnf /data/service/mysql/etc/my.cnf
## add gperftools
sed -i ‘s/executing\ mysqld_safe$/&\nexport\ LD_PRELOAD=”\/usr\/local\/lib\/libtcmalloc.so”/’ \
/data/service/mysql/bin/mysqld_safe

cp -f support-files/mysql.server /data/service/mysql/mysqld
chmod 755 /data/service/mysql/mysqld
chown -R mysql.mysql /data/data/mysql

vim /data/service/mysql/etc/my.cnf
[mysqld]
pid-file        = /data/data/mysql/mysqld.pid
datadir        = /data/data/mysql

max_connections = 500
max_connect_errors=10000
slow_query_log=1
slow_query_log_file = /data/data/mysql/slowsql.log
long_query_time = 2
log-queries-not-using-indexes

innodb_file_per_table = 1
innodb_data_home_dir = /data/data/mysql
innodb_data_file_path = ibdata1:10M:autoextend:max:2000M
innodb_log_group_home_dir = /data/data/mysql
innodb_file_per_table = 1
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 2M
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
sync_binlog = 1
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 50

log-bin=mysql-bin
binlog_format = mixed
expire_logs_days = 7

[mysqld_safe]
log-error = /data/data/mysql/mysql.log

/data/service/mysql/scripts/mysql_install_db \
–user=mysql –basedir=/data/service/mysql –datadir=/data/data/mysql

# mysql5.1
./configure \
–prefix=/data/service/mysql \
–localstatedir=/data/data/mysql \
–sysconfdir=/data/service/mysql/etc \
–with-mysqld-user=mysql \
–without-debug \
–with-big-tables \
–with-unix-socket-path=/tmp/mysql.sock \
–with-charset=gbk \
–with-collation=gbk_chinese_ci \
–with-extra-charsets=all \
–with-plugins=partition \
–enable-static \
–with-client-ldflags=-all-static \
–with-tcp-port=3306

/data/service/mysql/mysqld start
/data/service/mysql/mysqld restart
#/data/service/mysql/bin/mysqladmin -uroot password
/data/service/mysql/mysqld stop

# libmcrypt
./configure –prefix=/data/service/common/libmcrypt
make && make install
ln -s /data/service/common/libmcrypt/lib /data/service/common/libmcrypt/lib64
echo “/data/service/common/libmcrypt/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# mhash
./configure –prefix=/data/service/common/mhash
make && make install
ln -s /data/service/common/mhash/lib /data/service/common/mhash/lib64
echo “/data/service/common/mhash/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# mcrypt
#LD_LIBRARY_PATH=/data/service/common/libmcrypt/lib:/data/service/common/mhash/lib \
LDFLAGS=”-L/data/service/common/mhash/lib/ -I/data/service/common/mhash/include/” \
CFLAGS=”-I/data/service/common/mhash/include/” \
./configure –prefix=/data/service/common/mcrypt \
–with-libmcrypt-prefix=/data/service/common/libmcrypt
make && make install
ln -s /data/service/common/mcrypt/lib /data/service/common/mcrypt/lib64
echo “/data/service/common/mcrypt/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# libpng
# 下面这句,测试不能执行,否则就会报告下面的错误,而且无法安装到 /usr/lib/libpng/ 下
#cp scripts/makefile.linux makefile
./configure –prefix=/data/service/common/libpng –enable-shared –enable-static
make && make install
ln -s /data/service/common/libpng/lib /data/service/common/libpng/lib64
echo “/data/service/common/libpng/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# freetype
./configure –prefix=/data/service/common/freetype –enable-shared –enable-static
make && make install
ln -s /data/service/common/freetype/lib /data/service/common/freetype/lib64
echo “/data/service/common/freetype/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# libjpeg
./configure –prefix=/data/service/common/libjpeg –enable-shared –enable-static
make && make install
ln -s /data/service/common/libjpeg/lib /data/service/common/libjpeg/lib64
echo “/data/service/common/libjpeg/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# gd
yum install libXpm-devel fontconfig-devel
PATH=/data/service/common/libpng/bin/:$PATH \
LDFLAGS=”-L/data/service/common/libpng/lib/” \
CFLAGS=”-I/data/service/common/libpng/include/” \
./configure –prefix=/data/service/common/gd \
–enable-shared –enable-static \
–with-png=/data/service/common/libpng \
–with-freetype=/data/service/common/freetype \
–with-jpeg=/data/service/common/libjpeg
make && make install
ln -s /data/service/common/gd/lib /data/service/common/gd/lib64
echo “/data/service/common/gd/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# pcre
./configure –prefix=/data/service/common/pcre \
–enable-shared –enable-static
make && make install
ln -s /data/service/common/pcre/lib /data/service/common/pcre/lib64
echo “/data/service/common/pcre/lib64” >> \
/etc/ld.so.conf.d/service_lib.conf && ldconfig

# php5.3
./configure  \
–prefix=/data/service/phpfpm \
–with-config-file-path=/data/service/phpfpm/etc \
–with-libdir=lib64 \
–with-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-mcrypt=/data/service/common/libmcrypt \
–with-mhash=/data/service/common/mhash \
–with-gd=/data/service/common/gd \
–with-pcre-dir=/data/service/common/pcre \
–with-freetype-dir=/data/service/common/freetype \
–with-jpeg-dir=/data/service/common/libjpeg \
–with-png-dir=/data/service/common/libpng \
–with-openssl \
–with-zlib \
–with-curl \
–with-curlwrappers \
–with-xmlrpc \
–with-bz2 \
–with-gettext \
–with-xpm-dir \
–enable-fpm \
–enable-ftp \
–enable-sockets \
–enable-xml \
–enable-bcmath \
–enable-shmop \
–enable-sysvsem \
–enable-inline-optimization \
–enable-mbregex \
–enable-mbstring \
–enable-gd-native-ttf \
–enable-sockets \
–enable-zip \
–enable-soap \
–enable-pcntl \
–disable-rpath

make && make install
mkdir -p /data/service/phpfpm/etc
cp -f php.ini-production /data/service/phpfpm/etc/php.ini
sed -i ‘$a \\nextension_dir = “/data/service/phpfpm/lib/php/extensions/no-debug-non-zts-20090626/”‘ \
/data/service/phpfpm/etc/php.ini

#php5.2
wget -4 http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz
./configure –prefix=/data/service/common/autoconf_2.13 \
make && make install

wget -4 http://cn2.php.net/distributions/php-5.2.17.tar.gz
wget -4 http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
wget -4 https://raw.github.com/laruence/laruence.github.com/master/php-5.2-max-input-vars/php-5.2.17-max-input-vars.patch
gzip -d php-5.2.17-fpm-0.5.14.diff.gz
tar zxf php-5.2.17.tar.gz
cd php-5.2.17
patch -p1 < ../php-5.2.17-fpm-0.5.14.diff
patch -p1 < ../php-5.2.17-max-input-vars.patch
rm -rf configure \
&& PHP_AUTOCONF=”/data/service/common/autoconf_2.13/bin/autoconf” \
PHP_AUTOHEADER=”/data/service/common/autoconf_2.13/bin/autoheader” \
./buildconf –force

./configure  –prefix=/data/service/phpfpm_52 \
–with-config-file-path=/data/service/phpfpm_52/etc \
–with-libdir=lib64 \
–with-mysql=/data/service/mysql \
–with-mysqli=/data/service/mysql/bin/mysql_config \
–with-pdo-mysql=/data/service/mysql \
–with-mcrypt=/data/service/common/libmcrypt \
–with-mhash=/data/service/common/mhash \
–with-gd=/data/service/common/gd \
–with-freetype-dir=/data/service/common/freetype \
–with-jpeg-dir=/data/service/common/libjpeg \
–with-png-dir=/data/service/common/libpng \
–with-openssl \
–with-zlib \
–with-curl \
–with-curlwrappers \
–with-xmlrpc \
–with-bz2 \
–with-xpm-dir \
–enable-fpm \
–enable-fastcgi \
–enable-force-cgi-redirect \
–enable-ftp \
–enable-sockets \
–enable-xml \
–enable-bcmath \
–enable-shmop \
–enable-inline-optimization \
–enable-mbregex \
–enable-mbstring \
–enable-gd-native-ttf \
–enable-sockets \
–enable-zip \
–enable-soap \
–enable-pcntl \
–disable-rpath
make && make install
mkdir -p /data/service/phpfpm_52/etc
cp -f php.ini-recommended /data/service/phpfpm_52/etc/php.ini
cp sapi/cgi/fpm/php-fpm /data/service/phpfpm_52/bin/php-fpm && chmod 755 /data/service/phpfpm_52/bin/php-fpm
sed -i ‘$a \\nextension_dir = “/data/service/phpfpm_52/lib/php/extensions/no-debug-non-zts-20060613/”‘ /data/service/phpfpm_52/etc/php.ini
short_open_tag = On

# memcached/tar.gz
./configure –prefix=/data/service/memcached
make && make install

# libmemcached
./configure –prefix=/data/service/common/libmemcached \
–with-memcached=/data/service/memcached
make && make install
ln -s /data/service/common/libmemcached/lib /data/service/common/libmemcached/lib64

# memcache.so/tgz php_memcache
/data/service/phpfpm/bin/phpize \
&& ./configure \
–enable-memcache \
–with-php-config=/data/service/phpfpm/bin/php-config
make && make install
sed -i ‘$a \;extension=memcache.so’ /data/service/phpfpm/etc/php.ini
## php5.2
/data/service/php/bin/phpize \
&& ./configure \
–enable-memcache \
–with-php-config=/data/service/php/bin/php-config
make && make install
sed -i ‘$a \;extension=memcache.so’ /data/service/php/etc/php.ini

# memcached.so/tgz zlib/php_memcached
/data/service/php/bin/phpize \
&& ./configure \
–with-php-config=/data/service/php/bin/php-config \
–enable-memcached \
–with-libmemcached-dir=/data/service/common/libmemcached
make && make install
sed -i ‘$a \extension=memcached.so’ /data/service/php/etc/php.ini
sed -i “s#session.save_handler\ =\ files#;session.save_handler\ =\ files#g” /data/service/phpfpm/etc/php.ini
sed -i ‘$a \;session.save_handler = memcached\n;session.save_path = “ip:port”‘ /data/service/phpfpm/etc/php.ini
## php5.2
/data/service/phpfpm_52/bin/phpize \
&& ./configure \
–with-php-config=/data/service/phpfpm_52/bin/php-config \
–enable-memcached \
–with-libmemcached-dir=/data/service/common/libmemcached
make && make install
sed -i ‘$a \extension=memcached.so’ /data/service/phpfpm_52/etc/php.ini
sed -i “s#session.save_handler\ =\ files#;session.save_handler\ =\ files#g” /data/service/phpfpm_52/etc/php.ini
sed -i ‘$a \;session.save_handler = memcached\n;session.save_path = “ip:port”‘ /data/service/phpfpm_52/etc/php.ini

# eaccelerator
/data/service/phpfpm/bin/phpize \
&& ./configure \
–enable-eaccelerator=shared \
–with-php-config=/data/service/phpfpm/bin/php-config
make && make install
sed -i ‘$a \;extension=eaccelerator.so’ /data/service/phpfpm/etc/php.ini
## php5.2
/data/service/php/bin/phpize \
&& ./configure \
–enable-eaccelerator=shared \
–with-php-config=/data/service/php/bin/php-config
make && make install
sed -i ‘$a \;extension=eaccelerator.so’ /data/service/php/etc/php.ini

#APC
/data/service/phpfpm/bin/phpize \
&& ./configure \
–enable-eaccelerator=shared \
–with-php-config=/data/service/phpfpm/bin/php-config
make && make install
sed -i ‘$a \;extension=eaccelerator.so’ /data/service/phpfpm/etc/php.ini

# ZendGuardLoader php5.3
cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so \
/data/service/phpfpm/lib/php/extensions/no-debug-non-zts-20090626/
sed -i ‘$a \\n\;[Zend]\n;zend_extension=”/data/service/phpfpm/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so”\n;zend_loader.enable=1\n;zend_loader.disable_licensing=0\n;zend_loader.obfuscation_level_support=3\n;zend_loader.license_path=\n’ /data/service/phpfpm/etc/php.ini

# ZendOptimizer php5.2
cp ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /data/service/phpfpm_52/lib/php/extensions/no-debug-non-zts-20060613/
sed -i ‘$a \\n\;[Zend]\n;zend_extension=”/data/service/phpfpm_52/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so”\n;zend_loader.enable=1\n;zend_loader.disable_licensing=0\n;zend_loader.obfuscation_level_support=3\n;zend_loader.license_path=\n’ /data/service/phpfpm_52/etc/php.ini

# nginx
groupadd www -g 1001
useradd www -u 1001 -g www -s /sbin/nologin

./configure \
–prefix=/data/service/nginx \
–with-http_stub_status_module \
–with-pcre=../pcre-8.32 \
–with-http_ssl_module \
–with-google_perftools_module
make && make install

#vsftpd
vi defs.h
把 /etc/vsftpd.conf /data/service/vsftpd/etc/vsftpd.conf
vi builddefs.h
把 #undef VSF_BUILD_TCPWRAPPERS 修改成 #define VSF_BUILD_TCPWRAPPERS
把 #undef VSF_BUILD_SSL                修改成 #define VSF_BUILD_SSL
make

mkdir -p /data/service/vsftpd/sbin /data/service/vsftpd/man /data/service/vsftpd/etc /data/service/vsftpd/etc/virtual
cp vsftpd /data/service/vsftpd/sbin/vsftpd \
&& chmod 755 /data/service/vsftpd/sbin/vsftpd
cp vsftpd.8 /data/service/vsftpd/man/vsftpd.8 \
&& chmod 644 /data/service/vsftpd/man/vsftpd.8
cp vsftpd.conf.5 /data/service/vsftpd/man/vsftpd.conf.5 \
&& chmod 644 /data/service/vsftpd/man/vsftpd.conf.5
cp vsftpd.conf /data/service/vsftpd/etc/vsftpd.conf.default \
&& chmod 644 /data/service/vsftpd/etc/vsftpd.conf.default
cp RedHat/vsftpd.pam /data/service/vsftpd/etc/vsftpd.pam \
&& chmod 644 /data/service/vsftpd/etc/vsftpd.pam
echo -e “user\npassword\n” > /data/service/vsftpd/etc/user_pass
echo “user” > /data/service/vsftpd/etc/user_list
echo “/usr/bin/db_load -T -t hash -f /data/service/vsftpd/etc/user_pass /data/service/vsftpd/etc/login.db” \
>> /data/service/vsftpd/sbin/pass.sh
chmod 755 /data/service/vsftpd/sbin/pass.sh
echo “auth required /lib64/security/pam_userdb.so db=/data/service/vsftpd/etc/login” > /etc/pam.d/vsftpd
echo “account required /lib64/security/pam_userdb.so db=/data/service/vsftpd/etc/login” >> /etc/pam.d/vsftpd

# tokyo cabinet
./configure –prefix=/data/service/common/tokyocabinet
make && make install
# tokyo tyrant
./configure –prefix=/data/service/tokyotyrant –with-tc=/data/service/common/tokyocabinet
make && make install
/data/service/tokyotyrant/bin/ttserver -port 11213 -thnum 8 -dmn -pid /data/data/ttdb/ttserver.pid -log /data/data/ttdb/ttserver.log -le -ulog /data/data/ttdb/ -ulim 256m -sid 1 -rts /data/data/ttdb/ttserver.rts /data/data/ttdb/database.tcb#lmemb=1024#nmemb2048#bnum10000000

/data/service/memcached/bin/memcached -d -u www -c 64 -p 11212

相关阅读:

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 6.4 下的 LNMP 生产环境搭建及安装脚本 http://www.linuxidc.com/Linux/2013-11/92428.htm

生产环境实用之 LNMP 架构的编译安装 +SSL 加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm

LNMP 全功能编译安装 for CentOS 6.3 笔记 http://www.linuxidc.com/Linux/2013-05/83788.htm

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计15403字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中