lamt部署

lamt源码部署

准备工作

配置yum源,关闭防火墙和selinux
//配置yum源(阿里源)
[root@tomcat ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed
[root@tomcat ~]# yum makecache

//关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
拉取相应源码包
[root@localhost ~]# yum -y install wget vim
. . .
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.80.tar.gz  apr-1.7.4.tar.gz  apr-util-1.6.3.tar.gz  httpd-2.4.57.tar.gz

安装apache

//安装依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ make pcre-devel openssl openssl-devel libtool expat-devel bzip2
. . . 

//安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'

//创建apache服务的用户和组
[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache

//解压源码包
[root@localhost ~]# tar xf apr-1.7.4.tar.gz -C /usr/local/
[root@localhost ~]# tar xf apr-util-1.6.3.tar.gz -C /usr/local/
[root@localhost ~]# tar xf httpd-2.4.57.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/ && ls
apr-1.7.4  apr-util-1.6.3  bin  etc  games  httpd-2.4.57  include  lib  lib64  libexec  sbin  share  src

//进入apr的源码包目录,在configure定制组件中修改相关信息
[root@localhost local]# cd apr-1.7.4/
[root@localhost apr-1.7.4]# ls
apr-config.in  atomic            config.layout  file_io     LICENSE       network_io     README.cmake  time
apr.dep        build             configure      helpers     locks         NOTICE         shmem         tools
apr.dsp        build.conf        configure.in   include     Makefile.in   NWGNUmakefile  strings       user
apr.dsw        buildconf         docs           libapr.dep  Makefile.win  passwd         support
apr.mak        build-outputs.mk  dso            libapr.dsp  memory        poll           tables
apr.pc.in      CHANGES           emacs-mode     libapr.mak  misc          random         test
apr.spec       CMakeLists.txt    encoding       libapr.rc   mmap          README         threadproc

[root@localhost apr-1.7.4]# sed -i 's/$RM "$cfgfile"/ # $RM "$cfgfile"/g' configure
[root@localhost apr-1.7.4]# grep -C2 '# $RM "$cfgfile"' configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
     # $RM "$cfgfile"

    cat <<_LT_EOF >> "$cfgfile"
[root@tomcat apr-1.7.4]#

//编译安装apr-1.7.4、apr-util-1.6.3、httpd-2.4.57
[root@localhost apr-1.7.4]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.4]# make && make install

[root@localhost apr-1.7.4]# cd ../apr-util-1.6.3/
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.3]# make && make install

[root@localhost apr-util-1.6.3]# cd ../httpd-2.4.57/
[root@localhost httpd-2.4.57]# ./configure --prefix=/usr/local/apache \
 --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@localhost httpd-2.4.57]# make && make install

//安装后配置
[root@localhost httpd-2.4.57]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@localhost httpd-2.4.57]# source /etc/profile.d/apache.sh
[root@localhost httpd-2.4.57]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost httpd-2.4.57]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

//取消ServerName前面的注释
[root@localhost httpd-2.4.57]# sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf

//启动httpd服务
[root@localhost httpd-2.4.57]# apachectl start
[root@localhost httpd-2.4.57]# 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              128                                  *:80                                *:*

在这里插入图片描述

安装mariadb

yum命令安装mariadb

[root@localhost ~]# yum -y install mariadb mariadb-server
[root@localhost ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@note1 ~]# mysql -e "set password = password('12345678');"

//查看端口
[root@localhost ~]# 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                              *:*            
LISTEN         0              128                                  *:80                                *:*

安装tomcat

//安装依赖包
[root@localhost ~]# dnf -y install java-17-openjdk java-17-openjdk-devel

//查看安装的版本,能够查看到版本则说明安装成功
[root@localhost ~]# java --version
openjdk 17.0.1 2021-10-19 LTS
OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS)
OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing)

//解压源码包至指定目录
[root@localhost ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
--2023-10-12 23:47:55--  https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
Resolving archive.apache.org (archive.apache.org)... 65.108.204.189, 2a01:4f9:1a:a084::2
Connecting to archive.apache.org (archive.apache.org)|65.108.204.189|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11692853 (11M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.80.tar.gz’

apache-tomcat-9.0.80.tar 100%[================================>]  11.15M   198KB/s    in 55s     

2023-10-12 23:48:52 (207 KB/s) - ‘apache-tomcat-9.0.80.tar.gz’ saved [11692853/11692853]


[root@localhost ~]# tar xf apache-tomcat-9.0.80.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/ && ls
apache                apr        apr-util        bin  games         include  lib64    sbin   src
apache-tomcat-9.0.80  apr-1.7.4  apr-util-1.6.3  etc  httpd-2.4.57  lib      libexec  share

//设置tomcat软链接,方便后续如果更换tomcat版本后也能直接使用
[root@localhost local]# ln -s apache-tomcat-9.0.80 tomcat
[root@localhost local]# ll 
total 12
drwxr-xr-x. 14 root root   164 Oct 10 23:52 apache
drwxr-xr-x.  9 root root   220 Oct 11 00:07 apache-tomcat-9.0.80
drwxr-xr-x.  6 root root    58 Oct 10 23:45 apr
drwxr-xr-x. 29  501 games 4096 Oct 10 23:45 apr-1.7.4
drwxr-xr-x.  5 root root    43 Oct 10 23:46 apr-util
drwxr-xr-x. 21  501 games 4096 Oct 10 23:46 apr-util-1.6.3
drwxr-xr-x.  2 root root     6 Aug 12  2018 bin
drwxr-xr-x.  2 root root     6 Aug 12  2018 etc
drwxr-xr-x.  2 root root     6 Aug 12  2018 games
drwxr-xr-x. 14  501 games 4096 Oct 10 23:51 httpd-2.4.57
drwxr-xr-x.  2 root root     6 Aug 12  2018 include
drwxr-xr-x.  2 root root     6 Aug 12  2018 lib
drwxr-xr-x.  2 root root     6 Aug 12  2018 lib64
drwxr-xr-x.  2 root root     6 Aug 12  2018 libexec
drwxr-xr-x.  2 root root     6 Aug 12  2018 sbin
drwxr-xr-x.  5 root root    49 Jul 20 11:24 share
drwxr-xr-x.  2 root root     6 Aug 12  2018 src
lrwxrwxrwx.  1 root root    20 Oct 11 00:08 tomcat -> apache-tomcat-9.0.80

//将tomcat的lib位置存放在/etc/ld.so.conf/d/下面,命名一个自身名字的文件,方便查找
[root@localhost local]# vim /etc/ld.so.conf.d/tomcat.conf
[root@localhost local]# cat /etc/ld.so.conf.d/tomcat.conf
/usr/localhost/tomcat/lib

//启动服务,使用绝对路径执行/usr/local/tomcat/bin/下面的脚本,tomcat不能写进环境变量,放置后续更改tomcat版本后环境变量仍是之前的tomcat版本
[root@localhost local]# cd tomcat/bin/
[root@localhost bin]# ./catalina.sh start
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 bin]# 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              1                      [::ffff:127.0.0.1]:8005                            *:*           
LISTEN         0              80                                      *:3306                            *:*           
LISTEN         0              100                                     *:8080                            *:*           
LISTEN         0              128                                     *:80                              *:*

启用httpd的代理模块

[root@localhost ~]# sed -i '/proxy_module/s/#//g' /usr/local/apache/conf/httpd.conf
[root@localhost ~]# sed -i '/proxy_fcgi_module/s/#//g' /usr/local/apache/conf/httpd.conf
[root@localhost ~]# sed -i '/proxy_connect_module/s/#//g' /usr/local/apache/conf/httpd.conf
[root@localhost ~]# sed -i '/proxy_http_module/s/#//g' /usr/local/apache/conf/httpd.conf

配置虚拟主机

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
[root@localhost ~]# tail -13 /usr/local/apache/conf/httpd.conf
SSLRandomSeed connect builtin
</IfModule>

<VirtualHost *:80>
     DocumentRoot "/usr/local/apache/htdocs"
     ProxyPass / http://192.168.134.148:8080/
     ProxyPassReverse / http://192.168.134.148:8080/
     <Directory "/usr/local/apache/htdocs">
         Options none
         AllowOverride none
         Require all granted
         </Directory>
</VirtualHost>

重启apache

[root@localhost ~]# apachectl restart
[root@localhost ~]# 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              1                      [::ffff:127.0.0.1]:8005                            *:*           
LISTEN         0              80                                      *:3306                            *:*           
LISTEN         0              100                                     *:8080                            *:*           
LISTEN         0              128                                     *:80                              *:*

通过80端口进行访问

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值