保证防火墙和selinux已经关闭,如果没有关闭可执行
systemctl stop firewalld
和setseenforce 0
来关闭
系统 | 主机名 | IP | 服务 |
---|---|---|---|
CentOS 7 | node1 | 192.168.207.129 | httpd2.4 |
CentOS 7 | node2 | 192.168.207.130 | mysql5.7 |
RedHat 7 | node3 | 192.168.207.131 | php7.4 |
node1
上安装和配置httpd配置yum源
//下载wget
[root@node1 ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
//下载Centos7的源
[root@node1 ~]# mv /etc/yum.repos.d/* /opt
[root@node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@node1 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo
//配置Centos7的源
[root@node1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@node1 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
//下载epel源
[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@node1 ~]# yum clean all
安装开发工具包
[root@node1 ~]# yum groups mark install 'Development Tools'
创建apache服务的用户和组
[root@node1 ~]# useradd -r -M -s /sbin/nologin apache
[root@node1 ~]# id apache
uid=997(apache) gid=995(apache) groups=995(apache)
安装依赖包
[root@node1 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
下载并解压apr和apr-util
[root@node1 ~]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@node1 ~]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@node1 ~]# tar xf apr-1.7.0.tar.gz
[root@node1 ~]# tar xf apr-util-1.6.1.tar.gz
[root@node1 ~]# ls
apr-1.7.0 apr-util-1.6.1
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
安装apr和apr-util
//安装apr
[root@node1 ~]# cd apr-1.7.0
[root@node1 apr-1.7.0]# sed -ri '/^(....\$RM."\$cfgfile")$/d' configure
[root@node1 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@node1 apr-1.7.0]# make && make install
//安装apr-util
[root@node1 apr-1.7.0]# cd ../apr-util-1.6.1
[root@node1 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@node1 apr-util-1.6.1]# make && make install
[root@node1 apr-util-1.6.1]# cd
下载并编译安装httpd
[root@node1 ~]# wget https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@node1 ~]# tar xf httpd-2.4.43.tar.gz
[root@node1 ~]# cd httpd-2.4.43
[root@node1 httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@node1 httpd-2.4.43]# make && make install
配置httpd
//配置环境变量
[root@node1 httpd-2.4.43]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@node1 httpd-2.4.43]# source /etc/profile.d/httpd.sh
//创建软连接
[root@node1 httpd-2.4.43]# ln -s /usr/local/apache/include /usr/include/httpd
//配置帮助文档
[root@node1 httpd-2.4.43]# echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf
//取消注释
[root@node1 httpd-2.4.43]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
[root@node1 httpd-2.4.43]# cd
启动apache
[root@node1 ~]# apachectl start
[root@node1 ~]# ss -antl|grep 80
LISTEN 0 128 :::80 :::*
node2
上安装和配置mysql配置yum源
//下载wget
[root@node2 ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
//下载Centos7的源
[root@node2 ~]# mv /etc/yum.repos.d/* /opt
[root@node2 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@node2 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo
//配置Centos7的源
[root@node2 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@node2 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
//下载epel源
[root@node2 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@node2 ~]# yum clean all
安装依赖包
[root@node2 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
下载mysql安装包
[root@node2 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@node2 ~]# ls
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
解压mysql安装包至/usr/local目录中
[root@node2 ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
配置mysql
//创建mysql用户和组
[root@node2 ~]# useradd -r -M -s /sbin/nologin -u 306 mysql
[root@node2 ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
//创建软连接并配置文件属组
[root@node2 ~]# ln -s /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql
[root@node2 ~]# chown -R mysql.mysql /usr/local/mysql*
[root@node2 ~]# ll -d /usr/local/mysql*
lrwxrwxrwx. 1 mysql mysql 46 7月 11 09:49 /usr/local/mysql -> /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 7月 11 09:47 /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64
//配置环境变量
[root@node2 ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@node2 ~]# source /etc/profile.d/mysql.sh
//创建数据存放目录
[root@node2 ~]# mkdir /opt/data
[root@node2 ~]# chown -R mysql.mysql /opt/data
[root@node2 ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 7月 11 09:54 /opt/data/
//初始化数据库
//这里用了insecure选项,所以初始化之后可以免密码登录
[root@node2 ~]# mysqld --initialize-insecure --user=mysql --datadir=/opt/data
//创建include头文件的软连接
[root@node2 ~]# ln -s /usr/local/mysql/include /usr/include/mysql
//配置帮助文档
[root@node2 ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@node2 ~]# ldconfig
生成配置文件
[root@node2 ~]# cat > /etc/my.cnf <
[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
配置服务启动脚本
[root@node2 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@node2 ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@node2 ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
启动mysql
[root@node2 ~]# service mysqld start
[root@node2 ~]# chkconfig mysqld on
[root@node2 ~]# ss -antl |grep 3306
LISTEN 0 80 :::3306 :::*
修改登录密码
[root@node2 ~]# mysql --connect-expired-password -uroot -e "set password = password('123')"
[root@node2 ~]# mysql -uroot -p123
mysql> exit
Bye
node3
上安装和配置php配置yum源
//下载wget
[root@node3 ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
//下载Centos7的源
[root@node3 ~]# mv /etc/yum.repos.d/* /opt
[root@node3 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@node3 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo
//配置Centos7的源
[root@node3 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@node3 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
//下载epel源
[root@node3 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@node3 ~]# yum clean all
//下载remi源
//remi源下载较慢,可以使用迅雷下载到本地然后传进来
[root@node3 ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@node3 ~]# ls
remi-release-7.rpm
[root@node3 ~]# yum -y localinstall remi-release-7.rpm
[root@node3 ~]# yum clean all
[root@node3 ~]# yum makecache --enablerepo=remi-php74
安装依赖包
[root@node3 ~]# yum -y gcc gcc-c++ 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 libsqlite3x-devel oniguruma-devel php74-php-mysqlnd
下载并安装php
[root@node3 ~]# wget https://www.php.net/distributions/php-7.4.7.tar.gz
[root@node3 ~]# tar xf php-7.4.7.tar.gz
[root@node3 ~]# cd php-7.4.7
[root@node3 ~]# ./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
编译安装php
//-j指定内核数,后面的命令取出内核数量,多核的执行此条命令编译速度比单核的要快
[root@node1 php-7.4.7]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@node1 php-7.4.7]# make install
配置php-fpm
//配置环境变量
[root@node3 ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@node3 ~]# source /etc/profile.d/php7.sh
//配置服务启动脚本
[root@node3 ~]# cp php-7.4.7/php.ini-production /etc/php.ini
[root@node3 ~]# cp php-7.4.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node3 ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@node3 ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@node3 ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
启动php-fpm
[root@node3 ~]# service php-fpm start
[root@node3 ~]# chkconfig php-fpm on
[root@node3 ~]# ss -antl |grep 9000
LISTEN 0 128 127.0.0.1:9000 *:*
//配置监听所有IP
[root@node3 ~]# sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/' /usr/local/php7/etc/php-fpm.d/www.conf
[root@node3 ~]# service php-fpm restart
[root@node3 ~]# ss -antl |grep 9000
LISTEN 0 128 *:9000 *:*
在node1
上启用代理模块
[root@node1 ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@node1 ~]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
在node1
上配置虚拟主机
[root@node1 ~]# chown -R apache.apache /usr/local/apache/htdocs
[root@node1 ~]# echo 'hello' > /usr/local/apache/htdocs/index.html
[root@node1 ~]# sed -ir '/ AddType application\/x-gzip .gz .tgz/a \ AddType application/x-httpd-php-source .phps' /etc/httpd24/httpd.conf
[root@node1 ~]# sed -ir '/ AddType application\/x-gzip .gz .tgz/a \ AddType application/x-httpd-php .php' /etc/httpd24/httpd.conf
[root@node1 ~]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
[root@node1 ~]# cat >> /etc/httpd24/httpd.conf <
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs"
ServerName test.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.207.131:9000/lamp/\$1
<Directory "/usr/local/apache/htdocs">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
EOF
[root@node1 ~]# apachectl restart
配置项目实例
//查看项目文件
[root@node3 PbootCMS]# ls
admin.php config doc LICENSE robots.txt
api.php core favicon.ico README.md static
apps data index.php rewrite template
//配置项目文件
[root@node3 PbootCMS]# cd config/
[root@node3 config]# ls
config.php database.php route.php
[root@node3 config]# vi database.php
'database' => array(
'type' => 'mysqli', // 数据库连接驱动类型: mysqli,sqlite,pdo_mysql,pdo_sqlite
'host' => '192.168.207.130', // 数据库服务器
'user' => 'root', // 数据库连接用户名
'passwd' => '123', // 数据库连接密码
'port' => '3306', // 数据库端口
'dbname' => 'abc' // 去掉注释,启用mysql数据库,注意修改前面的连接信>息及type为mysqli
//'dbname' => '/data/pbootcms.db' // 去掉注释,启用Sqlite数据库,注意>修改type为sqlite
)
[root@node3 PbootCMS]# scp static/backup/sql/* [email protected]:/root
[email protected] s password:
0cb2353f8ea80b398754308f15d1121e_2020070523 100% 114KB 23.3MB/s 00:00
[root@node2 ~]# mysql -uroot -p123
mysql> create database abc;
Query OK, 1 row affected (0.01 sec)
mysql> use abc
Database changed
mysql> source 0cb2353f8ea80b398754308f15d1121e_20200705235534_pbootcms.sql
mysql> grant all on *.* to 'root'@192.168.207.131 identified by '123';
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql> exit
Bye
//将网站文件放入lamp目录中
[root@node3 PbootCMS]# cp -rf * /lamp/
//将静态文件传到apache服务器中
[root@node3 lamp]# scp -r static/ [email protected]:/usr/local/apache/htdocs
[root@node3 lamp]# scp -r template/ [email protected]:/usr/local/apache/htdocs
[root@node3 lamp]# scp -r apps/ [email protected]:/usr/local/apache/htdocs