在裸机上安装并部署Java环境、tomcat环境及Nginx负载均衡及Nginx前端项目。
首先安装要安装的是JDK,我选择的版本为jdk-8u161-linux-x64(百度云提取码:hlf5
) ,tomcat版本为apache-tomcat-8.5.57 (百度云提取码:temp
),nginx版本为nginx-1.18.0。
首先把这些安装包存放在/usr/local/目录下(举个栗子)
首先需要安装的是JDK环境。
tar -zxf /usr/local/jdk-8u161-linux-x64.tar.gz
vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_161
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
java -version
其次安装tomcat。
tar -zxf /usr/local/apache-tomcat-8.5.57.tar.gz
server.xml
vi /usr/local/apache-tomcat-8.5.57/conf/server.xml
修改第69行
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
将8080修改为想要启动的端口。
mv $war-dir/project.war /usr/local/apache-tomcat-8.5.57/webapps/
此时服务访问地址为:http://${ip}:${port}/project/
mv $war-dir/ROOT.war /usr/local/apache-tomcat-8.5.57/webapps/
此时服务访问地址为:http://${ip}:${port}/
nginx安装相对比较麻烦。从官网下载的nginx需要自己编译生成可以用的nginx。
tar -zxf /usr/local/nginx-1.18.0.tar.gz
#centos下
yum install -y gcc
#ubnutu下
apt-get install -y gcc
cd /usr/local/nginx-1.18.0/
mkdir /usr/local/nginx/
./configuration --prefix=/usr/local/nginx/
此时可能会报错:
错误1:缺少prce库
#ubnutu下
apt-get install libpcre3 libpcre3-dev -y
#centos下
yum install libpcre3 libpcre3-dev -y
错误2:缺少zlib库
#ubnutu下
apt-get install zlib1g-dev -y
#centos下
yum install zlib1g-dev -y
错误3:缺少OpenSSL库
#ubnutu下
apt-get install openssl libssl-dev -y
#centos下
yum install openssl libssl-dev -y
make
make install
最后在/usr/local/nginx/目录下为编译好的nginx。
vi /usr/local/nginx/conf/nginx.conf
在虚拟机上直接安装比使用docker安装更加麻烦一点,可以使用docker安装。
yum install -y docker
systemctl start docker
docker search tomcat
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/tomcat Apache Tomcat is an open source implementa... 2810 [OK]
docker.io docker.io/tomee Apache TomEE is an all-Apache Java EE cert... 80 [OK]
docker.io docker.io/dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 55 [OK]
docker.io docker.io/bitnami/tomcat Bitnami Tomcat Docker Image 35 [OK]
docker.io docker.io/kubeguide/tomcat-app Tomcat image for Chapter 1 29
docker.io docker.io/consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 17 [OK]
docker.io docker.io/cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
docker.io docker.io/aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 13 [OK]
docker.io docker.io/arm32v7/tomcat Apache Tomcat is an open source implementa... 10
docker.io docker.io/maluuba/tomcat7-java8 Tomcat7 with java8. 6
docker.io docker.io/rightctrl/tomcat CentOS , Oracle Java, tomcat application s... 6 [OK]
docker.io docker.io/unidata/tomcat-docker Security-hardened Tomcat Docker container. 4 [OK]
docker.io docker.io/amd64/tomcat Apache Tomcat is an open source implementa... 2
docker.io docker.io/arm64v8/tomcat Apache Tomcat is an open source implementa... 2
docker.io docker.io/jelastic/tomcat An image of the Tomcat Java application se... 2
docker.io docker.io/99taxis/tomcat7 Tomcat7 1 [OK]
docker.io docker.io/camptocamp/tomcat-logback Docker image for tomcat with logback integ... 1 [OK]
docker.io docker.io/cfje/tomcat-resource Tomcat Concourse Resource 1
docker.io docker.io/chenyufeng/tomcat-centos tomcat基于centos6的镜像 1 [OK]
docker.io docker.io/oobsri/tomcat8 Testing CI Jobs with different names. 1
docker.io docker.io/ppc64le/tomcat Apache Tomcat is an open source implementa... 1
docker.io docker.io/picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAG... 0 [OK]
docker.io docker.io/s390x/tomcat Apache Tomcat is an open source implementa... 0
docker.io docker.io/secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]
docker.io docker.io/softwareplant/tomcat Tomcat images for jira-cloud testing 0 [OK]
docker pull docker.io/tomcat
docker pull docker.io/tomcat:latest
docker pull docker.io/tomcat:{version}
docker run -idt -p 80:8080 -p 443:8443 --name service -v /root/webapps:/usr/local/tomcat/webapps --restart=always -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime
tomcat
-p
为端口映射,前面的端口为本机端口,后面的端口为容器内端口,意思为将docker
容器的端口8080
映射到本地的80
端口,将8443
端口映射到443
端口,-v
为挂载,将/root/webapps
挂载在tomcat
容器内/usr/local/tomcat/webapps/
目录,此时将文件存放到/root/webapps/目录下就相当于存放到容器内,另外一个-v /etc/localtime:/etc/localtime
主要用于解决docker
容器内时区为UCT
的问题,将本地的时区配置文件挂载到容器,保证时区显示正常。--restart=always
表示容器退出是项目总数要重启。
docker search nginx
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/nginx Official build of Nginx. 13638 [OK]
docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1864 [OK]
docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 783 [OK]
docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by Linu... 126
docker.io docker.io/bitnami/nginx Bitnami nginx Docker Image 88 [OK]
docker.io docker.io/tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rt... 88 [OK]
docker.io docker.io/jc21/nginx-proxy-manager Docker container for managing Nginx proxy ... 78
docker.io docker.io/alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from s... 72 [OK]
docker.io docker.io/nginxdemos/hello NGINX webserver that serves a simple page ... 59 [OK]
docker.io docker.io/jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 53 [OK]
docker.io docker.io/nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 40
docker.io docker.io/privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & ... 32 [OK]
docker.io docker.io/schmunk42/nginx-redirect A very simple container to redirect HTTP t... 19 [OK]
docker.io docker.io/nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 17
docker.io docker.io/nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 15
docker.io docker.io/centos/nginx-112-centos7 Platform for running nginx 1.12 or buildin... 13
docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 13
docker.io docker.io/raulr/nginx-wordpress Nginx front-end for the official wordpress... 13 [OK]
docker.io docker.io/bitwarden/nginx The Bitwarden nginx web server acting as a... 7
docker.io docker.io/mailu/nginx Mailu nginx frontend 7 [OK]
docker.io docker.io/sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats... 7 [OK]
docker.io docker.io/bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Con... 6 [OK]
docker.io docker.io/flashspys/nginx-static Super Lightweight Nginx Image 6 [OK]
docker.io docker.io/ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]
docker.io docker.io/wodby/nginx Generic nginx 1 [OK]
pull nginx镜像
docker pull docker.io/nginx:lastest
docker run --name nginx-test -p 8080:80 -itd nginx