服务类型 | IP地址 | 应用 | 系统平台 |
---|---|---|---|
httpd | 192.168.93.129 | httpd | centos7 redhat7 |
mysql | 192.168.93.130 | mysql | centos7 redhat7 |
php | 192.168.93.131 | php phpmyadmin |
centos7 redhat7 |
//关闭防火墙和selinux
[root@http ~]# systemctl stop firewalld
[root@http ~]# systemctl disable firewalld
[root@http ~]# getenforce
Disabled
//下载开发工具包
[root@http ~]# yum groups mark install 'Development Tools'
//创建apache服务的用户和组
[root@http ~]# groupadd -r apache
[root@http ~]# useradd -r -M -s /sbin/nologin -g apache apache
//安装依赖包
[root@http ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
......
作为依赖被安装:
keyutils-libs-devel.x86_64 0:1.5.8-3.el7
krb5-devel.x86_64 0:1.15.1-8.el7
libcom_err-devel.x86_64 0:1.42.9-10.el7
libkadm5.x86_64 0:1.15.1-8.el7
libselinux-devel.x86_64 0:2.5-11.el7
libsepol-devel.x86_64 0:2.5-6.el7
libverto-devel.x86_64 0:0.2.5-4.el7
zlib-devel.x86_64 0:1.2.7-17.el7
完毕!
//下载和安装apr以及apr-util
[root@http ~]# cd /usr/src/
[root@http src]# ls
debug kernels
[root@http src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
[root@http src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@http src]# ls
apr-1.6.5.tar.gz apr-util-1.6.1.tar.gz debug kernels
[root@http src]# tar xf apr-1.6.5.tar.gz
[root@http src]# tar xf apr-util-1.6.1.tar.gz
[root@http src]# ls
apr-1.6.5 apr-util-1.6.1 debug
apr-1.6.5.tar.gz apr-util-1.6.1.tar.gz kernels
[root@http src]# cd apr-1.6.5
[root@http apr-1.6.5]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行删除或者加上注释
[root@http apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@http apr-1.6.5]# make && make install
[root@http apr-1.6.5]# cd /usr/src/apr-util-1.6.1
[root@http apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@http apr-util-1.6.1]# make && make install
//编译安装httpd
[root@http ~]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.38.tar.gz
[root@http ~]# ls
anaconda-ks.cfg httpd-2.4.38.tar.gz
[root@http ~]# tar xf httpd-2.4.38.tar.gz
[root@http ~]# ls
anaconda-ks.cfg httpd-2.4.38 httpd-2.4.38.tar.gz
[root@http ~]# cd httpd-2.4.38
[root@http httpd-2.4.38]# ./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@http httpd-2.4.38]# make && make install
//安装后配置
[root@http ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@http ~]# source /etc/profile.d/httpd.sh
[root@http ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@http ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
//取消ServerName前面的注释
[root@http ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
//启动apache服务
[root@http ~]# apachectl start
[root@http ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
//安装依赖包
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[root@mysql ~]# groupadd -r -g 306 mysql
[root@mysql ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
//下载二进制格式的mysql软件包
[root@mysql ~]# cd /usr/src/
[root@mysql src]# ls
debug kernels
[root@mysql src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mysql src]# ls
debug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mysql src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql src]# cd
[root@mysql ~]# ls /usr/local/
bin games lib libexec sbin src
etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
[root@mysql ~]# cd /usr/local/
[root@mysql local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"
[root@mysql local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 3月 10 2016 bin
drwxr-xr-x. 2 root root 6 3月 10 2016 etc
drwxr-xr-x. 2 root root 6 3月 10 2016 games
drwxr-xr-x. 2 root root 6 3月 10 2016 include
drwxr-xr-x. 2 root root 6 3月 10 2016 lib
drwxr-xr-x. 2 root root 6 3月 10 2016 lib64
drwxr-xr-x. 2 root root 6 3月 10 2016 libexec
lrwxrwxrwx 1 root root 36 8月 10 20:09 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 129 8月 10 20:08 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 3月 10 2016 sbin
drwxr-xr-x. 5 root root 49 3月 25 02:56 share
drwxr-xr-x. 2 root root 6 3月 10 2016 src
//修改目录/usr/local/mysql的属主属组
[root@mysql ~]# chown -R mysql.mysql /usr/local/mysql
[root@mysql ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 8月 10 20:09 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
//添加环境变量
[root@mysql ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@mysql ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql ~]# source /etc/profile.d/mysql.sh
[root@mysql ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
//建立数据存放目录
[root@mysql ~]# mkdir /opt/data
[root@mysql ~]# chown -R mysql.mysql /opt/data/
[root@mysql ~]# ll /opt/
总用量 0
drwxr-xr-x 2 mysql mysql 6 8月 10 20:16 data
//初始化数据库
[root@mysql ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2019-08-10T12:17:29.959505Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-10T12:17:30.902297Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-10T12:17:31.051861Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-10T12:17:31.392858Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d3ae6f6d-bb68-11e9-82bc-000c2918dd01.
2019-08-10T12:17:31.396859Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-10T12:17:31.405610Z 1 [Note] A temporary password is generated for root@localhost: hy)n=ek#&6FU
//配置mysql
[root@mysql ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@mysql ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@mysql ~]# ldconfig -v
//生成配置文件
[root@mysql ~]# 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@mysql ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
//启动mysql
[root@mysql ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/mysql.err'.
. SUCCESS!
[root@mysql ~]# ps -ef|grep mysql
root 18333 1 0 20:22 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 18511 18333 7 20:22 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 18543 1315 0 20:22 pts/0 00:00:00 grep --color=auto mysq
[root@mysql ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
//修改密码
//使用临时密码登录
[root@mysql ~]# mysql -uroot -p'hy)n=ek#&6FU'
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 2
Server version: 5.7.22
Copyright (c) 2000, 2018, 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>
//设置新密码
mysql> set password = password('jxy123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
//验证是否密码修改成功
[root@mysql ~]# mysql -uroot -p'jxy123!'
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.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
//关闭防火墙和selinux
[root@php ~]# systemctl stop firewalld
[root@php ~]# systemctl disable firewalld
[root@php ~]# getenforce
Disabled
//配置yum源
[root@php ~]# cd /etc/yum.repos.d/
[root@php yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@php yum.repos.d]# ls
2019.repo CentOS7-Base-163.repo redhat.repo
[root@php ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@php ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@php ~]# yum -y install epel-release
[root@php ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//安装依赖包
[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 libpcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72w-mysqlnd
//下载php
[root@php ~]# cd /usr/src/
[root@php src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@php src]# ls
debug kernels php-7.2.8.tar.xz
[root@php src]# tar xf php-7.2.8.tar.xz
[root@php src]# ls
debug kernels php-7.2.8 php-7.2.8.tar.xz
[root@php src]# cd php-7.2.8
[root@php php-7.2.8]# ./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 \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib-dir \
> --with-freetype-dir \
> --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@php php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@php php-7.2.8]# make install
//安装后配置
[root@php php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@php php-7.2.8]# source /etc/profile.d/php7.sh
[root@php php-7.2.8]# which php
/usr/local/php7/bin/php
//配置php-fpm
[root@php php-7.2.8]# cp php.ini-production /etc/php.ini
cp:是否覆盖"/etc/php.ini"? y
[root@php php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@php php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@php php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
//配置fpm的相关选项为你所需要的值:
include=/usr/local/php7/etc/php-fpm.d/*.conf
//在配置文件最后一行添加如下
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@php ~]# tail /usr/local/php7/etc/php-fpm.conf
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
//修改php-fpm服务器上配置文件,修改监听地址
[root@php ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 192.168.93.131:9000 //ip指向自己
listen.allowed_clients = 192.168.93.129 //ip填http的ip地址
//启动php-fpm
[root@php ~]# service php-fpm start
Starting php-fpm done
[root@php ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 192.168.93.131:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@php ~]# ps -ef|grep php
root 39527 1 0 21:09 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 39528 39527 0 21:09 ? 00:00:00 php-fpm: pool www
nobody 39529 39527 0 21:09 ? 00:00:00 php-fpm: pool www
nobody 39530 39527 0 21:09 ? 00:00:00 php-fpm: pool www
nobody 39531 39527 0 21:09 ? 00:00:00 php-fpm: pool www
nobody 39532 39527 0 21:09 ? 00:00:00 php-fpm: pool www
root 39540 1414 0 21:10 pts/0 00:00:00 grep --color=auto php
//编辑httpd.conf文件,取消以下两行内容的注释:
[root@http ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@http ~]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.con
//创建虚拟主机目录
[root@http ~]# mkdri /usr/local/apache/htdocs/jiangxiuying.com
[root@http ~]# mkdir /var/jxy
[root@http ~]# vim /etc/httpd24/httpd.conf
//在配置文件最后一行添加如下:
DocumentRoot "/usr/local/apache/htdocs/jiangxiuying.com"
ServerName www.jiangxiuying.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/jiangxiuying.com/$1
Options none
AllowOverride none
Require all granted
[root@http ~]# vim /etc/httpd24/httpd.conf
//搜索AddType,添加以下内容
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
//在index.html前面添加index.php
[root@http ~]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
//重启apache服务
[root@http ~]# apachectl stop
[root@http ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@http ~]# apachectl start
[root@http ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
//在php上创建index.php文件
[root@php ~]# mkdir /var/jxy
[root@php ~]# cd /var/jxy/
[root@php jxy]# vim index.php
[root@php jxy]# cat index.php
//在浏览器上验证
//下载phpMyAdmin压缩包
[root@php ~]# wget https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
[root@php ~]# ls
anaconda-ks.cfg phpMyAdmin-4.0.10.20-all-languages.zip
//解压到/var/jxy下
[root@php ~]# unzip phpMyAdmin-4.0.10.20-all-languages.zip
[root@php ~]# mv phpMyAdmin-4.0.10.20-all-languages /var/jxy/
[root@php ~]# ls /var/jxy/
index.php phpMyAdmin-4.0.10.20-all-languages
//建立软链接
[root@php ~]# cd /var/jxy/
[root@php jxy]# ln -sv phpMyAdmin-4.0.10.20-all-languages PMA
"PMA" -> "phpMyAdmin-4.0.10.20-all-languages"
[root@php jxy]# ll
总用量 8
-rw-r--r-- 1 root root 23 8月 10 21:24 index.php
drwxr-xr-x 9 root root 4096 3月 28 2017 phpMyAdmin-4.0.10.20-all-languages
lrwxrwxrwx 1 root root 34 8月 10 22:19 PMA -> phpMyAdmin-4.0.10.20-all-languages
[root@php jxy]# cd PMA/
[root@php PMA]# mv config.sample.inc.php config.inc.php
[root@php PMA]# vim config.inc.php
$cfg['blowfish_secret'] = 'jxy123'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['Servers'][$i]['host'] = '192.168.93.130'; //将localhost修改为数据库的地址
//重启php-fpm服务
[root@php ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@php ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 192.168.93.131:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@mysql ~]# mysql -uroot -p'jxy123!'
mysql> grant all on *.* to PMA@'192.168.93.%' identified by 'PMApass';
Query OK, 0 rows affected, 1 warning (0.50 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.32 sec)
mysql>
//将反向代理目录改成php共享的目录
[root@http ~]# vim /etc/httpd24/httpd.conf
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.jiangxiuying.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.93.131:9000/var/jxy/PMA/$1
Options none
AllowOverride none
Require all granted
[root@http ~]# mkdir /usr/local/apache/htdocs/pma
[root@http ~]# apachectl stop
[root@http ~]# apachectl start
[root@http ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*