• lamp分离部署


    lamp分离部署

    环境说明:

    主机IP 需要安装的服务 系统平台
    192.168.100.2 httpd redhat8
    192.168.100.3 mysql redhat8
    192.168.100.4 php redhat8

    本次环境YUM源(centos和epel)为:"阿里云官方镜像站"

    准备工作(3台):

    //配置centos源
    [root@localhost ~]# rm -rf /etc/yum.repos.d/*
    [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
    [root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    [root@localhost ~]# sed -i 's|$releasever|8|' /etc/yum.repos.d/CentOS-Base.repo
    
    //配置epel源
    [root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
    [root@localhost ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
    [root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
    [root@localhost ~]# sed -i 's|$releasever|8|' /etc/yum.repos.d/epel*
    [root@localhost ~]# yum clean all
    [root@localhost ~]# yum makecache
    
    //关闭防火墙和selinux
    [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# setenforce 0
    

    安装httpd

    //安装开发工具包
    [root@httpd ~]# yum -y groups mark install 'Development Tools'
    
    //创建apache服务的用户和组
    [root@httpd ~]# useradd -r -M -s /sbin/nologin apache
    
    //安装依赖包
    [root@httpd ~]# yum -y install bzip2 make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel
    
    //下载源码包
    [root@httpd ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.bz2
    [root@httpd ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
    [root@httpd ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
    [root@httpd ~]# ls
    anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.46.tar.bz2
    
    //安装apr
    [root@httpd ~]# tar xf apr-1.7.0.tar.gz
    [root@httpd ~]# cd apr-1.7.0
    [root@httpd apr-1.7.0]# vim configure
        cfgfile=${ofile}T
        trap "$RM "$cfgfile"; exit 1" 1 2 15
        # $RM "$cfgfile"		//将此行加上注释,或者删除此行
    [root@httpd apr-1.7.0]# ./configure --prefix=/usr/local/apr
    [root@httpd apr-1.7.0]# make
    [root@httpd apr-1.7.0]# make install
    
    //安装apr-util
    [root@httpd apr-1.7.0]# cd ..
    [root@httpd ~]# tar xf apr-util-1.6.1.tar.gz 
    [root@httpd ~]# cd apr-util-1.6.1
    [root@httpd apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    [root@httpd apr-util-1.6.1]# make
    [root@httpd apr-util-1.6.1]# make install
    
    //安装httpd
    [root@httpd apr-util-1.6.1]# cd ..
    [root@httpd ~]# tar xf httpd-2.4.46.tar.bz2 
    [root@httpd ~]# cd httpd-2.4.46
    [root@httpd httpd-2.4.46]# ./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@httpd httpd-2.4.46]# make
    [root@httpd httpd-2.4.46]# make install
    
    //安装后配置
    [root@httpd httpd-2.4.46]# cd
    [root@httpd ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
    [root@httpd ~]# source /etc/profile.d/httpd.sh
    [root@httpd ~]# which apachectl
    /usr/local/apache/bin/apachectl
    [root@httpd ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
    [root@httpd ~]# vim /etc/man_db.conf 
    MANDATORY_MANPATH                       /usr/local/apache/man
    
    //取消ServerName前面的注释
    [root@httpd ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
    
    //启动apache
    [root@httpd ~]# apachectl start
    [root@httpd ~]# 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                      *:80                    *:*      
    LISTEN   0         128                   [::]:22                 [::]:*
    

    安装mysql

    //安装依赖包
    [root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
    
    //创建mysql的用户和组
    [root@mysql ~]# useradd -r -M -s /sbin/nologin mysql
    
    //下载源码包
    [root@mysql ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    [root@mysql ~]# ls
    anaconda-ks.cfg  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    
    //解压mysql到/usr/local/
    [root@mysql ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    
    //设置软链接并修改属主和属组
    [root@mysql ~]# ln -s  /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
    [root@mysql ~]# chown -R mysql.mysql /usr/local/mysql*
    
    //添加环境变量
    [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 ~]# which mysql
    /usr/local/mysql/bin/mysql
    
    //建立数据存放目录
    [root@mysql ~]# mkdir /opt/data
    [root@mysql ~]# chown -R mysql.mysql /opt/data
    
    //初始化数据库
    [root@mysql ~]# mysqld --initialize --user=mysql --datadir=/opt/data
    ······
    root@localhost: Tu(Mds9ad30%
    
    //记住密码
    [root@mysql ~]# echo 'Tu(Mds9ad30%' > pass
    
    //配置mysql
    [root@mysql ~]# vim /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
    
    //配置服务启动脚本
    [root@mysql ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@mysql ~]# vim /etc/init.d/mysqld
    basedir=/usr/local/mysql
    datadir=/opt/data
    
    //启动mysql
    [root@mysql ~]# 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                      *:80                    *:*      
    LISTEN   0         128                   [::]:22                 [::]:*      
    LISTEN   0         80                       *:3306                  *:*      
    
    //查看密码登录mysql
    [root@mysql ~]# cat pass
    Tu(Mds9ad30%
    [root@mysql ~]# mysql -uroot -p'Tu(Mds9ad30%'
    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.31
    
    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> set password = password('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    mysql> quit
    Bye
    
    //安装后配置
    [root@mysql ~]# vim /etc/man_db.conf
    MANDATORY_MANPATH                       /usr/local/mysql/man
    [root@mysql ~]# vim /etc/ld.so.conf.d/mysql.conf
    /usr/local/mysql/lib
    [root@mysql ~]# ldconfig
    

    安装php

    //安装开发工具包
    [root@php ~]# 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
    

    配置apache和php

    httpd:
    //启用httpd的相关模块
    [root@httpd ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
    [root@httpd ~]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
    
    //配置虚拟主机
    [root@httpd ~]# vim /etc/httpd24/httpd.conf
    //在最后加入
    <VirtualHost *:80>
        DocumentRoot "/usr/local/apache/htdocs/"
        ServerName yuqinghao.com
        ProxyRequests Off
        ProxyPassMatch ^/(.*.php)$ fcgi://192.168.100.4:9000/var/www/html/$1
        <Directory "/usr/local/apache/htdocs/">
            Options none
            AllowOverride none
            Require all granted
        </Directory>
    </VirtualHost>
    
    //搜索AddType,添加以下内容
        # If the AddEncoding directives above are commented-out, then you
        # probably should define those extensions to indicate media types:
        #
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType application/x-httpd-php .php      		#添加此行
        AddType application/x-httpd-php-source .phps        #添加此行
    
    [root@httpd ~]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
    
    php:
    //修改配置文件
    [root@php ~]# vim /etc/php-fpm.d/www.conf
    ······
    listen = 0.0.0.0:9000					//修改成0.0.0.0:9000
    ······
    listen.allowed_clients = 192.168.100.2			//修改成httpd主机的ip地址
    
    //创建php测试页面
    [root@php ~]# echo -e "<?php
    	phpinfo();
    ?>" > /var/www/html/index.php
    [root@php ~]# chown -R apache.apache /var/www/html/
    
    //重启httpd和php服务
    [root@httpd ~]# apachectl restart
    [root@php ~]# systemctl restart php-fpm
    

    测试

    lamp1

  • 相关阅读:
    google 地图 v2
    javascript 跨域名 异常:
    cvs 使用规范
    fastcgi apache fcgi
    玄幻系列
    必须掌握的命令行(转)
    浏览器,RIA,flash,flex,siliverlight,socket
    游戏外挂的一些原理
    shtml我几乎要忘了的东西
    北京下雨了,兴奋中
  • 原文地址:https://www.cnblogs.com/yuqinghao/p/14248983.html
Copyright © 2020-2023  润新知