一、安装Mysql
1.进入cd /usr/local/src/目录里,命令:wget安装
mv mysql-5.6.35-linux-glibc2.5-x86_ 64 /usr/local/mysql
useradd -s /sbin/nologin mysql //创建用户
cd /usr/local/mysql 进入
mkdir -p /data/mysql 创建目录
chown -R mysql:mysql /data/mysql
./scripts/mysq1_ install db --user=mysql --datadir=/data/mysql
cp support-files/my-default .cnf /etc/my .cnf
cp support-files/mysql. server /etc/init . d/mysqld
chmod 755 /etc/init. d/mysqld
2. vim进入 /etc/init . d/mysqld 搜索datadir修改为datadir=/data/mysql
设定开机启动并启动Mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
查看MySQL是否启动
ps aux |grep mysqld
二、安装php
1.cd进入/usr/local/src,下载源码包,tar zxvf解压
useradd -s /sbin/nologin php-fpm 该账号用来运行php- fpm服务
2.配置编译参数
cd php-5.6.36 进入
./configure
--prefix=/usr/local/php-fpm
--with-config-file-path=/usr/local/php-fpm/etc
--enable-fpm
--with-fpm-user=php-fpm
--with-fpm-group=php-fpm
--with-mysql=/usr/local/mysql
--with-mysql-sock=/tmp/mysql.sock
--with-libxml-dir
--with-gd
--with-jpeg-dir
--with-png-dir
--with-freetype-dir
--with-iconv-dir
--with-zlib-dir
--with-mcrypt
--enable-soap
--enable-gd-native-ttf
--enable-ftp
--enable-mbstring
--enable-exif
--disable-ipv6
--with-pear
--with-curl
--with-openssl
编译参数和上- -章不同,多了一个--enable-fpm, 如果不加该参数,则不会有php- fpm执行文件生
成,更不能启动php- fpm服务
(yum install –y libxml2-devel)(yum install –y openssl openssl-devel)(yum install –y bzip2 bzip2-devel)(yum install –y libpng libpng-devel)(yum install –y freetype freetype-devel)(yum install –y epel-release)(yum install –y libmcrypt-devel)(yum install -y libcurl-devel)
3.编译安装php
make && make install
4.修改配置文件
cp php.ini-production /usr/local/php- fpm/etc/php. ini
vim 进入/usr/1ocal/ php- fpm/etc/php-fpm. conf编写如下内容:
[global]
pid = /usr/local/php- fpm/var/run/php-fpm.pid
error_ log = /ust/local/php-fpm/var/log/php-fpm.1og
[www]
listen = /tmp/php-fcgi . sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_ _children = 50
pm.start_ servers = 20
pm.min_ spare_ servers = 5
pm.max_ spare_ servers = 35
pm.max_ requests = 500
rlimit_ files = 1024
保存配置文件后,检验配置是否正确
/usr/local/php-fpm/sbin/php-fpm -t
如果显示“test is successful”,则说明配置没有问题
启动php-fpm:
cp /usr/local/src/php-5.6. 30/sapi/ fpm/ init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init. d/php-fpm
useradd -s /sbin/nologin php- fpm
service php-fpm start
设置php-fpm开机启动命令
chkconfig php-fpm on
检测php-fpm是否启动命令
ps aux Igrep php-fpm
三、安装Nginx
1.进入/usr/local/src
tar zxvf解压
2.配置编译,安装
3.进入/etc/init.d/nginx编写启动脚本,并加入系统服务
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
3.更改脚本权限
开机启动Nginx
4.更改Nginx的配置文件
清空原来的配置文件
进入/usr/local/nginx/conf/nginx.conf编写如下内容
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ .php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
保存退出,然后检验
出现如下图所示说明正确
启动Mginx
service nginx start
5.解析php
先创建测试文件vim进入/usr/local/nginx/html/2.php,编辑如下内容
<?php
echo "test php scripts." ;
?>
6.测试
curl localhost/2.php
四,配置Nginx
1.修改主配置文件nginx.conf,在结束符号}上面加入一行配置,
include vhost/* . conf;
}
意思是,/usr/ocal/nginx/conf/vhost/下面的所有以.conf结尾的文件都会加载,这样我们就可以把所有虚拟主机配置文件放到vhost目录下面了
验证
测试
五、用户认证
vim进入test.com.conf编写如下内容
yum install -y httpd
htpasswd -C /usr/1ocal/nginx/conf/htpasswd aming 创建aming用户
验证
auth_basic打开认证,auth_basic_user_file指定用户密码文件,当然前提 Nginx不自带这个工具,
状态码为401,说明该网站需要验证
打开windows的hosts文件,并加入一行
192.168.200.147 test.com
关闭防火墙
六、域名重定向
1.配置
验证,curl测试
七、Nginx的访问日志
先查看Nginx的日志格式
配置虚拟主机文件
验证,使用access_ log来指定日志的存储路径,最后面指定日志的格式名字,curl测试
查看
2.配置静态文件不记录日志并添加过期时间
配置
使用location ~可以指定对应的静态文件,expires配置过期时间,而access_ log配置 为off就可以:
访问js类型文件,缓存过期时间为12小时
查看访问日志