我是靠谱客的博主 义气路灯,最近开发中收集的这篇文章主要介绍手动部署LAMT1. 安装httpd2. 安装mysql3. 安装tomcat4. 配置apache,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
文章目录
- 1. 安装httpd
- 2. 安装mysql
- 3. 安装tomcat
- 3.1 java环境部署
- 3.2 tomcat部署
- 4. 配置apache
环境说明:
系统 | 主机名 | IP | 需要安装的服务 |
---|---|---|---|
CentOS8 | Tomcat | 192.168.50.153 | tomcat |
CentOS | httpd | 192.168.50.154 | httpd |
RedHat8 | mysql | 192.168.50.135 | mysql |
1. 安装httpd
- 配置阿里云网络源和epel源
[root@httpd yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@httpd yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@httpd yum.repos.d]# sed -i 's/$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo
[root@httpd yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@httpd yum.repos.d]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@httpd yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@httpd yum.repos.d]# yum makecache
- 安装开发工具包
[root@httpd ~]# yum groups mark -y install 'Development Tools'
- 创建apache服务的用户和组
[root@httpd ~]# useradd -r -M -s /sbin/nologin apache
[root@httpd ~]# id apache
uid=994(apache) gid=991(apache) groups=991(apache)
- 安装依赖包
[root@httpd ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
- 下载和安装apr以及apr-util
[root@httpd ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.gz
apr-1.6.5.tar.gz httpd-2.4.46.tar.bz2
[root@httpd ~]# yum -y install lbzip2
[root@httpd ~]# tar xf httpd-2.4.46.tar.bz2 -C /usr/src/
[root@httpd ~]# tar xf apr-1.6.5.tar.gz -C /usr/src/
[root@httpd ~]# tar xf apr-util-1.6.1.tar.gz -C /usr/src/
[root@httpd ~]# ls /usr/src/
apr-1.6.5 apr-util-1.6.1 debug httpd-2.4.46 kernels
[root@httpd ~]# cd /usr/src/
[root@httpd src]# ls
apr-1.6.5 apr-util-1.6.1 debug httpd-2.4.46 kernels
[root@httpd src]# cd apr-1.6.5/
[root@httpd apr-1.6.5]# vim configure
trap "$RM "$cfgfile"; exit 1" 1 2 15
# $RM "$cfgfile" 将其注释
[root@httpd apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@httpd apr-1.6.5]# make && make install
[root@httpd apr-1.6.5]# cd ..
[root@httpd src]# cd apr-util-1.6.1/
[root@httpd apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@httpd apr-util-1.6.1]# make && make install
[root@httpd apr-util-1.6.1]# cd ..
[root@httpd src]# cd httpd-2.4.46/
[root@httpd httpd-2.4.46]# ./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@httpd httpd-2.4.46]# make && make install
- 设置环境变量和软连接
[root@httpd ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@httpd ~]# source /etc/profile.d/httpd.sh
[root@httpd ~]# echo $PATH
/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@httpd ~]# ln -s /usr/local/include/ /usr/include/apache
#取消ServerName前面的注释
[root@httpd ~]# vim /etc/httpd24/httpd.conf
ServerName www.example.com:80
- 启动服务
[root@httpd ~]# apachectl start
[root@httpd ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
- 关闭防火墙
[root@httpd ~]# systemctl stop firewalld
- 访问网页
2. 安装mysql
- 安装依赖包
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
- 创建一个系统用户
[root@mysql ~]# useradd -r -M -s /sbin/nologin mysql
[root@mysql ~]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)
- 下载压缩包并解压
[root@mysql ~]# ls
anaconda-ks.cfg
mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@mysql ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
- 做软连接
[root@mysql ~]# cd /usr/local/
[root@mysql local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
- 修改目录/usr/local/mysql的属主属组
[root@mysql local]# chown -R mysql.mysql mysql*
- 添加环境变量
[root@mysql local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql local]# source /etc/profile.d/mysql.sh
[root@mysql local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
- 建立数据存放目录
[root@mysql ~]# mkdir /opt/data
[root@mysql ~]# chown -R mysql.mysql /opt/data
- 初始化数据库
[root@mysql ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2020-11-26T12:59:49.147041Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-26T12:59:49.339169Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-26T12:59:49.361587Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-26T12:59:49.415615Z 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: 44437b2a-2fe7-11eb-9d86-000c2959b333.
2020-11-26T12:59:49.416282Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-26T12:59:50.651546Z 0 [Warning] CA certificate ca.pem is self signed.
2020-11-26T12:59:50.771547Z 1 [Note] A temporary password is generated for root@localhost: ?lgG._YKx0Gp
[root@mysql ~]# echo ' ?lgG._YKx0Gp' > passwd
- 配置mysql头文件和lib库
[root@mysql ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@mysql ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@mysql ~]# ldconfig
- 生成配置文件
[root@mysql ~]# 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@mysql ~]#
- 配置服务启动脚本
[root@mysql ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(basedir=).*#1/usr/local/mysql#g' /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(datadir=).*#1/opt/data#g' /etc/init.d/mysqld
[root@mysql ~]#
- 设置开机自启
[root@mysql ~]# chkconfig --add mysqld
[root@mysql ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@mysql ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN0 128 0.0.0.0:22 0.0.0.0:*
LISTEN0 128 [::]:22 [::]:*
LISTEN0 80 *:3306 *:*
[root@mysql ~]#
- 修改密码
#先安装一个包,为了解决登录数据库报的错
[root@mysql ~]# yum -y install ncurses-compat-libs
[root@mysql ~]# mysql -uroot -p'tIhAr%Ds5)Xu'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.31
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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
3. 安装tomcat
3.1 java环境部署
- 安装jdk环境
[root@Tomcat yum.repos.d]# yum -y install java-1.8.0-openjdk*
- 查看安装的版本
[root@Tomcat yum.repos.d]# java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
3.2 tomcat部署
- 上官网下载tomcat
[root@tomcat ~]# wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M10/bin/apache-tomcat-10.0.0-M10.tar.gz
- 解压安装包
[root@tomcat ~]# ls
anaconda-ks.cfg apache-tomcat-10.0.0-M10.tar.gz
[root@tomcat ~]# tar xf apache-tomcat-10.0.0-M10.tar.gz -C /usr/local/
[root@tomcat ~]# ls /usr/local/
apache-tomcat-10.0.0-M10 bin etc games include lib lib64 libexec sbin share src
[root@tomcat ~]#
- 做软连接
[root@tomcat local]# ln -s apache-tomcat-10.0.0-M10/ tomcat
- 主程序脚本文件
[root@Tomcat local]# cd /usr/local/tomcat/
[root@Tomcat tomcat]#
[root@Tomcat tomcat]# cd webapps/
[root@Tomcat webapps]# mkdir test
[root@Tomcat webapps]# cd test/
[root@Tomcat test]# vim index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("Hellow World");
%>
</body>
</html>
- 启动tomcat
[root@tomcat ~]# /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
Using CATALINA_OPTS:
Tomcat started.
[root@tomcat ~]# ps -ef | grep tomcat
root 23341 1 16 15:24 pts/1 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/tomca/temp org.apache.catalina.startup.Bootstrap start
root 23370 14066 0 15:25 pts/1 00:00:00 grep --color=auto tomcat
[root@tomcat ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 *:*
[root@tomcat ~]#
- 在web页面验证
4. 配置apache
- 启用代理模块
[root@httpd ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@httpd ~]# sed -i '/proxy_http_module/s/#//g' /etc/httpd24/httpd.conf
- 配置虚拟机
[root@httpd ~]# vim /etc/httpd24/httpd.conf
# Virtual hosts
Include /etc/httpd24/extra/httpd-vhosts.conf #取消注释,启动虚拟主机文件
[root@httpd ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs"
ServerName www.example.com
ErrorLog "logs/www.example.com-error_log"
CustomLog "logs/www.example.com-access_log" common
ProxyRequests Off
ProxyPass / http://192.168.50.153:8080/
ProxyPassReverse / http://192.168.50.153:8080/
<Directory "/usr/local/apache/htdocs">
Require all granted
</Directory>
</VirtualHost>
- 重启服务
[root@httpd ~]# apachectl restart
[root@httpd ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN0 128 0.0.0.0:80 0.0.0.0:*
LISTEN0 128 0.0.0.0:22 0.0.0.0:*
LISTEN0 128 [::]:22 [::]:*
[root@httpd ~]#
- 访问网页
最后
以上就是义气路灯为你收集整理的手动部署LAMT1. 安装httpd2. 安装mysql3. 安装tomcat4. 配置apache的全部内容,希望文章能够帮你解决手动部署LAMT1. 安装httpd2. 安装mysql3. 安装tomcat4. 配置apache所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复