生産環境搭建LNMP平台
版本号MySQL5.5.37 php-5.5.14
nginx-1.6.0 mongo-1.5.4
libiconv-1.14 gettext-0.18.1.1
libmcrypt-2.5.8 mcrypt-2.6.8
mhash-0.9.9 memcache-2.2.7
zlib-1.2.5 ImageMagick-6.8.8-9
libpng-1.6.2 imagick-3.1.2
freetype-2.4.12 pcre-8.35
php子產品
pthreads.so
redis.so
imap.so
memcache.so
imagick.so
opcache.so
mongo.so
服務重新加載
service nginx reload
service php-fpm reload
service mysqld restart
配置檔案路徑nginx
/usr/local/nginx/conf/nginx.conf
php
/usr/local/php/etc/php-fpm.conf
/usr/local/php/etc/php.ini
mysql
/etc/my.cnf
下面開始
Centos 6.5 64位CentOS-6.5-x86_64-minimal.iso最小化安裝
關閉selinux SELINUX=disabled
shutdown -r now #不重新開機的話,更新ssh後下一次重新開機,ssh會啟動失敗
yum install gcc gcc-c++ vim wget lrzsz ntpdate sysstat dstat wget man tree -y
tar -xzf ifstat-1.1.tar.gz
cd ifstat-1.1
./configure
make
make install
cd ..
yum install ncurses ncurses-devel libpcap libpcap-devel -y
tar -xzf iftop-0.17.tar.gz
cd iftop-0.17
./configure
make
make install
cd ..
tar -xzf htop-1.0.tar.gz
cd htop-1.0
./configure
make
make install
cd ..
# /usr/local/bin/htop
# /usr/local/bin/ifstat
echo "export PATH=$PATH:/usr/local/bin" >> /etc/profile.d/tools.sh
. /etc/profile.d/tools.sh
yum install -y vim-enhanced patch make flex bison file libtool libtool-libs autoconf libjpeg-devel libpng libpng-devel gd gd-devel freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel fonts-chinese gettext-devel gmp-devel pspell-devel unzip libcap apr* automake openssl-devel perl compat* mpfr cpp glibc glibc-devel libgomp libstdc++-devel ppl cloog-ppl keyutils keyutils-libs-devel libcom_err-devel libsepol-devel krb5-devel libXpm* php-common php-gd pcre-devel libmcrypt-devel gd2 gd2-devel openldap*
#Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate 0.asia.pool.ntp.org ;hwclock -w
cat >>/etc/sysctl.conf<
fs.file-max = 65535
eof
ulimit -SHn 65535
mkdir /data
cd /data/ #軟體包都放此目錄
編譯安裝MySQL5.5.37
安裝cmake2.8.7 跨平台的安裝(編譯)工具tar -zxf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
make&& make install
cd ..
編譯安裝mysql/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /var/mysql/data
mkdir -p /var/mysql/log
chown -R mysql.mysql /var/mysql
tar zxf mysql-5.5.37.tar.gz
cd mysql-5.5.37
cmake -DCMAKE_BUILD_TYPE:STRING=Release -DMYSQL_USER=mysql-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make -j4
make install
複制配置檔案:
mv /etc/my.cnf /etc/my.cnf.bak
cp support-files/my-large.cnf /etc/my.cnf
vim +40 /etc/my.cnf
在[mysqld]添加:skip-name-resolve
lower_case_table_names= 1
character-set-server= utf8
query_cache_limit= 10M
max_connections= 2000
datadir= /var/mysql/data
lower_case_table_names= 1
character-set-server= utf8
log-error= /var/mysql/log/mysql-error.log
pid-file= /var/mysql/log/mysql.pid
general_log= 1
log_output=TABLE
log-bin=/var/mysql/log/mysql-bin
slow_query_log= ON
slow_query_log_file= /var/mysql/log/mysql_slow.log
long_query_time= 2
max_heap_table_size= 64M
#注釋下面的log-bin=mysql-bin
複制啟動腳本 :cp ./support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cd..
初始化資料庫/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/var/mysql/data --basedir=/usr/local/mysql --log-output=file
cat> /etc/ld.so.conf.d/mysql.conf<
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
ldconfig
yum install mysql -y
service mysqld start
/usr/local/mysql/bin/mysql_secure_installation #配置mysql
編譯安裝php-5.5.14所需元件
安裝libiconvtar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libs
make
make install
cd ../
安裝libmcrypttar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/libs
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install --prefix=/usr/local/libs
make
make install
cd ../../
安裝mhashtar xzf mhash-0.9.9.tar.gz
cd mhash-0.9.9
./configure --prefix=/usr/local/libs
make
make install
cd ../
安裝zlibtar -zxf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure --prefix=/usr/local/libs
make
make install
cd ../
安裝libpngtar -zxf libpng-1.6.2.tar.gz
cd libpng-1.6.2
./configure --prefix=/usr/local/libs
make
make install
cd ../
安裝freetypetar -zxf freetype-2.4.12.tar.gz
cd freetype-2.4.12
./configure --prefix=/usr/local/libs
make
make install
cd ../
安裝Jpegtar -zxf jpegsrc.v9.tar.gz
cd jpeg-9
./configure --prefix=/usr/local/libs --enable-shared --enable-static
make
make install
cd ../
安裝gettexttar -zxf gettext-0.18.1.1.tar.gz
cd gettext-0.18.1.1
./configure --prefix=/usr/local/libs
make
make install
cd ../
cat > /etc/ld.so.conf.d/local.conf <
/usr/local/libs/lib
/usr/local/lib
eof
ldconfig -v
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
export LDFLAGS="-L/usr/local/libs/lib -L/usr/lib"export CFLAGS="-I/usr/local/libs/include -I/usr/include"
export LD_LIBRARY_PATH=/usr/local/libs/: LD_LIBRARY_PATH
./configure --prefix=/usr/local/libs --with-libmcrypt-prefix=/usr/local/libs
make
make install
cd ../
編譯安裝PHP(FastCGI模式)
cp -frp /usr/lib64/libldap* /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
tar zxf php-5.5.14.tar.gz
cd php-5.5.14/
./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/etc --with-openssl --with-curl --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=mysqlnd --enable-mbstring=all --with-gd --with-freetype-dir=/usr/local/libs --with-jpeg-dir=/usr/local/libs --with-png-dir=/usr/local/libs --with-zlib-dir=/usr/local/libs --enable-mbstring --enable-sockets --with-iconv-dir=/usr/local/libs --enable-libxml --enable-soap --with-mcrypt=/usr/local/libs --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-gd-native-ttf --with-mhash --enable-pcntl --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-phar --without-pear --enable-ftp --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-maintainer-zts --disable-rpath --with-gettext --enable-opcache
make ZEND_EXTRA_LIBS='-liconv'
make install
——插播——
#如果php版本為php-5.3.28,那麼編譯參數為
./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/etc --with-openssl --with-curl --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=mysqlnd --enable-mbstring=all --with-gd --with-freetype-dir=/usr/local/libs --with-jpeg-dir=/usr/local/libs --with-png-dir=/usr/local/libs --with-zlib-dir=/usr/local/libs --enable-mbstring --enable-sockets --with-iconv-dir=/usr/local/libs --enable-libxml --enable-soap --with-mcrypt=/usr/local/libs --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-gd-native-ttf --with-mhash --enable-pcntl --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-phar --without-pear --enable-ftp --disable-rpath --with-gettext --enable-magic-quotes
make ZEND_EXTRA_LIBS='-liconv' -j4
make install
并且下面的pthreads-master子產品會安裝不成功,不過ming可以安裝,是以根據自己的需要考慮,其他安裝過程一緻
——插播——
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /data/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cd ../
sed -i 's/;date\.timezone \=/date\.timezone \= Asia\/Shanghai/g' /usr/local/php/etc/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/php/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions =passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname/g' /usr/local/php/etc/php.ini
編譯安裝PHP擴充子產品unzip pthreads-master.zip
cd pthreads-master
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
——插播——
php5.3安裝ming可以按下面方法,php5.5整合zend,安裝的時候提示錯誤
Ming
首先開啟PHP指令
vi ~/.bash_profile
加一行後儲存
export PATH=$PATH:/www/wdlinux/php/bin
然後運作指令
source ~/.bash_profile
wget http://pear.php.net/go-pear.phar
php go-pear.phar
中間有個問題直接enter确認就行。
wget http://jaist.dl.sourceforge.net/project/ming/Releases/ming-0.4.5.tar.gz
tar-zxvf ming-0.4.5.tar.gz
cd ming-0.4.5.tar.gz
./configure --enable-php
make && make install
完成後修改PHP.ini增加 一行
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ming.so
——插播——
memcache擴充tar -xzf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
安裝imagick擴充tar zxf ImageMagick-6.8.8-9.tar.gz
cd ImageMagick-6.8.8-9/
./configure --prefix=/usr/local/p_w_picpathmagick
make && make install
cd ..
tar -xzf imagick-3.1.2.tgz
cd imagick-3.1.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/p_w_picpathmagick
make
make install
cd ..
安裝IMAP的PHP擴充yum install libc-client.x86_64 libc-client-devel.x86_64 -y
cp /usr/lib64/libc-client.so* /usr/lib
cd php-5.5.14/ext/imap/
phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imap --with-imap-ssl --with-kerberos
make
make install
cd /data
安裝phpredis擴充unzip phpredis-master.zip
cd phpredis-master
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd /data
mongo擴充tar -xzf mongo-1.5.4.tgz
cd mongo-1.5.4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --prefix=/usr/local/mongo
make
make install
cd ..
vim /usr/local/php/etc/php.ini #在php.ini最後添加如下extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/"
extension = "pthreads.so"
extension = "redis.so"
extension = "imap.so"
extension = "memcache.so"
extension = "imagick.so"
extension = "mongo.so"
zend_extension =/usr/local/php/lib/php/extensions/no-debug-zts-20121212/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
安裝Nginx
安裝Nginxtar -zxf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr/local/pcre
make&&make install
cd ../
groupadd www
useradd -g www www -s /sbin/nologin
tar -xzf nginx-1.6.0.tar.gz
cd nginx-1.6.0/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/data/pcre-8.35 --with-http_realip_module --with-http_p_w_picpath_filter_module
make
make install
cd ../wget -c http://soft.vpser.net/lnmp/ext/init.d.nginx
cp init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
建立Nginx日志目錄mkdir -p /data/nginx/logs
chmod +w /data/nginx/logs
chown -R www:www /data/nginx/logs
修改nginx配置檔案
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bakcat > /usr/local/nginx/conf/nginx.conf <
user www www;
worker_processes 4;
error_log /data/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 300;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascripttext/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server_tokens off;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
log_not_found off;
fastcgi_intercept_errors on;
server
{
listen 80;
server_name www.yourweb.com;
index index.html index.htm index.php;
root /var/www/;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /data/nginx/logs/access.log access;
error_page 404 = /404.html;
}
include /usr/local/nginx/conf/server/*.conf;
}
eof
mkdir /usr/local/nginx/conf/server/
cp /usr/local/nginx/conf/fastcgi.conf /usr/local/nginx/conf/fcgi.conf
mkdir /var/www/
cat>/var/www/phpinfo.php<
phpinfo();
?>
eof
mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bakcat > /usr/local/php/etc/php-fpm.conf <
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = error
[www]
listen = /tmp/php-cgi.sock
user = www
group = www
listen.mode = 0666
;pm = dynamic
pm = static
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 30
request_terminate_timeout = 60
request_slowlog_timeout = 60s
slowlog = /var/log/php-fpm.log.slow
pm.max_requests = 1024
eof
更新前關閉selinux
更新ssl,sshyum install zlib zlib-devel krb5-devel.x86_64 -y #如果單獨更新openssh需要安裝
tar -xzf openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
./config --prefix=/usr/local/ssl shared zlib-dynamic enable-camellia -DOPENSSL_NO_HEARTBEATS
make
make install
openssl version
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/opensslold
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl
echo "/usr/local/ssl/lib/" >>/etc/ld.so.conf
ldconfig -v|grep ssl
openssl version
cd ..
yum install pam* -y
tar -xzf openssh-6.6p1.tar.gz
cd openssh-6.6p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-ssl-dir=/usr/local/ssl --with-md5-passwords --mandir=/usr/share/man --with-kerberos5=/usr/lib64/libkrb5.so --mandir=/usr/share/man
make
make install
ssh -V
cd ..