我是靠谱客的博主 成就书本,最近开发中收集的这篇文章主要介绍lamt环境搭建lamt环境搭建,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

lamt环境搭建

文章目录

  • lamt环境搭建
    • 1. 安装httpd
    • 2. 安装mysql
    • 3. 安装tomcat
      • 3.1 java环境安装
      • 3.2 tomcat部署
    • 4. 配置apache
      • 4.1 启用代理模块
      • 4.2 配置虚拟主机

实验环境:

环境ip需要安装的服务
centos7192.168.139.128tomcat,mysql
centos7192.168.139.129httpd

1. 安装httpd

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

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

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

//下载和安装apr以及apr-util
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost src]# tar xf apr-1.7.0.tar.gz
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz
[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"        //将此行加上注释,或者删除此行
    
//安装apr
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install

//安装apr-util
[root@localhost apr-1.7.0]# 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 apr-util-1.6.1]# cd ..
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@localhost src]# tar xf httpd-2.4.43.tar.gz
[root@localhost src]# 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 httpd-2.4.43]# cd /usr/local/apache/
[root@localhost apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost apache]# source /etc/profile.d/httpd.sh
[root@localhost apache]# ln -s /usr/local/apache/include /usr/include/httpd
[root@localhost apache]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man    //添加此行
[root@localhost apache]# cd /etc/httpd24/
[root@localhost httpd24]# vim httpd.conf
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80    //取消此行注释

//启动apache
[root@localhost httpd24]# apachectl start
[root@localhost httpd24]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100     [::1]:25                   [::]:*                  
LISTEN     0      128      [::]:80                   [::]:*                  
LISTEN     0      128      [::]:22                   [::]:*

在浏览器上访问网页,看到下图说明配置成功
在这里插入图片描述

2. 安装mysql

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin -u 306 mysql

//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

//解压软件至/usr/local/
[root@localhost src]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql

//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll -d mysql
lrwxrwxrwx 1 mysql mysql 36 Aug  4 11:49 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/

//添加环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh

//配置mysql
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/local/include/mysql
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man    //添加此行

[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig

//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Aug  4 11:50 data

//初始化数据库
[root@localhost ~]# mysqld --initialize-insecure --user=mysql --datadir=/opt/data

//生成配置文件
[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 ~]# cp /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

//启动mysql
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.err'.
 SUCCESS!
 
//修改密码
[root@localhost ~]# mysql -uroot -e "set password = password('12321');"

3. 安装tomcat

3.1 java环境安装

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

//查看安装的版本
[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 https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz

//解压部署
[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz -C /usr/local
[root@localhost ~]# ln -s /usr/local/apache-tomcat-9.0.37/ /usr/local/tomcat

//添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh
[root@localhost ~]# chmod +x /etc/profile.d/tomcat.sh
[root@localhost ~]# source /etc/profile.d/tomcat.sh

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

在浏览器上访问,看到下图表示安装成功
在这里插入图片描述

4. 配置apache

4.1 启用代理模块

//启用httpd的相关模块
[root@localhost ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@localhost ~]# sed -i '/proxy_http_module/s/#//g' /etc/httpd24/httpd.conf

4.2 配置虚拟主机

//配置虚拟主机(在ip为129的主机上配)
[root@localhost ~]# vim /etc/httpd24/httpd.conf
//在最后添加以下内容
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ProxyRequests Off
    ProxyPass / http://192.168.139.128:8080/
    ProxyPassReverse / http://192.168.139.128:8080/
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//重启服务
[root@localhost ~]# apachectl restart

在浏览器访问192.168.139.129会跳转到tomcat主页
在这里插入图片描述
到此为止表明lamt架构部署成功!

最后

以上就是成就书本为你收集整理的lamt环境搭建lamt环境搭建的全部内容,希望文章能够帮你解决lamt环境搭建lamt环境搭建所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(30)

评论列表共有 0 条评论

立即
投稿
返回
顶部