lamt部署

lamt部署

步骤:

  1. 安装apache
  2. 安装mysql
  3. 安装tomcat
  4. 配置apache

tomcat简介

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 规范。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
诀窍是,当配置正确时,Apache 为HTML页面服务,而Tomcat 实际上运行JSP 页面和Servlet。另外,Tomcat和IIS等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTML的能力不如Apache服务器。目前Tomcat最新版本为9.0。

tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中。而tomcat本身的运行也依赖于jdk环境。

安装apache

安装开发工具包


[root@localhost ~]# dnf -y install epel-release

[root@localhost ~]# dnf -y groups mark install "Development Tools"

创建apache服务的用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

安装依赖包

[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

编译安装httpd

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.43.tar.bz2  kernels

[root@localhost src]# tar xf apr-1.7.0.tar.bz2 
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2 
[root@localhost src]# tar xf httpd-2.4.43.tar.bz2 
[root@localhost src]# ls
apr-1.7.0          apr-util-1.6.1          debug         httpd-2.4.43.tar.bz2
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.43  kernels


[root@localhost src]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
    cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行
    
//配置
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
//编译安装
[root@localhost apr-1.7.0]# make && make install

//配置
[root@localhost apr-1.7.0]# cd /usr/src/apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
//编译安装
[root@localhost apr-util-1.6.1]# make && make install


//配置
[root@localhost ~]# cd httpd-2.4.43
[root@localhost 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@localhost 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 ~]# vim /etc/man_db.conf    //在这个文件里加入下列一行内容

MANDATORY_MANPATH                       /usr/local/apache/man

开启apache

[root@localhost ~]# apachectl start  
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

[root@localhost ~]# systemctl disable firewalld  //永久性关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port  Process  
LISTEN   0        128              0.0.0.0:111           0.0.0.0:*              
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*              
LISTEN   0        5              127.0.0.1:631           0.0.0.0:*              
LISTEN   0        128                 [::]:111              [::]:*              
LISTEN   0        128                    *:80                  *:*              
LISTEN   0        128                 [::]:22               [::]:*              
LISTEN   0        5                  [::1]:631              [::]:*              

安装mysql

安装依赖包

[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

创建用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

解压软件至/usr/local/

[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache    bin    include  libexec                              share
apr       etc    lib      mysql-5.7.33-linux-glibc2.12-x86_64  src
apr-util  games  lib64    sbin

[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql   //修改一下名字方便后续操作
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src

修改目录/usr/local/mysql的属主属组

[root@localhost local]# ll /usr/local/mysql -d
drwxr-xr-x. 9 root root 129 615 18:18 /usr/local/mysql
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d
drwxr-xr-x. 9 mysql mysql 129 615 18:18 /usr/local/mysql

添加环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh 
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf  //添加下列一行内容

/usr/local/mysql/lib

[root@localhost ~]# ldconfig
[root@localhost ~]# vim /etc/man_db.conf   //添加下列一行内容
MANDATORY_MANPATH                       /usr/local/mysql/man

建立数据存放目录

[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 615 18:40 data

初始化数据库

[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-12T13:49:08.214347Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T13:49:08.703901Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T13:49:08.782468Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T13:49:08.839617Z 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: d333fe0e-b328-11eb-8f31-000c29f893b1.
2021-05-12T13:49:08.840917Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T13:49:09.329992Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T13:49:09.468731Z 1 [Note] A temporary password is generated for root@localhost: ,WwgSw<M0?zw   //这个密码是随机生成的需要记住,所以给它放到一个文件夹里以防遗忘
[root@localhost ~]# echo ',WwgSw<M0?zw' > pass
[root@localhost ~]# cat pass
,WwgSw<M0?zw

生成配置文件

[root@localhost ~]# cat > /etc/my.cnf <<EOF
> [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@localhost ~]# 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

//配置服务启动脚本
[root@localhost ~]# ls /usr/local/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost ~]# ls /usr/local/mysql/support-files/
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@localhost ~]# vim /etc/init.d/mysqld 
//补齐这两行=后面的路径
basedir=/usr/local/mysql
datadir=/opt/data

启动mysql`

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port  Process  
LISTEN   0        128              0.0.0.0:111           0.0.0.0:*              
LISTEN   0        32         192.168.122.1:53            0.0.0.0:*              
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*              
LISTEN   0        5              127.0.0.1:631           0.0.0.0:*              
LISTEN   0        128                 [::]:111              [::]:*              
LISTEN   0        128                    *:80                  *:*              
LISTEN   0        128                 [::]:22               [::]:*              
LISTEN   0        5                  [::1]:631              [::]:*              
LISTEN   0        80                     *:3306                *:*       


[root@localhost ~]# dnf -y install ncurses-compat-libs

mysql> set password = password('ZHANGde12+Jun')//修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
    
//设置开机自启
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:1:2:3:4:5:6:

安装tomcat

java环境安装

//安装jdk环境
[root@localhost ~]# yum install -y java-11-openjdk-devel java-11-openjdk

//查看安装的版本
[root@localhost ~]# java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)

tomcat部署

安装包链接

//解压部署
[root@localhost ~]# tar xf apache-tomcat-9.0.24.tar.gz

[root@localhost local]# mv apache-tomcat-9.0.46 /usr/local/tomcat
[root@localhost local]# cd tomcat/
[root@localhost tomcat]# ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp

//启动tomcat
[root@localhost tomcat]# /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 tomcat]# ss -antl
State   Recv-Q  Send-Q          Local Address:Port     Peer Address:Port  Process  
LISTEN  0       128                   0.0.0.0:111           0.0.0.0:*              
LISTEN  0       32              192.168.122.1:53            0.0.0.0:*              
LISTEN  0       128                   0.0.0.0:22            0.0.0.0:*              
LISTEN  0       5                   127.0.0.1:631           0.0.0.0:*              
LISTEN  0       100                 127.0.0.1:25            0.0.0.0:*              
LISTEN  0       1          [::ffff:127.0.0.1]:8005                *:*              
LISTEN  0       80                          *:3306                *:*              
LISTEN  0       128                      [::]:111              [::]:*              
LISTEN  0       100                         *:8080                *:*              
LISTEN  0       128                         *:80                  *:*              
LISTEN  0       128                      [::]:22               [::]:*              
LISTEN  0       5                       [::1]:631              [::]:*              
LISTEN  0       100                     [::1]:25               [::]:*  

配置apache

[root@localhost local]# cd apache
[root@localhost apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost apache]# cd conf
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original

[root@localhost conf]# vim 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

//在配置文件最后加入一下内容
//把所有的http请求代理http://192.168.147.66:8080/
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/conf"
    ProxyPass / http://192.168.147.66:8080/
    ProxyPassReverse / http://192.168.147.66:8080/
    <Directory "/usr/local/apache/conf">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>


//重启apache
[root@localhost conf]# systemctl restart httpd
[root@localhost conf]# ss -antl
State   Recv-Q  Send-Q          Local Address:Port     Peer Address:Port  Process  
LISTEN  0       128                   0.0.0.0:111           0.0.0.0:*              
LISTEN  0       32              192.168.122.1:53            0.0.0.0:*              
LISTEN  0       128                   0.0.0.0:22            0.0.0.0:*              
LISTEN  0       5                   127.0.0.1:631           0.0.0.0:*              
LISTEN  0       100                 127.0.0.1:25            0.0.0.0:*              
LISTEN  0       1          [::ffff:127.0.0.1]:8005                *:*              
LISTEN  0       80                          *:3306                *:*              
LISTEN  0       128                      [::]:111              [::]:*              
LISTEN  0       128                         *:80                  *:*              
LISTEN  0       100                         *:8080                *:*              
LISTEN  0       128                      [::]:22               [::]:*              
LISTEN  0       5                       [::1]:631              [::]:*              
LISTEN  0       100                     [::1]:25               [::]:* 

测试:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值