腾讯云centos7搭建javaweb服务器(亲测成功)
VIEW CONTENTS

腾讯云centos7搭建javaweb服务器(亲测成功)

2019-2-13 00:00| 发布者: xtyly| 查看: 388| 评论: 0|来自: 网络

原文地址;http://www.2cto.com/kf/201707/654874.html

若干秒之后,重装完毕,即可开始搭建环境!

去官网下载jdk和tomcat的压缩包

我下载的是tar包,Linux x64 jdk-8u131-linux-x64.tar.gz

tomcat

我下载的是apache-tomcat-8.5.16.tar.gz

恩,下载好之后,

用户可以使用putty,mac用户可以使用ssh连接到服务器

使用root用户输入密码之后即可登录服务器

依次执行:

[[email protected]_77_172_centos usr]# cd /usr

[[email protected]_77_172_centos usr]# mkdir java

本人使用的是filezilla软件分别将下载好的jdk和Tomcat包上传到服务器中的/usr/java目录下和/usr目录下。(注意)

先安装java:

[[email protected]_77_172_centos usr]# cd java

[[email protected]_77_172_centos java]# tar -xvzfjdk-8u131-linux-x64.tar.gz

[[email protected]_77_172_centos java]# ls

jdk1.8.0_131 jdk-8u131-linux-x64.tar.gz

[[email protected]_77_172_centos java]# vim /etc/profile

单击i可进行插入,在文末插入如下三行语句:

export JAVA_HOME=/usr/java/jdk1.8.0_131

export JRE_HOME=/$JAVA_HOME/jre

export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

单击esc之后输入:x保存并退出

[[email protected]_77_172_centos java]# source /etc/profile

此时,java安装完毕,可输入java -version查看:

[[email protected]_77_172_centos java]# java -version

java version "1.8.0_131"

Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

下面开始Tomcat安装:

[[email protected]_77_172_centos java]# cd ..

(注意,之前已经将tomcat包上传到/usr目录下)

[[email protected]_77_172_centos usr]# tar -xvzfapache-tomcat-8.5.16.tar.gz

[[email protected]_77_172_centos usr]# rm -rapache-tomcat-8.5.16.tar.gz

rm: remove regular file ’apache-tomcat-8.5.16.tar.gz'? y

[[email protected]_77_172_centos usr]#mvapache-tomcat-8.5.16 tomcat

[[email protected]_77_172_centos usr]# ls

bin games java lib64 local share tmp

etc include lib libexec sbin src tomcat

[[email protected]_77_172_centos tomcat]# /usr/tomcat/bin/startup.sh

Using CATALINA_BASE: /usr/tomcat

Using CATALINA_HOME: /usr/tomcat

Using CATALINA_TMPDIR: /usr/tomcat/temp

Using JRE_HOME: //usr/java/jdk1.8.0_131/jre

Using CLASSPATH: /usr/tomcat/bin/bootstrap.jar:/usr/tomcat/bin/tomcat-juli.jar

Tomcat started.

此时,tomcat安装完毕,接下来打开端口:

[[email protected]_77_172_centos tomcat]# systemctl stop firewalld.service

[[email protected]_77_172_centos tomcat]# systemctl disable firewalld.service

[[email protected]_77_172_centos tomcat]# systemctl mask firewalld.service

Created symlink from /etc/systemd/system/firewalld.service to /dev/null.

[[email protected]_77_172_centos tomcat]# cd ~

[[email protected]_77_172_centos ~]# yum install iptables-services -y

[[email protected]_77_172_centos ~]# systemctl enable iptables

Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.

[[email protected]_77_172_centos ~]# systemctl start iptables

[[email protected]_77_172_centos ~]# systemctl status iptables

[[email protected]_77_172_centos usr]# systemctl unmask firewalld

Removed symlink /etc/systemd/system/firewalld.service.

[[email protected]_77_172_centos usr]# systemctl start firewalld

[[email protected]_77_172_centos usr]# firewall-cmd --zone=public --add-port=8080/tcp --permanent

success

[[email protected]_77_172_centos usr]# firewall-cmd --zone=public --add-port=80/tcp --permanent

success

[[email protected]_77_172_centos usr]# firewall-cmd --zone=public --add-port=22/tcp --permanent

success

[[email protected]_77_172_centos usr]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[[email protected]_77_172_centos usr]# firewall-cmd --reload

success

至此,不出意外的话,就可以外网访问服务器ip:8080看到Tomcat初始界面了!

接下来,安装mysql:

[[email protected]_77_172_centos usr]# cd ~

[[email protected]_77_172_centos ~]# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

[[email protected]_77_172_centos ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm

[[email protected]_77_172_centos ~]# yum install mysql-server

中间输入若干次y

[[email protected]_77_172_centos ~]# yum install mysql-devel

中间输入若干次y

[[email protected]_77_172_centos ~]# yum install mysql

检查一下MySQL:

[[email protected]_77_172_centos ~]# rpm -qa|grep -i mysql

mysql-community-libs-5.7.18-1.el7.x86_64

mysql-community-libs-compat-5.7.18-1.el7.x86_64

mysql57-community-release-el7-7.noarch

mysql-community-common-5.7.18-1.el7.x86_64

mysql-community-client-5.7.18-1.el7.x86_64

mysql-community-server-5.7.18-1.el7.x86_64

mysql-community-devel-5.7.18-1.el7.x86_64

[[email protected]_77_172_centos ~]# service mysqld start

Redirecting to /bin/systemctl start mysqld.service

[[email protected]_77_172_centos ~]# vim /etc/my.cnf

添加一条语句:skip-grant-tables

保存退出

[[email protected]_77_172_centos ~]# service mysqld restart

Redirecting to /bin/systemctl restart mysqld.service

[[email protected]_77_172_centos ~]# mysql -u root

即可进入mysql

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update mysql.user set authentication_string=password('123456') where user='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

Bye

[[email protected]_77_172_centos ~]# vim /etc/my.cnf

删除掉刚才添加的那条语句,保存退出。

[[email protected]_77_172_centos ~]# service mysqld restart

Redirecting to /bin/systemctl restart mysqld.service

[[email protected]_77_172_centos ~]# mysql -uroot -p

输入密码登录MySQL

mysql> set global validate_password_policy=0;

Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6;

Query OK, 0 rows affected (0.00 sec)

mysql> set PASSWORD = PASSWORD('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set host='%' where user='root' and host='localhost';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit

Bye

至此,MySQL也安装完毕!

享受没有配置错误的流程吧!


  • 域名:
  • 有一个服务器已经部署好项目
  • 已做域名解析
  • 使用IP:8080/项目名称 能够访问项目

    • 进入tomcat文件夹

    cd 到你的tomcat下

  • 修改server.xml文件中监听端口

  • 修改前是这样的:

cd conf
vim server.xml

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />修改后是这样的:
<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

*也就是说将监听端口,修改为默认的80端口。*
  • 继续修改server.xml中Host
找到
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
修改为:
<Host name="你的域名"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
以及在该<Host>...</Host>标签内添加<Context />标签
<Context path="" docBase="/myApp" />
docBase属性填写你的项目位置,最好是绝对路径即...../webapps/myApp。
  • 重启tomcat

进入bin 
./shutdown.sh

./startup.sh

  • 打开浏览器

输入域名



鲜花

握手

雷人

路过

鸡蛋
腾讯云服务器优惠

相关阅读

最新评论




在线客服(工作时间:9:00-22:00)
400-600-6565

内容导航

zuntop公众号

Copyright   ©2015-2019  云服务器社区  Powered by©Discuz!  技术支持:尊托网络     ( 湘ICP备15009499号-1 )