CentOS 7.x 编译安装 LNMP
L 版本是 CentOS 7.x x64版本,
N 我们使用tengine 的最新版本,主要原因是因为tengine 默认支持很多的模块。
M 这里我们选用 mysql 5.7 的版本,mysql 5.7 性能提升非常之多。
p 这里就选用了 php 5.6 版本,至于5.7 是因为 很多扩展支持的还不好。
一、下载相应软件包:
下载 php 5.6.19
http://cn2.php.net/distributions/php-5.6.19.tar.gz
下载 mysql 5.7
ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.7/mysql-5.7.14.tar.gz
下载 tengine 2.1.1
http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
二、安装必要支持库,以及软件。
yum install -y gcc gcc-c++ cmake ncurses-devel
三、编译安装 Mysql 5.7
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /opt/local/mysql/data
mkdir -p /opt/local/mysql/binlog
mkdir -p /opt/local/mysql/logs
mkdir -p /opt/local/mysql/relaylog
mkdir -p /var/lib/mysql
mkdir -p /opt/local/mysql/etc/
tar zxvf mysql-5.7.14.tar.gz
cd mysql-5.7.14
cmake -DCMAKE_INSTALL_PREFIX="/opt/local/mysql" -DDEFAULT_CHARSET=utf8 -DMYSQL_DATADIR="/opt/local/mysql/data/" -DCMAKE_INSTALL_PREFIX="/opt/local/mysql" -DINSTALL_PLUGINDIR=plugin -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_DEBUG_SYNC=0 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=1 -DWITH_ZLIB=system -DWITH_EXTRA_CHARSETS=none -DMYSQL_MAINTAINER_MODE=OFF -DEXTRA_CHARSETS=all -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
( -DDOWNLOAD_BOOST=1 会自动下载boost 到 DWITH_BOOST= 指定目录 或者自行下载,存放于指定目录 )
make -j `cat /proc/cpuinfo | grep processor| wc -l`
make install
ln -s /opt/local/mysql/lib/mysql /usr/lib/mysql
ln -s /opt/local/mysql/include/mysql /usr/include/mysql
ln -s /opt/local/mysql/bin/mysql /usr/bin/mysql
ln -s /opt/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /opt/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /opt/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
rm -rf /etc/my.cnf
cp /opt/local/mysql/support-files/my-default.cnf /opt/local/mysql/etc/my.cnf
cd /opt/local/mysql/bin/
chmod +w /opt/local/mysql
chown -R mysql:mysql /opt/local/mysql
chmod +w /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
./mysqld --initialize --user=mysql --basedir=/opt/local/mysql --datadir=/opt/local/mysql/data
( 系统会自动生成一个随机密码,在logs 文件里面可以查看 )
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
echo 'basedir=/opt/local/mysql-5.6.15/' >> /etc/init.d/mysqld
echo 'datadir=/opt/local/mysql-5.6.15/data' >>/etc/init.d/mysqld
service mysqld start
/opt/local/mysql/bin/mysql_secure_installation -uroot -p
修改密码,加固密码,设置密码级别,删除测试库
四、编译安装php 5.6
1. 安装php所需的依赖
yum -y install libXpm-devel zlib zlib-devel libzip libzip-devel autoconf ImageMagick-devel
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
tar zxvf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./configure --prefix=/usr/local
make && make install
tar zxvf php-5.6.19.tar.gz
cd php-5.6.19
cp -frp /usr/lib64/libldap* /usr/lib/
vi /etc/ld.so.conf.d/local.conf
添加:
/usr/local/lib
执行
ldconfig -v
mkdir /opt/local/php/logs
./configure --prefix=/opt/local/php --with-config-file-path=/opt/local/php/etc --with-mysql=/opt/local/mysql --with-mysqli=/opt/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --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 --with-gd --with-xpm-dir=/usr/lib --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --disable-phar --enable-opcache=no --with-pdo-mysql --enable-maintainer-zts
------------------------------------------------------------------------------------------------------------------------------------------------
1. 报错:
configure: error: Cannot find libmysqlclient_r under /opt/local/mysql.
Note that the MySQL client library is not bundled anymore!
创建一个软链接
ln -s /opt/local/mysql/lib/libmysqlclient.so.20.2.0 /opt/local/mysql/lib/libmysqlclient_r.so
ldconfig
2. 报错:
undefined reference to symbol 'ber_strdup'
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
vi Makefile
找到 EXTRA_LIBS 行,
在行末添加 ‘ -llber ‘ 保存退出再次make
------------------------------------------------------------------------------------------------------------------------------------------------
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /opt/local/php/etc/php.ini
2. 安装 php 扩展
wget http://pecl.php.net/get/memcache-3.0.8.tgz
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8/
/opt/local/php/bin/phpize
./configure --with-php-config=/opt/local/php/bin/php-config
make && make install
wget http://pecl.php.net/get/mongo-1.6.12.tgz
tar zxvf mongo-1.6.12.tgz
cd mongo-1.6.12
/opt/local/php/bin/phpize
./configure --with-php-config=/opt/local/php/bin/php-config
make && make install
wget http://pecl.php.net/get/imagick-3.4.1.tgz
tar zxvf imagick-3.4.1.tgz
cd imagick-3.4.1
./configure --with-php-config=/opt/local/php/bin/php-config
make && make install
wget https://github.com/phpredis/phpredis/archive/develop.zip
unzip develop.zip
cd phpredis-develop/
/opt/local/php/bin/phpize
./configure --with-php-config=/opt/local/php/bin/php-config
make && make install
echo extension_dir = '"/opt/local/php/lib/php/extensions/no-debug-zts-20131226/"' >> /opt/local/php/etc/php.ini
echo extension = '"memcache.so"' >> /opt/local/php/etc/php.ini
echo extension = '"imagick.so"' >> /opt/local/php/etc/php.ini
echo extension = '"mongo.so"' >> /opt/local/php/etc/php.ini
echo extension = '"redis.so"' >> /opt/local/php/etc/php.ini
echo open_basedir = '"/opt/htdocs/"' >> /opt/local/php/etc/php.ini
cp /opt/software/php-5.6.19/sapi/fpm/php-fpm.conf /opt/local/php/etc/
/usr/sbin/groupadd upload
/usr/sbin/useradd -g upload upload
五、安装编译 tengine
1. 安装所需依赖
yum -y install pcre gd-devel
2. 安装 tengine
tar zxvf tengine-2.1.2.tar.gz
cd tengine-2.1.2
vi src/core/nginx.h
查找 #define TENGINE 与 #define TENGINE_VERSION
修改 版本号与显示信息
./configure --user=upload --group=upload --prefix=/opt/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module
make && make install
cd /opt/local/nginx/conf
vi nginx.conf
----------------------------------------------------------------------------------------------
user upload upload;
error_log /opt/local/nginx/logs/nginx_error.log crit;
pid /opt/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
events
{
reuse_port on;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 100m;
sendfile on;
server_tokens off;
tcp_nopush on;
keepalive_timeout 120;
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 128k;
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-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for "$request_time"';
include vhost/*.conf;
}
-----------------------------------------------------------------------------------------------------
mkdir -p /opt/local/nginx/conf/vhost
cd /opt/local/nginx/conf/vhost
vi www.xxx.com.conf
---------------------------------------------------------------------------------------------------
server
{
listen 80;
server_name www.xxx.com;
index index.html index.htm index.php;
root /opt/htdocs/;
access_log /opt/local/nginx/logs/www.xxx.com.log main;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
------------------------------------------------------------------------------------------------------
六、启动服务
启动php-fpm
/opt/local/php/sbin/php-fpm
启动 tengine
/opt/local/nginx/sbin/nginx