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