1.关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
2.安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make //pcre:兼容一些正则表达式,zlib:解压缩包
3.创建运行用户
useradd -M -s /sbin/nologin nginx
4.编译安装Nginx 拖入安装包
cd /opt
tar zxvf nginx-1.12.2.tar.gz -C /opt/ //解压软件包
cd nginx-1.12.2/
./configure \
--prefix=/usr/local/nginx \ //指定nginx的安装路径
--user=nginx \ //指定用户名
--group=nginx \ //指定组名
--with-http_stub_status_module //启用 http_stub_status_module 状态统计模块
make -j3 && make install
5.优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //让系统识别nginx的操作命令
nginx -t //检查配置文件是否配置正确
[root@zz nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
nginx //启动
##——停止——##
cat /usr/local/nginx/logs/nginx.pid //先查看nginx的PID号
[root@zz nginx-1.12.2]# cat /usr/local/nginx/logs/nginx.pid
15858
kill -3
kill -s QUIT
killall -3 nginx
killall -s QUIT nginx
##——重载——##
kill -1
kill -s HUP
killall -1 nginx
killall -s HUP nginx
##——日志分隔,重新打开日志文件——##
kill -USR1
##——平滑升级——##
kill -USR2
| 信号编号 | 信号名 | 含义 |
| -------- | ------ | ------------------------------------------------------------ |
| 0 | EXIT | 程序退出时收到该信息。 |
| 1 | HUP | 挂掉电话线或终端连接的挂起信号,这个信号也会造成某些进程在没有终止的情况下重新初始化。 |
| 2 | INT | 表示结束进程,但并不是强制性的,常用的 "Ctrl+C" 组合键发出就是一个 kill -2 的信号。 |
| 3 | QUIT | 退出。 |
| 9 | KILL | 杀死进程,即强制结束进程。 |
| 11 | SEGV | 段错误。 |
| 15 | TERM | 正常结束进程,是 kill 命令的默认信号 |
cat /usr/local/nginx/logs/nginx.pid
ss -ntpl | grep 80 //推荐使用,读取速度快
netstat -natpl | grep 80
netstat -natpl | grep nginx
lsof -i :80
(三)添加Nginx系统服务
1.方法一(编写脚本)启动速度没有方法二快
vim /etc/init.d/nginx
#!/bin/bash //解释器
#chkconfig:35 99 20 //在运行界别3 5 开机第99个启动 关机20关闭
#desc:this is nginx service control scprit
COM = "/usr/local/nginx/sbin/nginx"
PID = "/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$COM
;;
stop)
kill -s QUIT `cat $PID`
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP `cat $PID`
;;
*)
echo "please use: $0 {start|stop|restart|reload}"
exit 1 //返回码,执行失败返回码不是0
esac
exit 0
##——增加权限执行——##
chmod +x /etc/init.d/nginx
chkconfig --add nginx //添加进系统服务
systemctl stop nginx
systemctl start nginx
2.方法二
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
systemctl stop nginx和service nginx start不能一起使用,service会开启失败
cd /opt
wget http://nginx.org/download/nginx-1.23.0.tar.gz
tar zxvf nginx-1.23.0.tar.gz
cd nginx-1.23.0
yum install openssl openssl-devel -y
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module \
--with-http_ssl_module
make
千万不要执行make install,make install 直接重装了,环境就没了
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old //备份
cp objs/nginx /usr/local/nginx/sbin/nginx
systemctl restart nginx //重启服务
nginx -V //查看版本
1.安装Mysql环境依赖包
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
或者:
yum -y install ncurses ncurses-devel bison cmake
2.创建运行用户
useradd -M -s /sbin/nologin mysql
3.编译安装
cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
cd /opt/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 //编译安装
4.对mysql的数据目录进行权限调整
chown -R mysql:mysql /usr/local/mysql
5.修改mysql 配置文件
vim /etc/my.cnf
[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_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
6.设置环境变量,并输出全局变量,刷新文件
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
7.初始化数据文件
cd /usr/local/mysql/bin
mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
8.使用systemctl工具来进行服务控制
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /lib/systemd/system/
systemctl daemon-reload #刷新识别
9.开启mysql服务,进行验证
systemctl start mysqld.service #开启服务
systemctl enable mysqld #开机自启动
netstat -anpt | grep 3306 #查看端口
10.设置mysql数据库的密码,并登录
mysqladmin -u root -p password "123"
mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by '123';
#授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限
show databases; #查看当前已有的数据库
11.授权远程登录
mysql -u root -p
1.安装关系依赖包
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2.解压
tar zxvf php-7.1.10.tar.gz
3.配置模块
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-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
4.编译安装
make && make install
1.路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
2.调整PHP配置文件
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展展配置文件
//调整主配置文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
//在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件
vim /usr/local/php/lib/php.ini
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai
php -m //验证安装的模块
//调整进程服务配置文件:
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
——17行——去掉“;”注释
pid = run/php-fpm.pid
//调整扩展配置匹配文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
3.启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -natp | grep 9000
4.配置 Nginx支持PHP解析
vim /usr/local/nginx/conf/nginx.conf
——65行——取消注释,修改
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; //将/scripts修改为
nginx的工作目录
include fastcgi_params;
}
5.创建首页,重启nginx
vim /usr/local/nginx/html/index.php
//可以改成显示php配置的web网页
systemctl restart nginx