部署lamt架构
lamt架构部署
准备工作
//配置yum源,推荐使用阿里云源
[root@rl ~]# rm -rf /etc/yum.repos.d/*
[root@rlf ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@rl ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@rl ~]# yum clean all
18 files removed
[root@rl ~]# yum makecache
//永久关闭防火墙和selinux
[root@wanf ~]# 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@wanf ~]# setenforce 0
[root@wanf ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
//重启主机
[root@wanf ~]# reboot
编译安装httpd
安装apr和apr-util0
//下载相关依赖包
[root@rl ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make wget vim --allowerasing
//下载apr、apr-util软件包
[root@rl ~]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz -P /usr/src/
[root@rl ~]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz -P /usr/src/
[root@wanf src]# ls
apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz debug kernels
//先编译安装apr
[root@rl src]# tar -xf apr-1.7.4.tar.gz
[root@rl src]# cd apr-1.7.4/
[root@rl apr-1.7.4]# sed -i 's/$RM "$cfgfile"/#$RM "$cfgfile"/g' configure
[root@rl apr-1.7.4]# ./configure --prefix=/usr/local/apr
[root@rl apr-1.7.4]# make -j4 && make install
//再编译安装apr-util
[root@rl apr-1.7.4]# cd ..
[root@rl src]# ls
apr-1.7.4 apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz debug kernels
[root@rl src]# tar -xf apr-util-1.6.3.tar.gz
[root@rl src]# cd apr-util-1.6.3/
[root@rl apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@rl apr-util-1.6.3]# make -j4 && make install
[root@rl apr-util-1.6.3]# cd
[root@rl ~]#
安装httpd
//创建apache用户
[root@rl ~]# groupadd -r apache
[root@rl ~]# useradd -r -M -s /sbin/nologin -g apache apache
//下载httpd软件包
[root@rl ~]# wget https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz -P /usr/src/
[root@rl ~]# cd /usr/src/
[root@rl src]# ls
apr-1.7.4 apr-util-1.6.3 debug kernels
apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz httpd-2.4.57.tar.gz
[root@rl src]# tar -xf httpd-2.4.57.tar.gz
[root@rl src]# cd httpd-2.4.57/
[root@rl httpd-2.4.57]# ./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@wanf httpd-2.4.57]# make -j4 && make install
(过程省略...)
安装后配置
//永久配置环境变量
[root@rl httpd-2.4.57]# cd
[root@rl ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@rl ~]# bash
//链接头文件
[root@rl ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
//指定man文件路径
[root@rl ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
//取消ServerName前面的注释
[root@rl ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
//配置加入systemctl管理
[root@rl ~]# vim /usr/lib/systemd/system/httpd.service
[root@rl ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=httpd server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP
[Install]
WantedBy=multi-user.target
[root@rl ~]# systemctl daemon-reload
//启动httpd服务,并设置开机自启
[root@wanf ~]# systemctl start httpd
[root@wanf ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
//80端口已经起来了
[root@rl ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
安装mariadb
//安装mariadb10.3
[root@rl ~]# yum -y install mariadb mariadb-server
//启动mariadb服务,并设置开机自启
[root@rl ~]# systemctl enable --now mariadb.service
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@rl ~]#
//设置数据库密码
[root@rl ~]# mysql
MariaDB [(none)]> set password = password('lcwanf001');
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> quit
Bye
安装Tomcat
//安装Java环境
[root@rl ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@rl ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
[root@rl ~]#
//下载tomcat软件包
[root@rl ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.79/bin/apache-tomcat-9.0.79.tar.gz -P /usr/src/
//解压部署,解压到哪个目录,该目录就是安装目录
[root@rl ~]# cd /usr/src/
[root@rl src]# ls
apache-tomcat-9.0.79.tar.gz apr-util-1.6.3 httpd-2.4.57
apr-1.7.4 apr-util-1.6.3.tar.gz httpd-2.4.57.tar.gz
apr-1.7.4.tar.gz debug kernels
[root@rl src]# tar -xf apache-tomcat-9.0.79.tar.gz -C /usr/local/
[root@rl src]# cd /usr/local/
[root@rl local]# ls
apache apr bin games lib libexec share
apache-tomcat-9.0.79 apr-util etc include lib64 sbin src
//软链接
[root@rl local]# ln -s apache-tomcat-9.0.79/ tomcat
[root@rl local]# ls
apache apr bin games lib libexec share tomcat
apache-tomcat-9.0.79 apr-util etc include lib64 sbin src
[root@rl local]#
//启动tomcat服务
[root@rl local]# /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.
//8005和8080端口已经起来了
[root@rl local]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@rl local]#
访问测试
//写一个用于测试的Java页面
[root@wanf ~]# cd /usr/local/tomcat/webapps/
[root@wanf webapps]# ls
docs examples host-manager manager ROOT
[root@wanf webapps]# mkdir test
[root@wanf webapps]# vim test/index.jsp
[root@wanf webapps]# cat test/index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("this is a test");
%>
</body>
</html>
[root@wanf webapps]#
192.168.14.130:8080/test/
访问Tomcat主页面(根目录)
IP地址加8080端口号就可以访问192.168.14.129:8080