(Linux+Nginx+MySQL+PHP源码安装 )+Discuz论坛的搭建
环境:redhat6.5
mysql-boost-5.7.11.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm
一.mysql的源码安装及配置
软件包依赖性:
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel cmake
[root@server1 ~]# ls
anaconda-ks.cfg install.log mysql-boost-5.7.11.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm install.log.syslog
解压
[root@server1 ~]# tar zxf mysql-boost-5.7.11.tar.gz
[root@server1 ~]# cd mysql-5.7.11/
安装cmake
[root@server1 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \
#数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \
#安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
#安装 innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
#安装 archive 存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
#安装 blackhole 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \
#安装数据库分区
-DENABLED_LOCAL_INFILE=1 \
#允许从本地导入数据
-DWITH_READLINE=1 \
#快捷键功能
-DWITH_SSL=yes \
#支持 SSL
-DDEFAULT_CHARSET=utf8 \
#使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \
#校验字符
-DEXTRA_CHARSETS=all \
#安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 \
#MySQL 监听端口
编译时会出现很多依赖性,一个一个解决,以下是问题描述及解决方法
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
CMake Error at cmake/os/Linux.cmake:41 (MESSAGE):
Unsupported compiler!
Call Stack (most recent call first):
CMakeLists.txt:162 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.11/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.11/CMakeFiles/CMakeError.log".
[root@server1 mysql-5.7.11]# yum install -y gcc gcc-c++
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:471 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.11/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.11/CMakeFiles/CMakeError.log".
[root@server1 mysql-5.7.11]# rm -rf CMakeCache.txt
[root@server1 mysql-5.7.11]# yum install -y ncurses-devel
[root@server1 mysql-5.7.11]# yum install -y bison
Make &&make install
编译链接完成后,配置
[root@server1 local]# cd lnmp/
[root@server1 lnmp]# ls
mysql
[root@server1 lnmp]# cd mysql/
[root@server1 mysql]# ls
bin COPYING docs include lib man mysql-test README share support-files
[root@server1 mysql]# ll /etc/my.cnf
-rw-r--r--. 1 root root 251 Aug 9 2013 /etc/my.cnf
[root@server1 support-files]# pwd
/usr/local/lnmp/mysql/support-files
[root@server1 support-files]# vim my-default.cnf
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@server1 support-files]# vim /etc/my.cnf
第18,19,22行更改如下
13 # Remove leading # to turn on a very important data integrity option: loggi ng
14 # changes to the binary log between backups.
15 # log_bin
16
17 # These are commonly set, remove the # and set as required.
18 basedir = /usr/local/lnmp/mysql
19 datadir = /usr/local/lnmp/mysql/data
20 port = 3306
21 # server_id = .....
22 socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
这是个脚本文件
[root@server1 support-files]# file mysql.server
mysql.server: POSIX shell script text executable
我们把它复制到linux默认脚本执行路径
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 mysql]# pwd
/usr/local/lnmp/mysql
创建组
[root@server1 mysql]# groupadd -g 27 mysql
创建用户
[root@server1 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql
将路径注明添加到环境变量
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
export PATH
刷新环境变量
[root@server1 ~]# source .bash_profile
[root@server1 mysql]# ls
bin COPYING docs include lib man mysql-test README share support-files
[root@server1 mysql]# vim /etc/my.cnf
17 # These are commonly set, remove the # and set as required.
18 basedir = /usr/local/lnmp/mysql
19 datadir = /usr/local/lnmp/mysql/data
20 port = 3306
21 # server_id = .....
22 socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 mysql]# mysqld --initialize --user=mysql
2018-08-05T03:14:57.498814Z 1 [Note] A temporary password is generated for root@localhost: S/tghuuF(6&Z ###密码,以后初始化要用
[root@server1 data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server1 data]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@server1 mysql]# pwd
/usr/local/lnmp/mysql
更改组及用户
[root@server1 mysql]# chgrp root . -R
[root@server1 mysql]# ll
total 60
drwxr-xr-x 2 root root 4096 Aug 5 10:44 bin
-rw-r--r-- 1 root root 17987 Feb 2 2016 COPYING
*drwxr-x--- 5 mysql root 4096 Aug 5 11:16 data*
drwxr-xr-x 2 root root 4096 Aug 5 10:43 docs
drwxr-xr-x 3 root root 4096 Aug 5 10:43 include
drwxr-xr-x 4 root root 4096 Aug 5 10:44 lib
drwxr-xr-x 4 root root 4096 Aug 5 10:43 man
drwxr-xr-x 10 root root 4096 Aug 5 10:44 mysql-test
-rw-r--r-- 1 root root 2478 Feb 2 2016 README
drwxr-xr-x 28 root root 4096 Aug 5 10:44 share
drwxr-xr-x 2 root root 4096 Aug 5 10:57 support-files
* [root@server1 mysql]# chown mysql data/ -R
初始化及登陆
[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server1 mysql]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : yes
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
[root@server1 mysql]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.11 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye
php的源码安装及配置
[root@server1 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35.tar.bz2
gd-devel-2.0.35-11.el6.x86_64.rpm mysql-5.7.11 re2c-0.13.5-1.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz
[root@server1 ~]# tar jxf php-5.6.35.tar.bz2
[root@server1 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35
gd-devel-2.0.35-11.el6.x86_64.rpm mysql-5.7.11 php-5.6.35.tar.bz2
libmcrypt-2.5.8-9.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz re2c-0.13.5-1.el6.x86_64.rpm
gd-devel-2.0.35-11.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm re2c-0.13.5-1.el6.x86_64.rpm
需要下载安装包的
[root@server1 ~]# yum install -y libxml2-devel openssl-devel curl-devel gd-devel-2.0.35-11.el6.x86_64.rpm gmp-devel libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm net-snmp-devel
[root@server1 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
[root@server1 ~]# cd php-5.6.35
[root@server1 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
自己一个一个安装(同上,只是表明如何解决error)
[root@server1 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
No package xml2-config available.
Error: Nothing to do
[root@server1 php-5.6.35]# rpm -qa |grep libxml2
libxml2-python-2.7.6-14.el6.x86_64
libxml2-2.7.6-14.el6.x86_64
[root@server1 php-5.6.35]# yum install libxml2 libxml2-devel -y
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
[root@server1 php-5.6.35]# yum install curl curl-devel -y
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.
[root@server1 php-5.6.35]# yum -y install libjpeg-devel
If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
[root@server1 php-5.6.35]# yum install libpng-devel libpng -y
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@server1 php-5.6.35]# yum install freetype-devel
configure: error: Unable to locate gmp.h
[root@server1 php-5.6.35]# yum install gmp-devel
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
[root@server1 php-5.6.35]# yum -y install net-snmp-devel
php配置
[root@server1 php-5.6.35]# cd /usr/local/lnmp/php/
[root@server1 php]# ls
bin etc include lib php sbin var
[root@server1 php]# cd etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 ~]# cd php-5.6.35
[root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# cd -
/root
[root@server1 ~]# ls
anaconda-ks.cfg libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11
gd-devel-2.0.35-11.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz
install.log php-5.6.35
install.log.syslog php-5.6.35.tar.bz2
libmcrypt-2.5.8-9.el6.x86_64.rpm re2c-0.13.5-1.el6.x86_64.rpm
[root@server1 ~]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php.ini
936 date.timezone =Asia/Shanhai
[root@server1 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid
26
27 ; Error log file
[root@server1 etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx
[root@server1 etc]# cd
[root@server1 ~]# cd php-5.6.35
[root@server1 php-5.6.35]# cd sapi/fpm/
[root@server1 fpm]# file init.d.php-fpm
是个脚本文件
init.d.php-fpm: POSIX shell script text executable
将脚本文件传到默认脚本路径
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
给可执行权限
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
执行
[root@server1 fpm]# /etc/init.d/php-fpm start
Starting php-fpm done
nginx源码安装及配置
[root@server1 ~]# tar zxf nginx-sticky-module-ng.tar.gz
[root@server1 ~]# ls
anaconda-ks.cfg mysql-boost-5.7.11.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm nginx-1.10.1.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm nginx-sticky-module-ng
install.log nginx-sticky-module-ng.tar.gz
install.log.syslog php-5.6.35
libmcrypt-2.5.8-9.el6.x86_64.rpm php-5.6.35.tar.bz2
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm re2c-0.13.5-1.el6.x86_64.rpm
mysql-5.7.11
[root@server1 ~]# tar zxf nginx-1.10.1.tar.gz
[root@server1 ~]# cd nginx-1.10.1
[root@server1 nginx-1.10.1]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@server1 nginx-1.10.1]# vim src/core/nginx.h
[root@server1 nginx-1.10.1]# vim src/core/nginx.h 删掉版本号
[root@server1 nginx-1.10.1]# vim auto/cc/gcc 注释debug
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
[root@server1 nginx-1.10.1]# yum install pcre-devel -y
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio
[root@server1 nginx-1.10.1]# make && make install
[root@server1 nginx-1.10.1]# cd /usr/local/
[root@server1 local]# cd lnmp/
[root@server1 lnmp]# cd nginx/
[root@server1 nginx]# ls
conf html logs sbin
[root@server1 nginx]# pwd
/usr/local/lnmp/nginx
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim /etc/security/limits.conf
[root@server1 conf]# tail -n 2 /etc/security/limits.conf
# End of file
nginx - nofile 65536
[root@server1 conf]# cd /usr/local/lnmp/nginx/sbin/
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# pwd
/usr/local/lnmp/nginx/sbin
[root@server1 sbin]# cd
[root@server1 ~]# vim .bash_
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin
export PATH
[root@server1 ~]# source .bash_profile
[root@server1 ~]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 ~]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 891/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 967/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 15593/php-fpm
tcp 0 0 172.25.53.1:22 172.25.53.250:55730 ESTABLISHED 15570/sshd
tcp 0 0 172.25.53.1:22 172.25.53.250:51062 ESTABLISHED 1022/sshd
tcp 0 0 :::22 :::* LISTEN 891/sshd
tcp 0 0 ::1:25 :::* LISTEN 967/master
[root@server1 ~]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# ls
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
[root@server1 html]# pwd
/usr/local/lnmp/nginx/html
[root@server1 html]# vim index.php
[root@server1 html]# cat index.php
<?php
phpinfo()
?>
[root@server1 html]# nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/lnmp/nginx/logs/nginx.pid"
[root@server1 html]# nginx -s stop
nginx: [error] invalid PID number "" in "/usr/local/lnmp/nginx/logs/nginx.pid"
[root@server1 html]# nginx
[root@server1 html]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 html]# nginx
50x.html index.html index.php
[root@server1 html]# nginx
50x.html index.html index.php
[root@server1 html]# cd
[root@server1 ~]# nginx
anaconda-ks.cfg
.bash_history
.bash_logout
.bash_profile
.bashrc
cmake-2.8.12.2-4.el6.x86_64.rpm
.cshrc
gd-devel-2.0.35-11.el6.x86_64.rpm
install.log
install.log.syslog
libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
mysql-5.7.11/
mysql-boost-5.7.11.tar.gz
.mysql_history
nginx-1.10.1/
nginx-1.10.1.tar.gz
nginx-sticky-module-ng/
nginx-sticky-module-ng.tar.gz
php-5.6.35/
php-5.6.35.tar.bz2
re2c-0.13.5-1.el6.x86_64.rpm
.tcshrc
[root@server1 ~]# nginx -s stop
[root@server1 ~]# nginx
[root@server1 ~]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# cd conf/
[root@server1 conf]# nginx -s reload
安装论坛 yum install -y unzip
125 unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/
[root@server1 ~]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# ls
50x.html index.html index.php readme upload utility
[root@server1 html]# cd upload/
[root@server1 html]# mv upload/ bbs
bbs下文件目录权限不足,修改权限
[root@server1 bbs]# chmod 777 config/ data/ uc_server/ uc_client/ -R
[root@server1 bbs]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@server1 bbs]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> bye
-> quit
-> exit
->
->
-> ^C
mysql> exit
Bye
[root@server1 bbs]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
目录不存在,添加目录
[root@server1 etc]# vim php.ini
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@server1 etc]# cd /usr/local/
[root@server1 local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Jun 28 2011 bin
drwxr-xr-x. 2 root root 4096 Jun 28 2011 etc
drwxr-xr-x. 2 root root 4096 Jun 28 2011 games
drwxr-xr-x. 2 root root 4096 Jun 28 2011 include
drwxr-xr-x. 2 root root 4096 Jun 28 2011 lib
drwxr-xr-x. 2 root root 4096 Jun 28 2011 lib64
drwxr-xr-x. 2 root root 4096 Jun 28 2011 libexec
drwxr-xr-x 5 root root 4096 Aug 5 14:26 lnmp
drwxr-xr-x. 2 root root 4096 Jun 28 2011 sbin
drwxr-xr-x. 5 root root 4096 Jul 27 17:19 share
drwxr-xr-x. 2 root root 4096 Jun 28 2011 src
[root@server1 local]# cd lnmp/
[root@server1 lnmp]# ll
total 12
drwxr-xr-x 11 root root 4096 Aug 5 11:14 mysql
drwxr-xr-x 11 root root 4096 Aug 5 14:39 nginx
drwxr-xr-x 9 root root 4096 Aug 5 13:16 php
[root@server1 lnmp]# cd mysql/
[root@server1 mysql]# ll
total 60
drwxr-xr-x 2 root root 4096 Aug 5 10:44 bin
-rw-r--r-- 1 root root 17987 Feb 2 2016 COPYING
drwxr-x--- 5 mysql root 4096 Aug 5 15:16 data
drwxr-xr-x 2 root root 4096 Aug 5 10:43 docs
drwxr-xr-x 3 root root 4096 Aug 5 10:43 include
drwxr-xr-x 4 root root 4096 Aug 5 10:44 lib
drwxr-xr-x 4 root root 4096 Aug 5 10:43 man
drwxr-xr-x 10 root root 4096 Aug 5 10:44 mysql-test
-rw-r--r-- 1 root root 2478 Feb 2 2016 README
drwxr-xr-x 28 root root 4096 Aug 5 10:44 share
drwxr-xr-x 2 root root 4096 Aug 5 10:57 support-files
[root@server1 mysql]# chmod 755 data/
[root@server1 mysql]# ll
total 60
drwxr-xr-x 2 root root 4096 Aug 5 10:44 bin
-rw-r--r-- 1 root root 17987 Feb 2 2016 COPYING
drwxr-xr-x 5 mysql root 4096 Aug 5 15:16 data
drwxr-xr-x 2 root root 4096 Aug 5 10:43 docs
drwxr-xr-x 3 root root 4096 Aug 5 10:43 include
drwxr-xr-x 4 root root 4096 Aug 5 10:44 lib
drwxr-xr-x 4 root root 4096 Aug 5 10:43 man
drwxr-xr-x 10 root root 4096 Aug 5 10:44 mysql-test
-rw-r--r-- 1 root root 2478 Feb 2 2016 README
drwxr-xr-x 28 root root 4096 Aug 5 10:44 share
drwxr-xr-x 2 root root 4096 Aug 5 10:57 support-files
[root@server1 mysql]# cd data/
[root@server1 data]# ll
total 122944
-rw-r----- 1 mysql root 56 Aug 5 11:14 auto.cnf
-rw-r----- 1 mysql mysql 314 Aug 5 11:38 ib_buffer_pool
-rw-r----- 1 mysql root 12582912 Aug 5 15:16 ibdata1
-rw-r----- 1 mysql root 50331648 Aug 5 15:16 ib_logfile0
-rw-r----- 1 mysql root 50331648 Aug 5 11:14 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Aug 5 15:16 ibtmp1
drwxr-x--- 2 mysql root 4096 Aug 5 11:15 mysql
-rw-rw---- 1 root root 6 Aug 5 15:16 mysqld_safe.pid
srwxrwxrwx 1 mysql mysql 0 Aug 5 15:16 mysql.sock
-rw------- 1 mysql mysql 6 Aug 5 15:16 mysql.sock.lock
drwxr-x--- 2 mysql root 4096 Aug 5 11:15 performance_schema
-rw-r----- 1 mysql root 20901 Aug 5 15:16 server1.err
-rw-r----- 1 mysql mysql 6 Aug 5 15:16 server1.pid
drwxr-x--- 2 mysql root 12288 Aug 5 11:15 sys
php添加memcache缓存模块
[root@server1 ~]# ls
anaconda-ks.cfg mysql-5.7.11
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz
Discuz_X3.2_SC_UTF8.zip nginx-1.10.1
gd-devel-2.0.35-11.el6.x86_64.rpm nginx-1.10.1.tar.gz
install.log nginx-sticky-module-ng
install.log.syslog nginx-sticky-module-ng.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm php-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35.tar.bz2
memcache-2.2.5.tgz re2c-0.13.5-1.el6.x86_64.rpm
[root@server1 ~]# tar zxf memcache-2.2.5.tgz
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/
[root@server1 lnmp]# ls
mysql nginx php
[root@server1 lnmp]# cd php/
[root@server1 php]# cd bin/
[root@server1 bin]# pwd
/usr/local/lnmp/php/bin
[root@server1 bin]# cd
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin:/usr/local/lnmp/php/bin
export PATH
[root@server1 ~]# source .bash_profile
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@server1 memcache-2.2.5]# ls
acinclude.m4 configure.in memcache.php
aclocal.m4 config.w32 memcache_queue.c
autom4te.cache CREDITS memcache_queue.h
build example.php memcache_session.c
config9.m4 install-sh memcache_standard_hash.c
config.guess ltmain.sh missing
config.h.in Makefile.global mkinstalldirs
config.m4 memcache.c php_memcache.h
config.sub memcache_consistent_hash.c README
configure memcache.dsp run-tests.php
[root@server1 memcache-2.2.5]# ./configure
[root@server1 memcache-2.2.5]# make && make install
memcache配置
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@server1 no-debug-non-zts-20131226]# ls
memcache.so opcache.a opcache.so
[root@server1 no-debug-non-zts-20131226]# pwd
/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226
[root@server1 no-debug-non-zts-20131226]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@server1 etc]# php -m |grep memcache
memcache
[root@server1 etc]# cd
[root@server1 ~]# yum install -y memcached
[root@server1 ~]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# ls
50x.html example.php index.php readme
bbs index.html memcache.php utility
[root@server1 html]# vim memcache.php
[root@server1 html]# vim memcache.php
[root@server1 html]# vim .bash_profile
[root@server1 html]# vim /root/.bash_profile
[root@foundation53 ~]# ab -c 10 -n 1000 http://172.25.53.1/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.53.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/
Server Hostname: 172.25.53.1
Server Port: 80
Document Path: /index.php
Document Length: 84794 bytes
Concurrency Level: 10
Time taken for tests: 2.433 seconds
Complete requests: 1000
Failed requests: 101
(Connect: 0, Receive: 0, Length: 101, Exceptions: 0)
Write errors: 0
Total transferred: 84950888 bytes
HTML transferred: 84793888 bytes
Requests per second: 411.08 [#/sec] (mean)
Time per request: 24.326 [ms] (mean)
Time per request: 2.433 [ms] (mean, across all concurrent requests)
Transfer rate: 34102.88 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 4 24 4.0 24 60
Waiting: 2 21 4.5 19 59
Total: 4 24 4.0 24 60
Percentage of the requests served within a certain time (ms)
50% 24
66% 25
75% 25
80% 25
90% 26
95% 27
98% 29
99% 53
100% 60 (longest request)
[root@foundation53 ~]# ab -c 10 -n 1000 http://172.25.53.1/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.53.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/
Server Hostname: 172.25.53.1
Server Port: 80
Document Path: /example.php
Document Length: 123 bytes
Concurrency Level: 10
Time taken for tests: 0.960 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 280000 bytes
HTML transferred: 123000 bytes
Requests per second: 1042.11 [#/sec] (mean)
Time per request: 9.596 [ms] (mean)
Time per request: 0.960 [ms] (mean, across all concurrent requests)
Transfer rate: 284.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 2 9 0.9 9 14
Waiting: 1 9 1.0 9 14
Total: 2 10 0.9 10 14
Percentage of the requests served within a certain time (ms)
50% 10
66% 10
75% 10
80% 10
90% 10
95% 11
98% 11
99% 12
100% 14 (longest request)
example.php的页面是直接访问了服务器,而memcache的页面是缓存
Nginx 采用的是 master-worker 模型,一个 master 进程管理多个 worker 进程,基本的事件处理都是放在 woker 中,master 负责一些全局初始化,以及对 worker 的管理。在OpenResty中,每个 woker 使用一个 LuaVM,当请求被分配到 woker 时,将在这个 LuaVM 里创建一个 coroutine(协程)。协程之间数据隔离,每个协程具有独立的全局变量_G。
ps. 协程和多线程下的线程类似:有自己的堆栈,自己的局部变量,有自己的指令指针,但是和其他协程程序共享全局变量等信息。线程和协程的主要不同在于:多处理器的情况下,概念上来说多线程是同时运行多个线程,而协程是通过代码来完成协程的切换,任何时刻只有一个协程程序在运行。并且这个在运行的协程只有明确被要求挂起时才会被挂起。
[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz
[root@server1 ~]# cd openresty-1.13.6.1
[root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio
[root@server1 openresty-1.13.6.1]# gmake && gmake install
[root@server1 openresty-1.13.6.1]# cd /usr/local/lnmp/openresty/
[root@server1 openresty]# ls
bin COPYRIGHT luajit lualib nginx pod resty.index site
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf test is successful
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx
[root@server1 html]# pwd
/usr/local/lnmp/openresty/nginx/html
[root@server1 html]# cp /usr/local/lnmp/nginx/html/example.php .
[root@server1 html]# cp /usr/local/lnmp/nginx/html/index.php .
[root@server1 html]# cd ..
[root@server1 nginx]# cd conf/
[root@server1 conf]# cat nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
upstream memcache {
server localhost:11211;
keepalive 512;
}
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location /memc {
internal;
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
set $memc_key $query_string;
set $memc_exptime 300;
memc_pass memcache;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
set $key $uri$args;
srcache_fetch GET /memc $key;
srcache_store PUT /memc $key;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@foundation53 ~]# ab -c 10 -n 1000 http://172.25.53.1/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.53.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: openresty/1.13.6.1
Server Hostname: 172.25.53.1
Server Port: 80
Document Path: /index.php
Document Length: 84814 bytes
Concurrency Level: 10
Time taken for tests: 0.477 seconds
Complete requests: 1000
Failed requests: 3
(Connect: 0, Receive: 0, Length: 3, Exceptions: 0)
Write errors: 0
Total transferred: 85005767 bytes
HTML transferred: 84813997 bytes
Requests per second: 2097.41 [#/sec] (mean)
Time per request: 4.768 [ms] (mean)
Time per request: 0.477 [ms] (mean, across all concurrent requests)
Transfer rate: 174113.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 2 5 2.2 5 30
Waiting: 1 3 1.6 3 27
Total: 2 5 2.2 5 30
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 5
80% 5
90% 5
95% 6
98% 7
99% 14
100% 30 (longest request)
[root@foundation53 ~]# ab -c 10 -n 1000 http://172.25.53.1/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.53.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: openresty/1.13.6.1
Server Hostname: 172.25.53.1
Server Port: 80
Document Path: /example.php
Document Length: 123 bytes
Concurrency Level: 10
Time taken for tests: 0.185 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 312979 bytes
HTML transferred: 123000 bytes
Requests per second: 5411.40 [#/sec] (mean)
Time per request: 1.848 [ms] (mean)
Time per request: 0.185 [ms] (mean, across all concurrent requests)
Transfer rate: 1653.96 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 0 2 0.3 2 3
Waiting: 0 2 0.3 2 3
Total: 1 2 0.3 2 3
Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 2
80% 2
90% 2
95% 2
98% 3
99% 3
100% 3 (longest request)