lamt(Linux apache mysql tomcat)

Posted rmㅤ-rf *

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamt(Linux apache mysql tomcat)相关的知识,希望对你有一定的参考价值。

lamt

lamt的搭建

安装apache

安装所需要的工具等

[root@localhost ~]# dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel make expat-devel libtool
[root@localhost ~]# dnf -y groups mark install 'Development Tools'

解压

[root@localhost ~]# tar xf apr-1.7.0.tar.bz2 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2

编译安装
因为httpd依赖apr-util-1.6.1,而apr-util-1.6.1又依赖apr-1.7.0所以安装顺序为apr-1.7.0,apr-util-1.6.1,httpd-2.4.43
将apr-1.7.0下的configure中的RM "$cfgfile"删除或者注释掉

编译按装apr-1.7.0

[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install

编译安装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-1.7.0]# make && make install

检测apache的编译环境并且配置所需要的功能并安装

[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 apr-1.7.0]# make && make install

创建用户和组并设置属组和属主

[root@localhost httpd-2.4.43]# useradd -r -M -s /sbin/nologin -g apache apache
[root@localhost httpd-2.4.43]# chown -R apache.apache /usr/local/apache/

配置环境变量帮助文档和头文件

[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.config

取消ServerName的注释

[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 

写apache的.service文件

[root@localhost ~]# cat << EOF >> /etc/systemd/system/httpd.service
> Description=Start httpd
> [Service]
> Type=simple
> EnvironmentFile=/etc/httpd24/httpd.conf
> ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND
> ExecReload=/usr/local/apache/bin/httpd -k graceful
> ExecStop=/bin/kill -WINCH ${MAINPID}
> [Install]
> WantedBy=multi-user.target
> EOF

启动apache

[root@localhost system]# systemctl start httpd

安装mysql

安装依赖包

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

创建用户

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

解压

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

修改目录名

[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql

修改属主和属组

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

设置环境变量

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

创建存放数据的目录并修改属主属组

[root@localhost mysql]# mkdir /opt/mysql_data
[root@localhost mysql]# chown -R mysql.mysql /opt/mysql_data/
[root@localhost mysql]# ll /opt
drwxr-xr-x. 2 mysql mysql 6 五月    4 20:58 mysql_data

初始化并保存密码

[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/mysql_data/		//初始化	控制mysql的用户		数据存放目录
2021-05-04T13:01:07.403961Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-04T13:01:07.683107Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-04T13:01:07.739366Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-04T13:01:07.746720Z 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: caa21b8a-acd8-11eb-b7ab-000c294bb269.
2021-05-04T13:01:07.747895Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-04T13:01:09.096727Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-04T13:01:09.485357Z 1 [Note] A temporary password is generated for root@localhost: q_UG8?3sa/l%

写配置文件

[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
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/mysql_data#g' /etc/init.d/mysqld
[root@localhost mysql]# service mysqld start
[root@localhost mysql]# chkconfig  mysqld on      

头文件和库文件配置

[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql						
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost mysql]# ldconfig	

安装tomcat

安装jdk

[root@localhost tomcat]# dnf -y install java-11-openjdk java-11-openjdk-devel
[root@localhost tomcat]# 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.46.tar.gz 
[root@localhost ~]# mv apache-tomcat-9.0.46 /usr/local/tomcat

启动tomcat

[root@localhost 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
Using CATALINA_OPTS:   
Tomcat started.

配置apache

将下面四行取消注释

[root@wnz ~]# 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
Include /etc/httpd24/extra/httpd-vhosts.conf

配置虚拟主机

[root@localhost httpd-2.4.43]# vim /etc/httpd24/extra/httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ProxyPass / http://192.168.247.100:8080/
    ProxyPassReverse / http://192.168.247.100:8080/
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

重启apache

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

在这里插入图片描述

以上是关于lamt(Linux apache mysql tomcat)的主要内容,如果未能解决你的问题,请参考以下文章

lamt部署

Linux 基于LAMT反向代理测试

lamt部署和Jenkins

web应用构架LAMT及tomcat负载简析

Tomcat相关的LNMT和LAMT

OneinStack一键PHP/JAVA安装工具