lamt

1.简介

LAMT = Linux + Apache + Mysql或Mariadb + Tomcat

2.安装apache服务

1.1YUM源配置

[root@localhost ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum -y install epel-release

1.2安装开发工具包

[root@localhost yum.repos.d]# yum groups mark install 'Development Tools'

1.3安装apache依赖包

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

创建apache服务的用户和组

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

下载和安装apr以及apr-util

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# yum -y install bzip2
[root@localhost ~]# tar xf apr-1.7.0.tar.bz2 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2 
[root@localhost ~]# ls
apr-1.7.0  apr-1.7.0.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  kernels
[root@localhost ~]# 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
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
......
[root@localhost apr-1.7.0]# make && make install    //编译
[root@localhost ~]# cd 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

编译安装httpd

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@localhost ~]# ls
apr-1.7.0          apr-util-1.6.1          debug                 kernels
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.43.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2 
[root@localhost ~]# 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 ~]# 
[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 ~]# . /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.config

取消ServerName前面的注释

[root@localhost ~]# vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80

启动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      128       :::80                    :::*                  
LISTEN     0      128       :::22                    :::*                  
[root@localhost ~]# 

2 安装mysql

安装依赖包

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

创建用户和组

[root@localhost src]# useradd -r -M -s /sbin/nologin -u 306 mysql

下载二进制格式的mysql软件包

[root@localhost ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

解压软件至/usr/local/

[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll -d mysql*
lrwxrwxrwx. 1 root root  36 712 12:53 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 712 12:50 mysql-5.7.30-linux-glibc2.12-x86_64

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

[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql

添加环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh 
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# 

建立数据存放目录

[root@localhost ~]# mkdir mysqldata
[root@localhost ~]# chown -R mysql.mysql mysqldata/
[root@localhost ~]# ll
总用量 644556
-rw-------. 1 root  root       1607 519 12:56 anaconda-ks.cfg
-rw-r--r--. 1 root  root  660017902 712 12:47 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 mysql mysql         6 712 12:57 mysqldata
[root@localhost ~]# 

初始化数据库

[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/root/mysqldata
2020-07-30T11:07:13.585807Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-30T11:07:14.450868Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-30T11:07:14.485195Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-30T11:07:14.564024Z 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: d2e6acbd-d254-11ea-8e0a-000c29296d75.
2020-07-30T11:07:14.581412Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-30T11:07:15.179895Z 0 [Warning] CA certificate ca.pem is self signed.
2020-07-30T11:07:15.388582Z 1 [Note] A temporary password is generated for root@localhost: UslArIp7zd=C

配置mysql

[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ ->/usr/local/mysql/include/[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfi -l
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /mysqldata
socket = /tmp/mysql.sock
 port = 3306
pid-file = /mysqldata/mysql.pid
user = mysql
skip-name-resolve
[root@localhost ~]# vim /etc/my.cnf
[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/mysqldata#g' /etc/init.d/mysqld
[root@localhost ~]# vim /etc/in
init.d/  inittab  inputrc  
[root@localhost ~]# vim /etc/init.d/mysqld 
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/mysqldata/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN     0      128                      *:22                                   *:*                  
LISTEN     0      128                     :::80                                  :::*                  
LISTEN     0      128                     :::22                                  :::*                  
LISTEN     0      80                      :::3306                                :::*                  
[root@localhost ~]# 

设置数据库密码

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30 MySQL Community Server (GPL)

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('zzl123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# 

3.安装tomcat

3.1 java环境安装

[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

//查看安装的版本
[root@localhost ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

3.2 tomcat部署

下载tomcat

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz

解压部署

[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s apache-tomcat-9.0.37/ tomcat
[root@localhost local]# ll -d tomcat/
drwxr-xr-x. 9 root root 220 730 19:19 tomcat/

写一个hello world的java页面

[root@localhost ~]# vim index.jsp
[root@localhost ~]# cat index.jsp 
<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
            out.println("Hellow World");
        %>
</body>
</html>

[root@localhost ~]# mkdir /usr/local/tomcat/webapps/test
[root@localhost ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@localhost ~]# ll /usr/local/tomcat/webapps/test/
总用量 4
-rw-r--r--. 1 root root 141 730 19:23 index.jsp

启动tomcat

[root@localhost ~]# /usr/local/tomcat/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
Tomcat started.
[root@localhost ~]# ps -ef|grep tomcat
root      23611      1 36 19:27 pts/2    00:00:02 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      23748  19981  0 19:27 pts/2    00:00:00 grep --color=auto tomcat
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128        *:22                     *:*                  
LISTEN     0      100       :::8080                  :::*                  
LISTEN     0      128       :::80                    :::*                  
LISTEN     0      128       :::22                    :::*                  
LISTEN     0      1       ::ffff:127.0.0.1:8005                  :::*                  
LISTEN     0      80        :::3306                  :::*                  
[root@localhost ~]# 

在这里插入图片描述

在这里插入图片描述

配置apache

启动代理模块

[root@node1 ~]# 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

创建虚拟主机

...
<IfModule dir_module>
    DirectoryIndex index.jsp index.html
</IfModule>
...
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/"
    ServerName zzl.com
    ProxyRequests Off     
    ProxyPass /test http://127.0.0.1:8080/test/ 
    ProxyPassReverse /test http://127.0.0.1:8080/test/
    <Directory "/usr/local/apache/htdocs/">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值