笔记整理-yum安装jdk-tomcat安装测试记录
yum安装jdk
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel ls /usr/lib/jvm/ java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 ln -sv /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 /usr/lib/jvm/jdk1.8 #不要用超连接的形式配置jdk会报错
因为软链接不是目录
[root@localhost native]# vi /etc/profile.d/jdk8.sh #配置java家环境tomcat使用
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile.d/jdk8.sh
java -version
echo $JAVA_HOME
which java
下载版本会变先网页查看 https://mirrors.cnnic.cn/apache/tomcat/
wget https://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.5.39/bin/apache-tomcat-8.5.39.tar.gz
tar xvf apache-tomcat-8.5.39.tar.gz -C /usr/local/src/ #几项根据版本号修改命令 cd /usr/local/src/apache-tomcat-8.5.39/ cd .. ; mv apache-tomcat-8.5.39/ /usr/local/tomcat ; cd
vi /etc/init.d/tomcat
#!/bin/bash
#
# tomcat startup script for the Tomcat server
#
# chkconfig: 345 80 20
# description: start the tomcat deamon
#
# Source function library
. /etc/rc.d/init.d/functions
prog=tomcat
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64
export JAVA_HOME
CATALANA_HOME=/usr/local/tomcat
export CATALINA_HOME
case "$1" in
start)
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
stop)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
;;
restart)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
sleep 2
echo
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
esac
exit 0
启动测试
/usr/local/tomcat/bin/startup.sh chmod +x /etc/init.d/tomcat service tomcat restart chkconfig --add tomcat chkconfig tomcat on chkconfig --list netstat -antup | grep 8080
http://192.168.1.63:8080/
tomcat-native 安装
yum -y install apr-devel gcc gcc-c++ openssl-devel openssl cd /usr/local/tomcat/bin/ tar xf tomcat-native.tar.gz -C /usr/local/src/ cd /usr/local/src/tomcat-native-1.2.21-src/native/ #根据版本修改路径
[root@localhost ~]# echo $JAVA_HOME
/usr/lib/jvm/jdk1.8
./configure --with-apr=/usr/ --with-java-home=/usr/lib/jvm/jdk1.8 --with-ssl make && make install#如果报错可以安装一下编译工具
提示下面其实是安装成功了配置一下库就可以了
Libraries have been installed in:
/usr/local/apr/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
需要添加库文件:
[root@xuegod63 native]# vi /etc/ld.so.conf
/usr/local/apr/lib ##添加此行
[root@xuegod63 native]# ldconfig [root@xuegod63 native]# echo "ldconfig" >>/etc/rc.local
添加环境变量:
[root@localhost native]# vi /etc/profile.d/jdk8.sh
最后添加:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
重读生效:
[root@localhost native]#source /etc/profile.d/jdk8.sh
[root@localhost native]# vi /usr/local/tomcat/conf/server.xml 将默认的protocol="HTTP/1.1"修改为protocol="org.apache.coyote.http11.Http11AprProtocol"
引用apr:
[root@localhost native]# vi /usr/local/tomcat/bin/catalina.sh
253行下面添加:
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib"
重启服务生效:
service tomcat restart
cat /usr/local/tomcat/logs/catalina.out | grep Native
yum install mariadb mariadb-server -y
systemctl start mariadb
测试数据
mysql create database tomcat; use tomcat; create table tt(id int,name varchar(128)); insert into tt values (1,"come on boy"),(2,"come on girl"); grant all on tomcat.* to tomcat@localhost identified by 'tomcat'; mysql> \q [root@XueGod63 ~]# mysql -utomcat -ptomcat
https://dev.mysql.com/downloads/connector/j/
wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.47.tar.gz #稳定版下载
wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.15.tar.gz#此包不兼容
tar xf mysql-connector-java-5.1.36.tar.gz -C /usr/local/src/ #用旧版包新版可能不兼容 cp /usr/local/src/mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar /usr/local/tomcat/lib/
service tomcat stop; service tomcat start
vi /usr/local/tomcat/webapps/ROOT/mysql.jsp
<%@ page contentType="text/html;charset=utf-8"%> <%@ page import="java.sql.*"%> <html> <body> <% Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/tomcat?user=tomcat&password=tomcat&useUnicode=true&characterEncoding=utf-8"; Connection conn= DriverManager.getConnection(url); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from tt"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()){%> step:<%=rs.getString(1)%> context:<%=rs.getString(2)%><br><br> <%}%> <%out.print("Congratulations!!! JSP connect MYSQL IS OK!!");%> <%rs.close(); stmt.close(); conn.close(); %> %</body> %</html> %
http://192.168.1.63:8080/mysql.jsp
虚拟主机
vi /usr/local/tomcat/conf/server.xml
<Host name="www.xuegod63.com" appBase="/var/www/html"> <Context path="" docBase="/var/www/html/web1" /> </Host> <Host name="www.xuegod63.cn" appBase="/var/www/html"> <Context path="" docBase="/var/www/html/web2" /> </Host>
#在末尾的</Engine>上面添加上面这几行
service tomcat stop ; service tomcat start mkdir -p /var/www/html/{web1,web2} echo xuegod63.com > /var/www/html/web1/index.html echo xuegod63.cn> /var/www/html/web2/index.html #执行到这里才能监听端口没有目录tomcat无法启动
netstat -anput
192.168.1.63 www.xuegod63.com
192.168.1.63 www.xuegod63.cn