ubuntu jdk tomcat mysql_Ubuntu 下 JDK+Tomcat+MySql 环境的搭建

3.    安装 MySql

3.1    安装

使用 apt-get install 方式安装,终端输入:

sudo apt-get install mysql-server-5.1

(

小提示:

搜索软件: apt-cache search 软件名关键字,支持模糊查询,

譬如: apt-cache search mysql

)

安装过程中,有两次提示输入 mysql 的 root 账号的密码,这里输入 root ,确定,直至安装完成。

3.2    创建用户

Mysql 安装完之后,已自动启动,且默认就开机自启动了。

终端输入:

mysql –uroot –proot

进入 mysql 的控制台。创建一个用户(用户名为: test ,密码为: 123456 ),并授权,以便远程访问 mysql (如果需要的话):

grant all privileges on *.* to test@"%" identified by "123456" with grant option;

CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

输入 :

exit

退出 mysql

终端输入 :

mysql –utest –p123456

测试刚才创建的账号是否能正常登录 mysql

3.3    修改mysql文件

终端输入:

sudo vi /etc/mysql/my.cnf

打开 /etc/mysql/my.cnf 文件,找到如下行:

bind-address             = 127.0.0.1

注释掉这一行,否则 MySql 远程可能还是无法访问。

保存并退出。

出现错误提示:SQL Error (2013): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0.

在my.ini或者my.cnf中

[mysqld]项中,添加skip-name-resolve

4.    安装 JDK

sudo add-apt-repository ppa:webupd8team/java

apt-get ..

5.    安装 Tomcat

直接 apt-get ,

修改sudo vim /etc/init.d/tomcat7

在JDK_DIRS变量最后加入 /usr/lib/jvm/java-8-oracle

重启服务

6.  启用80端口

Enable authbind

Open a text editor like vim and load the default tomcat configuration file

nano /etc/default/tomcat7

Remove the comment hash "#" in front of the authbind property and set the value to "yes"

AUTHBIND=yes

Create authbind bind permission files for ports 80 and 443. Authbind will loop through the directory structure and try to find a byPort file referencing the port number attempting to be bound. Authorization will be granted if the user attempting to bind has execute permission.

touch /etc/authbind/byport/80

touch /etc/authbind/byport/443

chmod 0755 /etc/authbind/byport/80

chmod 0755 /etc/authbind/byport/443

chown tomcat7:tomcat7 /etc/authbind/byport/80

chown tomcat7:tomcat7 /etc/authbind/byport/443

Change the Tomcat Port from 8080/8443 to 80/443

Open a text editor like vim and load the server configuration file

Find the connector for port 8080 to port 80 and the redirect port from 8443 to 443:

C代码

connectiontimeout="20000" uriencoding="UTF-8"

redirectport="443">

Restart the Tomcat service

sudo service tomcat7 restart

View the catalina.out log after restart and look for any errors. If you see permission denied errors, then you may have missed a step like:

Forgetting to uncomment the AuthBind setting and putting it to "yes"

Forgetting to restart the tomcat7 service as sudo

最后运行netstat -ant,查看80端口是否起来 。

二、应用部署

tomcat配置成功后需要将开发的应用部署到tomcat服务器中。步骤如下:

1、将应用打包为ROOT.war

2、在/usr/share/tomcat7中创建logs目录

cd /usr/share/tomcat7

sudo mkdir logs

sudo chmod 755 logs

3、创建ROOT.xml文件内容如下:

debug="0" privileged="true">

WEB-INF/web.xml

其中 docBase="/usr/share/tomcat7/ROOT.war"指向应用部署所在文件地址。

4、 重启tomcat

sudo service tomcat7 restart

提示信息如下:

* Stopping Tomcat servlet engine tomcat7

...done.

* Starting Tomcat servlet engine tomcat7

...done.

5、启动完毕后登陆应用地址查看。如还不成功请则将ROOT.xml文件拷贝到如下目录中,重复tomcat即可。

/var/lib/tomcat7/conf/Catalina/localhost

7.  修改默认目录

修改默认目录,在tomcat的server.xml中在

unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

中间加上

我的项目都是放在/var/lib/tomcat7/webapps/下面的,项目名是Menu,所以只需要把项目的地址放在docBase中就OK了

8.  启用 HTTPS 访问

这个简单教程中我们通过简单的两步就可以在 Tomcat 7 中启用 HTTPS 访问。

第一步:创建 .keystore 文件

使用如下命令生成 .keystore 文件

windows :

Linux:

第二步:在 server.xml 中启用 SSL HTTP/1.1 连接器(已有配置,去除注释即可),端口 8443

修改 $CATALINA_HOME/conf/server.xml 文件:

"keystorePass" 是生成 .keystore 文件的密码,然后重启 Tomcat

打开浏览器访问如下地址:https://localhost

如果看到了 Tomcat 的首页就搞定了。

使用keytool为Tomcat生成证书,假定目标机器的域名是“localhost”,keystore文件存放在“D:\home\tomcat.keystore”,口令为“password”,使用如下命令生成:

keytool -genkey -v -alias tomcat -keyalg RSA -keystore D:\home\tomcat.keystore -validity 36500 (参数简要说明:“D:\home\tomcat.keystore”含义是将证书文件的保存路径,证书文件名称是tomcat.keystore ;“-validity 36500”含义是证书有效期,36500表示100年,默认值是90天 “tomcat”为自定义证书名称)。

在命令行填写必要参数:

A、 输入keystore密码:此处需要输入大于6个字符的字符串。

B、 “您的名字与姓氏是什么?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:gbcom.com 或者 10.1.25.251](就是你将来要在浏览器中输入的访问地址),否则浏览器会弹出警告窗口,提示用户证书与所在域不匹配。在本地做开发测试时,应填入“localhost”。

C、 你的组织单位名称是什么?”、“您的组织名称是什么?”、“您所在城市或区域名称是什么?”、“您所在的州或者省份名称是什么?”、“该单位的两字母国家代码是什么?”可以按照需要填写也可以不填写直接回车,在系统询问“正确吗?”时,对照输入信息,如果符合要求则使用键盘输入字母“y”,否则输入“n”重新填写上面的信息。

D、 输入的主密码,这项较为重要,会在tomcat配置文件中使用,建议输入与keystore的密码一致,设置其它密码也可以,完成上述输入后,直接回车则在你在第二步中定义的位置找到生成的文件。

2.强制https访问

在tomcat\conf\web.xml中的后面加上这样一段:

CLIENT-CERT

ClientCertUsers-onlyArea

SSL

/*

CONFIDENTIAL

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值