• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

jdk+tomcat8+nginx+mysql学习

mysql技术 Airsupport 68次浏览 已收录 0个评论

最小化安装系统后先更新

[root@Server ~]# yum update -y

[root@Server ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

[root@Server ~]# uname -r
3.10.0-957.21.3.el7.x86_64

关闭防火墙
systemctl stop firewalld.service

关闭防火墙开机启动
systemctl disable firewalld.service

关闭SELINUX (重启生效)
sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config


一、安装jdk
下载jkd
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

jdk-8u251-linux-x64.rpm

安装
rpm -ivh jdk-8u251-linux-x64.rpm

验证
[root@localhost ~]# java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

二、安装tomcat8
下载tomcat
https://tomcat.apache.org/

apache-tomcat-8.5.55.tar.gz

解压
tar -zxvf apache-tomcat-8.5.55.tar.gz

移至 root/apps下
mkdir -p /root/apps
mv apache-tomcat-8.5.55 /root/apps

运行tomcat
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE: /root/apps/tomcat8
Using CATALINA_HOME: /root/apps/tomcat8
Using CATALINA_TMPDIR: /root/apps/tomcat8/temp
Using JRE_HOME: /usr
Using CLASSPATH: /root/apps/tomcat8/bin/bootstrap.jar:/root/apps/tomcat8/bin/tomcat-juli.jar
Tomcat started.

验证
浏览器访问
http://IP:8080

网页正常显示即可

修改tomcat端口
停止tomcat服务
./shutdown.sh
备份原配置文件
cp /tomcat8/conf/server.xml /tomcat8/conf/server.xml.bak
编辑配置文件
vi /tomcat8/conf/server.xml

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

将默认8080 改为80

三、安装nginx
方法1:
增加nginx
#vi /etc/yum.repos.d/nginx.repo

源的内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

查看源是否配置成功
yum list nginx
yum list |grep nginx

更新源
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装nginx
yum install -y nginx

启动nginx
systemctl start nginx

加入开机自启
systemctl enable nginx.service

方法2:
下载
http://nginx.org/en/download.html

http://nginx.org/download/nginx-1.18.0.tar.gz

解压
tar -zxvf nginx-1.18.0.tar.gz

移至root/apps 并改名
mv nginx-1.18.0 nginx

安装依赖
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl–devel pcre pcre-devel

编译安装
./configure

make&make install

验证:
[root@localhost nginx]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

修改配置文件做反向代理
vi /etc/nginx/conf.d/default.conf

server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
    proxy_pass http://127.0.0.1:8080;
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

加一句
proxy_pass http://127.0.0.1:8080; 如上

上面这句话的意思就是,把所有到80nginx服务器的请求全部丢给本地8080来出来,8080端口正是我们的tomcat服务器。这样nginx就把访问交给tomcat来做了。

四、安装mysql
编辑repo
vi /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装
yum install -y MariaDB-server MariaDB-client

启动服务
systemctl start mariadb
开机自启
systemctl enable mariadb
配置向导
mysql_secure_installation
Enter current password for root (enter for none):<–初次运行直接回车
Switch to unix_socket authentication [Y/n]
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车, 建议 N
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

查看版本 10.4.6
[root@localhost ~]# mysql -V
mysql Ver 15.1 Distrib 10.4.13-MariaDB, for Linux (x86_64) using readline 5.1

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

测试登录
mysql -u root -p

修改允许远程登录数据库
use mysql
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
FLUSH PRIVILEGES;

五、Tomcat的数据目录(网站家目录)

如 /root/apps/tomcat8/webapps

测试
mkdir -p /root/apps/tomcat8/webapps/test

vi index.jsp
hello world

浏览器访问
http://ip/test/index.jsp


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明jdk+tomcat8+nginx+mysql学习
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址