CentOS7安装openjdk、tomcat和mysql流程介绍

首先是前戏,推荐一个远程工具Xshell和Xftp搭配使用,以下是Xshell的官网 
http://www.netsarang.com/products/xsh_overview.html


1.openjdk

How to download and install prebuilt OpenJDK packages

JDK 8

Debian, Ubuntu, etc.

On the command line, type:

$ sudo apt-get install openjdk-8-jre

The openjdk-8-jre package contains just the Java Runtime Environment. If you want to develop Java programs then please install the openjdk-8-jdk package.

Fedora, Oracle Linux, Red Hat Enterprise Linux, etc.

On the command line, type:

$ su -c “yum install java-1.8.0-openjdk”

The java-1.8.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.8.0-openjdk-devel package.

以上说了不同系统的安装方式,还指出命令只是安装了JRE,如果你需要开发应用程序,还需要另外安装(已经用加粗标识),想安装其它版本详情看openjdk官网介绍 
http://openjdk.java.net/install/

[root@VM_207_229_centos ~]# java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
  • 1
  • 2
  • 3
  • 4

2.tomcat

# cd /usr/local
# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz
# tar xzf apache-tomcat-8.0.36.tar.gz
# mv apache-tomcat-8.0.36 tomcat
# ls
apache-tomcat-8.0.36.tar.gz  etc    include  lib64    logs    sa    share  tomcat   bin   games  lib   libexec  qcloud  sbin  src
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

个人习惯把tomcat放在/user/local下,下载后解压,再更名为tomcat 
想要其它版本的话……在以下地址找好路径下载 
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/

修改配置文件conf/server.xml改为监听80端口,默认编码utf-8,并开启gzip压缩

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" executor="tomcatThreadPool" URIEncoding="utf-8"   
               compression="on"   
               compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"   
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />
    <!-- A "Connector" using the shared thread pool-->
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

启动tomcat,在浏览器输入ip地址访问,看到tomcat小猫页面就行了。CentOS7开放80端口,Centos 7使用firewalld代替了原来的iptables。

<!-- 启动防火墙 -->
# systemctl start  firewalld
<!-- 开启80端口,出现success表明添加成功 -->
# firewall-cmd --zone=public --add-port=80/tcp --permanent
<!-- 重启防火墙 -->
# systemctl restart firewalld.service
<!-- 检查端口 -->
# firewall-cmd --permanent --zone=public --list-ports
<!-- 自启动防火墙 -->
#systemctl enable firewalld
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

还有更改默认访问地址,不想见到tomcat小猫(此步骤看个人需要)

<Engine name="Catalina" defaultHost="www.caihongwen.cn">

     <Realm className="org.apache.catalina.realm.LockOutRealm">
       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="www.caihongwen.cn"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Context docBase="blog" path="" debug="0"  reloadable="true"/>
               <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

请在意Host之间添加了一段代码

<Context docBase="blog" path="" debug="0"  reloadable="true"/>
  • 1

这个blog是放在webapps的项目war包名,通过ip或域名直接进入博客,不会出现tomcat小猫管理页面,第一次启动tomcat稍慢,新增加的war包需要重启一次才能起效。还有一个要点是对外开启80端口。


3.mysql

使用RPM包进行安装,这种安装进程会自动完成系统的相关配置,比较方便。 
另外有.tar.gz的压缩文件安装方式,推荐一个博客的介绍。 
http://blog.csdn.net/superchanon/article/details/8546254/

卸载原有MySQL或者Mariadb安装程序 
1、CentOs7版本默认情况下安装了mariadb-libs,必须先卸载才可以继续安装MySql。 
a) 查找以前是否安装mariadb-libs

# rpm -qa | grep -i mariadb-libs
  • 1

b)卸载已经安装的mariadb-libs

# yum remove mariadb-libs-5.5.44-2.el7.centos.x86_64
  • 1

2、查找以前是否安装MySQL

 # rpm -qa | grep -i mysql
  • 1

有的话,也删除

安装MySQL

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
  • 1
  • 2
  • 3

成功安装之后重启mysql服务

# service mysqld restart
  • 1

初次安装mysql是root账户是没有密码的,设置密码的方法

# mysql -uroot
mysql> set password for 'root'@'localhost' = password('mypasswd');
  • 1
  • 2

远程授权连接mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypasswd' WITH GRANT OPTION;
FLUSH   PRIVILEGES;
  • 1
  • 2

修改mysql默认编码

# vim /etc/my.cnf
  • 1

作出以下修改

[client]
default-character-set=utf8
[mysqld]
character_set_server=utf8
  • 1
  • 2
  • 3
  • 4

然后重启mysql

# service mysqld restart
# mysql -uroot -p
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

安装mysql-jdbc驱动

# yum install mysql-connector-java
  • 1

完工!!!

远程连接mysql,如果连接不上的话,可能是没开放3306端口。 
最后,分享一个mysql远程管理神器navicat,你懂的 
http://pan.baidu.com/s/1mh87vGc

posted @ 2018-01-24 15:34  庞国明  阅读(1091)  评论(0编辑  收藏  举报