lamt部署

该博客详细记录了在Linux主机上安装和配置LAMP(Linux、Apache、MySQL、PHP)环境的过程,包括关闭防火墙和SELinux、安装Apache、MySQL和Tomcat,以及配置Apache作为反向代理服务器,将HTTP请求转发到Tomcat。最后,通过配置虚拟主机实现了通过Apache访问Tomcat应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LAMT
lamt部署

主机IP服务
192.168.136.135httpd-2.4.43 、 mysql-5.7 、 tomcat-9.0.46
关闭防火墙和selinux

[root@localhost ~]#  systemctl stop firewalld 
[root@localhost ~]#  setenforce 0
安装httpd

创建apache服务的用户和组
[root@localhost ~]#  useradd -r -M -s /sbin/nologin -g apache apache
​
安装依赖包
[root@localhost ~]#  yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget make
​
下载和安装apr以及apr-util
[root@localhost ~]#  wget https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz
[root@localhost ~]#  wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]#  tar xf apr-1.7.0.tar.gz 
[root@localhost ~]#  tar xf apr-util-1.6.1.tar.gz 
[root@localhost ~]#  cd apr-1.7.0
[root@happy apr-1.7.0]# vim configure
...
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile"    //将此行注释或者删除
...
[root@happy apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@happy apr-1.7.0]# make && make install
[root@happy apr-1.7.0]# cd ../apr-util-1.6.1
[root@happy apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@happy apr-util-1.6.1]# make && make install
​
下载和安装httpd
[root@localhost ~]#  wget https://archive.apache.org/dist/httpd/httpd-2.4.43.tar.gz
[root@localhost ~]#  tar xf httpd-2.4.43.tar.gz 
[root@localhost ~]#  cd httpd-2.4.43
[root@happy httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-proxy \
--enable-proxy-connect \
--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@happy httpd-2.4.43]# make && make install
​
安装后配置
[root@localhost ~]#  echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]#  source /etc/profile.d/httpd.sh
[root@localhost ~]#  ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]#  echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf
​
取消ServerName前面的注释
[root@localhost ~]#  sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
​
启动apache
[root@localhost ~]#  apachectl start
[root@localhost ~]#  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                           [::]:*                            
安装mysql

安装依赖包
[root@localhost ~]#  yum -y install libaio ncurses-devel openssl-devel openssl cmake mariadb-devel
​
创建用户和组
[root@localhost ~]#  useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql
​
下载二进制格式的mysql软件包
[root@localhost ~]#  wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]#  tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
​
创建软连接,修改文件属主
[root@localhost ~]#  cd  /usr/local/
[root@happy local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@happy local]# chown -R mysql.mysql /usr/local/mysql/
​
添加环境变量
[root@localhost ~]#  vim /etc/profile.d/mysql.sh
[root@localhost ~]#  cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]#  . /etc/profile.d/mysql.sh
[root@localhost ~]#  which mysql
/usr/local/mysql/bin/mysql
​
建立数据存放目录
[root@localhost ~]#  mkdir /opt/mysql-data
[root@localhost ~]#  chown -R mysql.mysql /opt/mysql-data/
​
初始化数据库
[root@localhost ~]#  ] /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/mysql-data
2021-06-15T11:39:50.807434Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-15T11:39:51.005362Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-06-15T11:39:51.041378Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-06-15T11:39:51.046622Z 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: 0379d25c-cdc6-11eb-9f5e-000c29369720.
2021-06-15T11:39:51.047530Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-06-15T11:39:51.476041Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-15T11:39:51.603173Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
​
生成配置文件
[root@localhost ~]#  vim /etc/my.cnf
[root@localhost ~]#  cat /etc/my.cnf
[mysqld]
datadir = /opt/mysql-data
basedir = /usr/local/mysql
datadir = /opt/mysql-data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/mysql-data/mysql.pid
user = mysql
skip-name-resolve
​
配置服务启动脚本
[root@localhost ~]#  cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]#  sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]#  sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
​
设置开机自启
[root@localhost ~]#  chkconfig --add mysqld
[root@localhost ~]#  chkconfig --list
​
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
​
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
​
mysqld          0:关   1:关   2:开    3:开    4:开    5:开    6:关
​
启动mysql
[root@localhost ~]#  service mysqld start
Starting MySQL.Logging to '/opt/mysql-data/C82.err'.
 SUCCESS! 
[root@localhost ~]#  ss -antl
State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
LISTEN     0      128                 *:22                              *:*                                 
LISTEN     0      80               [::]:3306                         [::]:*                  
LISTEN     0      128              [::]:80                           [::]:*                  
LISTEN     0      128              [::]:22                           [::]:*                         
​

安装tomcat

安装JDK
[root@localhost ~]#  yum -y install java-11-openjdk.x86_64 java-11-openjdk-devel.x86_64
​
安装tomcat
[root@localhost ~]#  wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.45/bin/apache-tomcat-9.0.45.tar.gz
[root@localhost ~]#  tar xf apache-tomcat-9.0.45.tar.gz
​
创建软连接
[root@localhost ~]#  cd /usr/local/
[root@happy local]# ln -s apache-tomcat-9.0.45 tomcat
​
启动tomcat
[root@happy local]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
​
[root@localhost ~]#  ss -antl
State  Recv-Q Send-Q      Local Address:Port   Peer Address:Port Process 
LISTEN 0      128               0.0.0.0:22          0.0.0.0:*            
LISTEN 0      1      [::ffff:127.0.0.1]:8005              *:*            
LISTEN 0      80                      *:3306              *:*            
LISTEN 0      128                     *:80                *:*            
LISTEN 0      100                     *:8080              *:*            
LISTEN 0      128                  [::]:22             [::]:*          

验证
在这里插入图片描述
在这里插入图片描述

配置apache

启动代理模块
[root@localhost ~]#  vim /etc/httpd24/httpd.conf 
将下面三行取消注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
​
配置虚拟主机
[root@localhost ~]#  vim /etc/httpd24/httpd.conf 
//在最后添加
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ProxyPass / http://192.168.11.120:8080/
    ProxyPassReverse / http://192.168.11.120:8080/
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
把所有http的请求代理到 http://192.168.11.120:8080/ ,也就是 Tomcat 的访问地址
​
//重启apache
[root@localhost ~]#  apachectl restart
[root@localhost ~]#  ss -antl
State  Recv-Q Send-Q      Local Address:Port   Peer Address:Port Process 
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      1      [::ffff:127.0.0.1]:8005              *:*            
LISTEN 0      80                      *:3306              *:*            
LISTEN 0      100                     *:8080              *:*            
LISTEN 0      128                  [::]:22             [::]:*    

验证
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值