nginx 下载地址
http://nginx.org/en/download.html
http://mirrors.sohu.com/mysql/
http://www.php.net/downloads.php
https://www.phpmyadmin.net/
http://www.awstats.org/#DOWNLOAD
关闭防火墙/设置防火墙规则
service firewalld stop
systemctl disable firewalld
下载nginx需要的插件
yum -y install \
pcre-devel \
zlib-devel
添加nginx用户
useradd -M -s /sbin/nologin nginx
解压nginx压缩包
tar xzvf nginx-1.13.7.tar.gz -C /usr/src/
定制
cd /usr/src/nginx-1.13.7
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
编译并安装
make && make install
创建软连接
ln-s /usr/local/nginx/sbin/nginx /usr/local/sbin/
开启nginx
ginx -t //配置文件语法检查
nginx //启动服务
注:如果启动不了有可能80端被占用了 需要关闭80端口 参考:https://blog.csdn.net/xie_xiansheng/article/details/78028051
killall -1 nginx //安全重启
killall -3 nginx //停止服务
-------制作管理角本--------
制作启动脚本
文件授权并添加到service管理
chmod +x /etc/init.d/nginx
chkconfig --add nginx
修改配置文件
vi /usr/local/nginx/conf/nginx.conf
user nginx nginx; //程序用户 和 组
注:查看nginx的程序用户 ps aux | grep nginx
error_log logs/error.log info; //错误信息日志
----日志级别---
//debug info notice warn error crit //向上记录
events {
use epoll; //新增此行 默认使用select/poll
worker_connections 10240; //表示1个工作进程允许10240个连接。
log_format main //定义日志格式 把前面的#号去掉
ulimit -n 65500//查看和更改系统本地打开资源数
ulimit -n 65500 >> /etc/rc.local
---配置统计功能----
location ~ /status {
stub_status on;
access_log off;
} //在server 模块里的error_page 上面增加
启动nginx
service nginx reload
查看访问日志
cat /usr/local/nginx/logs/access.log
网页访问
http://IP/status //当前的活动连接数,已处理的连接数,成功的TCP握手次数,已处理的请求数。
-----以下配置nginx的验证功能---
yum install httpd-tools
htpasswd -c /usr/local/nginx/passwd.db jack
chmod 400 /usr/local/nginx/passwd.db
chown nginx /usr/local/nginx/passwd.db
访问验证
vi /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
allow 192.168.80.0/24;
deny all;
auth_basic "secret";
auth_basic_user_file /usr/local/nginx/passwd.db;
}
启动服务
service nginx restart
http://192.168.80.181/ //需要验证才能访问
配置虚拟主机
-------以下配置虚拟主机功能-------
---基于域名----------IP和端口都相同但是域名不相同---在最后一行上面插入--
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.aa.com;
charset utf-8;
access_log logs/aa.access.log main;
location / {
root /var/www/aa;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
server {
listen 80;
server_name www.bc.com;
charset utf-8;
access_log logs/bc.access.log main;
location / {
root /var/www/bc;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
-------基于IP的--端口号相同但是IP不相同---
listen 192.168.80.193:80;
---基于端口的---------IP相同但是端口号不相同-----
listen 192.168.80.193:8080; //在配置文件头部
--------------以下是安装MYSQL-----http://mirrors.sohu.com/mysql/---
---------------以下安装mysql------------------------
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
mysql用户
useradd -s /sbin/nologin mysql
解压mysql
tar xf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/
定制功能
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
编译并安装
make && make install
文件设置归宿
chown -R mysql.mysql /usr/local/mysql/ 也可mysql:mysql
修改mysql配置文件
vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
修改归宿
chown mysql:mysql /etc/my.cnf
系统变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
生效变量
source /etc/profile
初始化
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
添加systemctl 管理
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306
开机自启
systemctl enable mysqld
初始化root用户
mysqladmin -u root -p password "abc123" //给root账号设置密码
进入数据库
mysql -u root
-----------------以下安装PHP-----------
安装php插件
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
解压并编译
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip \
--enable-fpm
编译并安装
make && make install
修改配置文件
cp php.ini-development /usr/local/php/lib/php.ini
vi /usr/local/php/lib/php.inimysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
模块验证
/usr/local/php/bin/php -m //验证安装的模块
-----------配置及优化FPM模块--------
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf //如果没有就是--enable-fpm 没开启
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.confcd /usr/local/php/etc/
vi php-fpm.confpid = run/php-fpm.pid
;user = nginx
;group = nginx
开启
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
netstat -anpt | grep 9000ln -s /usr/local/php/bin/* /usr/local/bin/
查看php-fpm
ps aux | grep -c "php-fpm" //结果
-----更新启动脚本----------
vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 99 20
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/php/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
--------以下是让nginx支持PHP功能--------
vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root /var/www/aa;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/aa$fastcgi_script_name; //注意目录名称
include fastcgi_params;
}
php页面
vi /var/www/aa/index.php
phpinfo();
?>
在网页测试“http://192.168.80.193/index.php”
--------下面测试数据库工作是否正常-----
mysql -u root -p
授权
CREATE DATABASE bbs;
GRANT all ON bbs. TO 'bbsadm'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs. TO 'bbsadm'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;DROP DATABASE bbs;删除数据库bbs
配置php
vi /var/www/aa/index.php
$link=mysqli_connect('192.168.80.181','bbsadm','admin123');
if($link) echo "Success!!
";
else echo "Fail!!";
?>
网页访问
在网页测试“http://ip地址/index.php”
---以下安装论坛------
unzip Discuz_X3.2_SC_UTF8.zip -d /tmp
cd /opt/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs 放到nginx的网页根目录中正常生效
cd /usr/local/nginx/html/bbs
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/http://IP/bbs/install
http://IP/bbs/admin.php //管理后台cd /var/www/aa/bbs
mv install/ install.lock
chmod 600 install.lock/
-----------配置动静分离--------------
vi /etc/nginx.conf //还原配置文件修改server下配置
server_name www.bt.com;
charset utf-8;
开启日志相关的配置
错误日志
日志格式
访问日志
-------在location /下新增--------
location ~ .php {
proxy_pass http://192.168.80.182:80;
} //把PHP动态请求转给192.168.80.182
-------以上是动态分离配置------
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
root html;
expires 1d;
} //这些静态内容从本地读取
--------在index.php中加入下面内容测试-----
;
抓包测试