本篇博文将会介绍的内容:
1.Java环境的搭建
2.Mysql环境的搭建
3.Tomcat环境的搭建
一.前期工作、工具以及资源(安装包)的准备
1.服务器配置信息
CPU:1核
内存:1024MB
操作系统:Ubuntu 16.04 64位
使用宽带:1Mbps
标准的学生机......
2.要用到的软件
1.FileZilla(连接云服务器,可以进行拷贝文件等操作) 下载地址:FileZilla
2.iTerm2(操作命令,配置环境变量等) 下载地址:iTerm2
3.使用iTerm2登陆服务器
3.1 在终端中输入一下命令,接着输入服务器的密码,即可登陆成功。
ssh root@公网IP
登陆成功提示:
登陆成功之后就可以使用Linux命令来控制服务器了。
二.Java环境,JDK的安装
1.输入以下命令更新source-list到最新的源信息
apt-get update
2.输入以下命令安装ftp服务器vsftp(其实在本安装教程中并没有使用filezilla等FTP软件进行操作,全部在命令行上进行操作)
apt-get install vsftpd -y
3.开始安装Java环境
3.1执行以下命令新建存放JDK的文件目录
mkdir /usr/java
3.2输入以下命令从根目录进入到上面新建的目录
cd /usr/java/
3.3输入以下命令下载JDK压缩包
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u72-b15/jdk-8u72-linux-x64.tar.gz" -O jdk-8u72-linux-x64.tar.gz
3.4输入以下命令解压缩下载的JDK压缩包
tar xzf jdk-8u72-linux-x64.tar.gz
3.5配置环境变量,输入以下命令
vi ~/.bashrc
3.6在打开的配置文件最后添加如下几条语句
export JAVA_HOME=/usr/java/jdk1.8.0_72 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
3.7输入以下命令刷新配置文件
source ~/.bash
3.8测试是否成功安装Java环境,输入以下命令,若出现下面结果则表示安装成功
xxxx:/usr/java# java -version java version "1.8.0_72" Java(TM) SE Runtime Environment (build 1.8.0_72-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)
三.Mysql的安装
1.新建存放mysql软件的目录
cd /usr mkdir mysql cd mysql
以上建好之后的目录结构为:/usr/mysql/mysql
2.进入相应目录下载mysql软件
cd /usr/mysql
wget http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.5.35-linux2.6-x86_64.tar.gz
3.解压缩下载的mysql文件
tar zxvf mysql-5.5.35-linux2.6-x86_64.tar.gz
4.对文件重命名
mv mysql-5.5.35-linux2.6-x86_64 mysql
5.添加组用户以及设置根目录
groupadd mysql
/usr/mysql/mysql/scripts/mysql_install_db --datadir=/usr/mysql/mysql/data/ --basedir=/usr/mysql/mysql --user=mysql
然后出现以下命令表示正常
Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/mysql/mysql/bin/mysqladmin -u root password \'new-password\' /usr/mysql/mysql/bin/mysqladmin -u root -h iZ2zeddsi0qgc23d1hexi3Z password \'new-password\' Alternatively you can run: /usr/mysql/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.
See the manual for more instructions. You can start the MySQL daemon with: cd /usr/mysql/mysql ; /usr/mysql/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql/mysql/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/mysql/mysql/scripts/mysqlbug script!
6.继续执行以下命令设置文件权限
chown -R mysql:mysql /usr/mysql/mysql chown -R mysql:mysql /usr/mysql/mysql/data chown -R mysql:mysql /usr/mysql/mysql/data/
7.创建所需的日志目录
/usr# mkdir log /usr# cd log /usr/log# mkdir mysql /usr/log# cd /usr/mysql
8.继续执行一条修改权限的命令
chown -R mysql:mysql /usr/log/mysql
9.对服务器进行配置
\cp -f /usr/mysql/mysql/support-files/mysql.server /etc/init.d/mysql sed -i \'s#^basedir=$#basedir=/usr/mysql/mysql#\' /etc/init.d/mysql sed -i \'s#^basedir=$#basedir=/usr/mysql/mysql/data#\' /etc/init.d/mysql \cp -f /usr/mysql/mysql/support-files/my-huge.cnf /etc/my.cnf sed -i \'s#skip-locking#skip-external-locking\nlog-error=/usr/log/mysql/error.log#\' /etc/my.cnf chmod 755 /etc/init.d/mysql
10.不出意外应该能正常启动了
service mysql start Starting MySQL ... * service mysql stop Shutting down MySQL . *
11.增加链接
ln -s /usr/mysql/mysql/bin/mysql /usr/bin ln -s /usr/mysql/mysql/bin/mysqladmin /usr/bin
12.为root用户设置密码
/usr/mysql/mysql/bin/mysqladmin -u root password \'你的密码\'
13.设置好之后可以通过命令直接登录mysql了
mysql -uroot -p你的密码
14.设置客户端工具可以登录服务器中的数据库(在数据库中输入以下命令)
GRANT ALL PRIVILEGES ON *.* TO root IDENTIFIED BY "你的密码";
15.若出现客户端中文乱码问题,进行以下操作
vim /etc/my.cnf
在[mysqld]中添加以下三行
character-set-server=utf8
collation-server = utf8_unicode_ci
init_connect =
\'set collation_connection = utf8_unicode_ci;\'
四.Tomcat的安装
1.新建存放tomcat文件的目录
cd /usr mkdir tomcat cd tomcat
2.下载tomcat压缩包(不同版本自己去官网找链接)
wget https://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.42/bin/apache-tomcat-8.0.42.tar.gz
3.解压并重命名
tar zxvf apache-tomcat-8.0.36.tar.gz mv apache-tomcat-8.0.36 tomcat
4.更改用户
cd /usr/tomcat/tomcat chown -R root . chgrp -R root .
5.配置环境变量
vi /etc/profile
在最后加入两句
CATALINA_HOME=/usr/tomcat/tomcat
export CATALINA_HOME
6.保存后退出vim,刷新配置文件
source /etc/profile
7.进入tomcat的bin目录
cd $CATALINA_HOME/bin
8.修改catalina.sh
vi catalina.sh
在# OS specific support. $var _must_ be set to either true or false. 这句下面添加
CATALINA_HOME=/usr/tomcat/tomcat
JAVA_HOME=/usr/java/java
9.保存后退出尝试开启服务(在tomcat的bin目录下)
sh startup.sh 或./startup.sh
10.注册tomcat服务(在tomcat的bin目录下)
cp catalina.sh /etc/init.d/tomcat
启动服务
service tomcat start
关闭服务
service tomcat stop
11.查看tomcat日志(在tomcat的logs目录下)
tail -500 catalina.out
-------------------------------------------------------------至此Java+Mysql+Tomcat环境搭建完成-------------------------------------------------------------
五.可能遇见的问题
1.通过iTerm2连接云服务器时提示:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:SeE50cV4XFx6QNExAvv8NlFFWNDndqdvkFtTObFDErw.
Please contact your system administrator.
Add correct host key in /Users/xxxxx/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/xxxxx/.ssh/known_hosts:1
ECDSA host key for xxx.xx.xxx.xxx has changed and you have requested strict checking.
Host key verification failed.
解决方法:
在终端中输入:
vim ~/.ssh/known_hosts
进入之后将关于服务器公网的信息删除即可。(需懂操作vim命令,不过非常简单)