CentOS6.5 硬盘20G
二、安装jdk
1,下载linux版本的jdk
下载jdk-7u75-linux-x64.tar.gz,下载地址为:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
2,卸载自带jdk
#rpm -qa|grep jdk
显示:jdk-1.6.0_10-fcs
卸载:#rpm -e --nodeps jdk-1.6.0_10-fcs
3,新建jdk的安装目录
在/usr/local/下新建java目录,命令:mkdir /usr/local/java ,再把 jdk-7u75-linux-x64.tar.gz压缩包从opt目录下复制到/usr/local/java目录下,命令如下:
cp jdk-7u75-linux-x64.tar.gz /usr/local/java
4,解压
解压缩刚才下载的:jdk-7u75-linux-x64.tar.gz包,命令如下:
tar xvf jdk-7u75-linux-x64.tar.gz
5,配置环境变量
解压完成后,进入到:
[root@localhost~]# cd /etc
[root@localhost etc]# vi profile
在profile文件的末尾加入如下命令(配置环境变量):
export JAVA_HOME=/usr/local/java/jdk1.7.0_75
export JRE_HOME=/usr/local/java/jdk1.7.0_75/jre
export PATH=$PATH:/usr/local/java/jdk1.7.0_75/bin
export CLASSPATH=./:/usr/local/java/jdk1.7.0_75/lib:/usr/local/java/jdk1.7.0_75/jre/lib
insert进入编辑,esc ,输入“:wq”保存并退出
执行source /etc/profile让配置生效,这样就不用重启了
再次查看版本确认jdk环境配置成功
# java –version
三、安装mysql
1,下载地址
http://dev.mysql.com/downloads/mysql/#downloads
选择RPM安装
2,解压压缩包
tar xvf ***
3,检查是否已经安装
[root@localhost JavaEE]#rpm -qa|grep -imysql
mysql-libs-5.1.61-4.el6.x86_64
可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸载时使用了--nodeps选项,忽略了依赖关系:
[root@localhost JavaEE]#rpm -emysql-libs-5.1.61-4.el6.x86_64 --nodeps
4,安装MySQL服务器端软件(注意切换到root用户)
[root@localhost JavaEE]#rpm -ivhMySQL-server-5.5.29-2.el6.x86_64.rpm
出现libaio.io.6的错误时yum源修复,yum search ** ;yum install **;
安装完成后,安装进程会在Linux中添加一个mysql组,以及属于mysql组的用户mysql。可通过id命令查看:
[root@localhost JavaEE]#id mysql
uid=496(mysql)gid=493(mysql)groups=493(mysql)
MySQL服务器安装之后虽然配置了相关文件,但并没有自动启动mysqld服务,需自行启动:
[root@localhost JavaEE]#service mysql start或/etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
可通过检查端口是否开启来查看MySQL是否正常启动:
[root@localhost JavaEE]#netstat -anp|grep3306
tcp 0 00.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld
5,安装MySQL客户端软件
[root@localhost JavaEE]#rpm -ivhMySQL-client-5.5.29-2.el6.x86_64.rpm
如果安装成功应该可以运行mysql命令,注意必须是mysqld服务以及开启:
[root@localhost JavaEE]#mysql –u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stop
Shutting down MySQL..[ OK ]
[root@DB-Server init.d]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select Host, User, Password,password_expired
-> from user
-> where user='root' and host='root' or host='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host | User | Password | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
mysql> update user set password=PASSWORD('123456')
-> where user='root' and host='root' or 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
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart
Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
[ OK ]
Starting MySQL.[ OK ]
[2]- Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@DB-Server init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.19
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('123456');
6,设置外网访问用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'woshiyonghu'@'%' IDENTIFIED BY 'woshimima' WITH GRANT OPTION;
mysql> flush privileges;
mysql >quit;
7,修改mysql的配置文件
(1) # vi/etc/my.cnf (如果my.cnf文件不在该位置,需要查找,查找命令find / -name my.cnf)
(2)将lower_case_table_name=1 添加到[mysqld]下面,保存并退出:1. 按Esc键 2. 输入冒号“:wq”
(3)然后重启mysql
service mysql restart
四、安装tomcat和操作
1.安装
tomcat直接复制安装包即可,把项目放在tomcat下webapp里
2. 关闭一下tomcat服务
特别是已经启动的情况下,只不过有些异常
./shutdown.sh
3. 检查一下tomcat是否确实已经关闭
ps -ef|grep java
假如出现以下类似的提示,表示tomcat已经关闭
root 30248 30113 0 10:00pts/0 00:00:00 grep java
4. 最后重新启动tomcat
./startup.sh
5 linux tomcat get中文乱码问题
Tomcat的conf下server.xml默认有个uri编码,可以解决GET请求编码问题。
<Connector port="8080"maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25"maxSpareThreads="75" enableLookups="false"redirectPort="8443" acceptCount="100"connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8" />
五
复制web应用文件夹到tomcat/webapps目录下
六、导入数据库文件
可用mysqlworkbench软件或者linux操作mysql导入数据库文件,用户名密码即使上文的设置外网访问用户的用户名密码。
七、设置自启动
1.mysql设置自启动
将mysqld服务加入开机自启动项。
(1)将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld(找不到mysql.server用find / -name mysql.server)
[root@localhostmysql] cp support-files/mysql.server /etc/rc.d/init.d/mysqld
(2)通过chkconfig命令将mysqld服务加入到自启动服务项中。
[root@localhost mysql]#chkconfig --add mysqld
注意服务名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。
(3)查看是否添加成功
[root@localhost mysql]#chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
重启系统,mysqld就会自动启动了。
(4)检查是否启动
[root@localhost mysql]#netstat -anp|grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld
unix 2 [ ACC] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock
(5)手动启动。
[root@localhost mysql]#service mysqld start
Starting MySQL.. SUCCESS!
2.tomcat设置自启动
(1)在/etc/init.d下新建一个文件tomcat(需要在root权限下操作)
vi /etc/init.d/tomcat
写下如下代码,tomcat自启动脚本:
#!/bin/sh
# chkconfig: 345 9910
# description:Auto-starts tomcat
#/etc/init.d/tomcatd
# Tomcat auto-start
# Source functionlibrary.
#./etc/init.d/functions
# source networkingconfiguration.
#./etc/sysconfig/network
RETVAL=0
exportJAVA_HOME=/usr/java/jdk1.7.0_60
exportJRE_HOME=/usr/java/jdk1.7.0_60/jre
exportCATALINA_HOME=/usr/local/tomcat
exportCATALINA_BASE=/usr/local/tomcat
start()
{
if [ -f$CATALINA_HOME/bin/startup.sh ];
then
echo$"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo "OK"
return $RETVAL
fi
}
stop()
{
if [ -f$CATALINA_HOME/bin/shutdown.sh ];
then
echo$"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu root |grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo "OK"
# [ $RETVAL -eq 0 ]&& rm -f /var/lock/...
return $RETVAL
fi
}
case "$1"in
start)
start
;;
stop)
stop
;;
restart)
echo$"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage:$0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
(2)增加可执行权限
chmod +x /etc/init.d/tomcat
(3)挂载
ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat
(4)设置脚本开机自启动
把这个脚本设置成系统启动时自动执行,系统关闭时自动停止,使用如下命令:
chkconfig --add tomcat
(5)验证
执行reboot。重启之后就会发现,Tomcat已经成功运行了。
八、运行
进入tomcat/bin目录下
执行./startup.sh
浏览器输入localhost(或者本机IP):8080/应用名