1. 部署Nginx
// 配置yum源
[root@xian ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@xian ~]# yum -y install remi-release-7.rpm
[root@xian ~]# yum clean all
[root@xian ~]# yum makecache --enablerepo=remi-php74
// 安装依赖包
[root@xian ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ wget
[root@xian ~]# yum -y groups mark install 'Development Tools'
// 创建nginx主和组,并创建日志存放目录
[root@xian ~]# useradd -r -M -s /sbin/nologin nginx
[root@xian ~]# mkdir -p /var/log/nginx
[root@xian ~]# chown -R nginx.nginx /var/log/nginx
// 下载nginx源码包,并安装
[root@xian ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@xian ~]# tar xf nginx-1.18.0.tar.gz
[root@xian ~]# cd nginx-1.18.0
[root@xian nginx-1.18.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@xian nginx-1.18.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
// 配置nginx
[root@xian nginx-1.18.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@xian nginx-1.18.0]# source /etc/profile.d/nginx.sh
[root@xian nginx-1.18.0]# nginx
[root@xian nginx-1.18.0]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
// 访问验证
2. 部署Mysql
2.1 安装mysql
// 安装依赖包
[root@xian ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
// 创建mysql用户和组
[root@xian ~]# useradd -r -M -s /sbin/nologin -u 306 mysql
[root@xian ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
// 下载并解压mysql
[root@xian ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@xian ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
2.2 配置mysql
//创建软连接,修改文件属主
[root@xian ~]# cd /usr/local/
[root@xian local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql
[root@xian local]# chown -R mysql.mysql mysql*
[root@xian local]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
lrwxrwxrwx. 1 mysql mysql 36 Aug 10 10:44 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Aug 10 10:43 mysql-5.7.30-linux-glibc2.12-x86_64
drwxr-xr-x. 11 root root 151 Aug 10 10:36 nginx
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Aug 10 10:01 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
//配置环境变量
[root@xian ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@xian ~]# source /etc/profile.d/mysql.sh
// 创建数据存放目录
[root@xian ~]# mkdir /opt/data
[root@xian ~]# chown -R mysql.mysql /opt/data
[root@xian ~]# ll -d /opt/data
drwxr-xr-x. 2 mysql mysql 6 Aug 10 10:46 /opt/data
2.3 初始化数据库,并配置
[root@xian ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data
//这里加了insecure选项,所以安装好后可以不用密码登录
[root@xian ~]# ln -s /usr/local/mysql/include /usr/local/include/mysql
[root@xian ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@xian ~]# ldconfig
2.4 生成配置文件
[root@xian ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
2.5 配置服务启动脚本
[root@xian ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@xian ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@xian ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
2.6 设置为开机自动启动并修改密码
[root@node2 ~]# chkconfig mysqld on //设置为开机自动启动
[root@xian ~]# chkconfig mysqld on
[root@xian ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/xian.err'.
SUCCESS!
[root@xian ~]# ss -antl |grep 3306
LISTEN 0 80 :::3306 :::*
[root@xian ~]# mysql -e "set password = password('123456')"
[root@xian ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> quit
Bye
3. 部署PHP
3.1 安装php
// 安装依赖包
[root@xian ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php74-php-mysqlnd
// 下载并安装php
[root@xian ~]# wget https://www.php.net/distributions/php-7.4.7.tar.gz
[root@xian ~]# tar xf php-7.4.7.tar.gz
[root@xian ~]# cd php-7.4.7
[root@xian php-7.4.7]# ./configure --prefix=/usr/local/php7 \> --with-config-file-path=/etc \
> --enable-fpm \
> --enable-inline-optimization \
> --disable-debug \
> --disable-rpath \
> --enable-shared \
> --enable-soap \
> --with-openssl \
> --enable-bcmath \
> --with-iconv \
> --with-bz2 \
> --enable-calendar \
> --with-curl \
> --enable-exif \
> --enable-ftp \
> --enable-gd \
> --with-jpeg \
> --with-png \
> --with-zlib-dir \
> --with-freetype \
> --with-gettext \
> --enable-json \
> --enable-mbstring \
> --enable-pdo \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-readline \
> --enable-shmop \
> --enable-simplexml \
> --enable-sockets \
> --enable-zip \
> --enable-mysqlnd-compression-support \
> --with-pear \
> --enable-pcntl \
> --enable-posix
//这里如果报错需要安装两个依赖包,安装好后再次执行上面的命令
[root@xian php-7.4.7]# yum install sqlite-devel
[root@xian php-7.4.7]# yum -y install oniguruma-devel3.4
//-j指定内核数,后面的命令取出内核数量,多核的执行此条命令编译速度比单核的要快
[root@xian php-7.4.7]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@xian php-7.4.7]# make install
3.2 配置环境变量
[root@xian ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@xian ~]# source /etc/profile.d/php7.sh
[root@xian ~]# php -v
PHP 7.4.7 (cli) (built: Aug 10 2020 11:09:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
3.3 配置php-fpm
[root@xian ~]# cp php-7.4.7/php.ini-production /etc/php.ini
[root@xian ~]# cp php-7.4.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@xian ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@xian ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@xian ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@xian ~]# vim /usr/local/php7/etc/php-fpm.conf
//添加以下四行
pm.max_children = 50 //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5 //启动时启动5个进程
pm.min_spare_servers = 2 //最小空闲进程数
pm.max_spare_servers = 8 //最大空闲进程数
3.4 启动php-fpm
[root@xian ~]# service php-fpm start
Starting php-fpm done
[root@xian ~]# chkconfig php-fpm on
[root@xian ~]# ss -antl |grep 9000
LISTEN 0 128 127.0.0.1:9000 *:*
3.5 配置监听所有IP
[root@xian ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 0.0.0.0:9000 //将这里的127.0.0.1改为0.0.0.0`
[root@xian ~]# service php-fpm restart
4. 配置Nginx
4.1 创建php测试页面
[root@xian ~]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
4.2 修改nginx主配置文件
[root@xian ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm index.php; //在index后面添加index.php,表示有限访问php页面
}
//将以下内容取消注释并修改
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 并将/scripts改为$document_root
# include fastcgi_params;
#}
4.3 重启nginx
[root@xian ~]# nginx -s stop
[root@xian ~]# nginx