环境:
应用 |
IP |
操作系统 |
nginx |
192.168.23.148 |
centos8 |
mysql |
192.168.23.142 |
centos8 |
php |
192.168.23.143 |
centos8 |
准备工作
//关闭防火墙与selinux
nginx
[root@nginx ]# systemctl stop firewalld
[root@nginx ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@nginx ]# setenforce 0
[root@nginx ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
mysql
[root@mysql ]# systemctl stop firewalld
[root@mysql ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mysql ]# setenforce 0
[root@mysql ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
php
[root@php ]# systemctl stop firewalld
[root@php ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@php ]# setenforce 0
[root@php ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
安装nginx
//创建系统用户nginx
[root@nginx ~]# useradd -r -M -s /sbin/nologin nginx
//安装依赖环境
[root@nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@nginx ~]# yum -y groups mark install 'Development Tools'
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools
//创建日志存放目录
[root@nginx ~]# mkdir -p /var/log/nginx
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx
[root@nginx ~]# cd /usr/src/
[root@nginx src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
--2021-05-24 23:01:08-- http://nginx.org/download/nginx-1.12.0.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 980831 (958K) [application/octet-stream]
Saving to: ‘nginx-1.12.0.tar.gz’
nginx-1.12.0.tar.gz 100%[============================================>] 957.84K 11.9KB/s in 76s
2021-05-24 23:02:25 (12.5 KB/s) - ‘nginx-1.12.0.tar.gz’ saved [980831/980831]
//编译安装
[root@nginx src]# ls
debug kernels nginx-1.12.0.tar.gz
[root@nginx src]# tar xf nginx-1.12.0.tar.gz
[root@nginx src]# cd nginx-1.12.0
[root@nginx nginx-1.12.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@nginx nginx-1.12.0]# make && make install
修改配置文件
//修改配置文件
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
//添加index.php
index index.php index.html index.htm;
}
location ~ \.php$ {
// 设置监听端口
fastcgi_pass 192.168.248.17:9000;
// 设置nginx的默认首页文件
fastcgi_index index.php;
// 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; 将$scripts修改为php根网站目录
//引入fastcgi的配置文件
include fastcgi_params;
}
//检查语法是否有误
[root@nginx ~]# 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
//创建ndex.php
[root@nginx ~]# cat > /usr/local/nginx/html/index.php <<EOF
> <?php
> phpinfo();
> ?>
> EOF
//启动服务
[root@nginx ~]# nginx
[root@nginx html]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
安装mysql
//wget安装
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
//安装依赖
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
//创建用户
[root@mysql ~]# useradd -r -M -s /sbin/nologin mysql
//安装mysql
[root@mysql ~]# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql ~]# ln -sv /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@mysql ~]# cd /usr/local/
[root@mysql local]# chown -R mysql.mysql mysql*
//添加环境变量
[root@mysql local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/myslq.sh
[root@mysql local]# source /etc/profile.d/myslq.sh
[root@mysql local]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@mysql local]# echo '/usr/local/mysql/lib' >/etc/ld.so.conf.d/mysql.conf
[root@mysql local]# ldconfig
//创建数据存放目录
[root@mysql local]# mkdir /opt/mydata
[root@mysql local]# chown -R mysql.mysql /opt/mydata/
//初始化数据库不用密码
[root@mysql local]# mysqld --initialize-insecure --user=mysql --datadir=/opt/mydata
//生成配置文件
[root@mysql local]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/opt/mydata
socket=/tmp/mysql.sock
port=3306
pid-file=/opt/mydata/mysql.pid
user=mysql
skip-name-resolve
EOF
//配置服务启动脚本
[root@mysql local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql local]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@mysql local]# sed -ri 's#^(datadir=).*#\1/opt/mydata#g' /etc/init.d/mysqld
//启动MySQL
[root@mysql local]# service mysqld start
[root@mysql ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
//修改配置
//更改配置文件
[root@mysql ~]# vim /etc/man_db.conf
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH manpath_element
# MANPATH_MAP path_element manpath_element
# MANDB_MAP global_manpath [relative_catpath]
#---------------------------------------------------------
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man //添加这一行内容
[root@mysql ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
//设置密码
[root@mysql local]# mysql -e "set password = password('yanchuang')"
安装php
//安装开发工具包
[root@yc4 ~]# yum -y groups mark install 'Development Tools'
//安装依赖包
[root@php ~]# 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 php-mysqlnd
//安装php
[root@php ~]# yum -y install php-*
//启动php
[root@php ~]# systemctl start php-fpm
[root@php html]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*