概述
nginx快速安装
root@ubuntu:~# apt-get install nginx
查看版本
root@ubuntu:~# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
启动程序
root@ubuntu:~# service nginx start
root@ubuntu:~# service nginx status
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-10-25 06:13:27 UTC; 4min 28s ago
Docs: man:nginx(8)
Main PID: 2460 (nginx)
Tasks: 3 (limit: 2244)
Memory: 6.0M
CGroup: /system.slice/nginx.service
├─2460 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─2461 nginx: worker process
└─2462 nginx: worker process
Oct 25 06:13:27 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 25 06:13:27 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.
nginx文件安装完成之后的文件位置:
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志
卸载apt-get安装的nginx
apt-get --purge autoremove nginx
防火墙放开
root@ubuntu:/etc/nginx/conf.d# ufw allow 'Nginx Full'
Rule added
Rule added (v6)
查看状态
root@ubuntu:/etc/nginx/conf.d# ufw status
Status: active
To
Action
From
--
------
----
22/tcp
ALLOW
Anywhere
Nginx Full
ALLOW
Anywhere
22/tcp (v6)
ALLOW
Anywhere (v6)
Nginx Full (v6)
ALLOW
Anywhere (v6)
java安装
创建目录
root@ubuntu:~# mkdir /usr/local/java
root@ubuntu:~# cd /usr/local/java/
自行从官方或镜像站下载JDK安装包
解压安装包
root@ubuntu:/usr/local/java# tar xzvf jdk-8u151-linux-x64.tar.gz
root@ubuntu:/usr/local/java/jdk1.8.0_151# pwd
/usr/local/java/jdk1.8.0_151
配置环境变量并刷新
root@ubuntu:/usr/local/java/jdk1.8.0_151# vi /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_151
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
root@ubuntu:/usr/local/java/jdk1.8.0_151# . /etc/profile
查看版本
root@ubuntu:~# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
tomcat安装
添加一个不能登录的用户
useradd -mUd
/opt/tomcat -s /bin/false tomcat
新建目录并下载文件
root@ubuntu:~# mkdir /opt/tomcat
root@ubuntu:~# wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.83/bin/apache-tomcat-8.5.83.tar.gz
解压到 /opt/并重命名为tomcat目录
root@ubuntu:~# tar xzvf apache-tomcat-8.5.83.tar.gz -C /opt/tomcat/
为了能运行tomcat,先前创建的系统用户必须有权访问tomcat安装目录。 将目录所有权更改为用户和组tomcat:
chown -R tomcat:tomcat /opt/tomcat
确定tomcat的安装目录下/bin目录中的脚本都具备执行权限,可以通过以下命令修改执行权限。
(chmod -R 755 /opt/tomcat/)
sudo sh -c `chmod +x /opt/tomcat/bin/*.sh`
与其手动启动和停止Tomcat服务器,不如将其设置为作为服务运行。 打开文本编辑器,然后在/etc/systemd/system/目录中创建tomcat.service单元文件:
vi /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_151"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Tomcat基础命令
systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat
systemctl status tomcat
注:nginx放开80端口,反向代理Tomcat8080无需放开
最后
以上就是怕孤单金针菇为你收集整理的Ubuntu(一)安装 Java Tomcat NGINX的全部内容,希望文章能够帮你解决Ubuntu(一)安装 Java Tomcat NGINX所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复