jdk安装

建立一个文件夹存放软件安装包

1
2
cd /opt
mkdir setups

建立java安装文件夹

1
2
cd /usr
mkdir java

解压文件并移动到java文件夹

1
2
tar -zxvf jdk-8u131-linux-x64.tar.gz
mv jdk1.8.0_131 /usr/java

配置环境变量

1
2
3
4
5
6
7
8
9
10
vim /etc/profile
在末尾添加
JAVA_HOME=/usr/java/jdk1.8.0_131
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH

刷新配置

1
source /etc/profile

检查配置

1
java -version

Tomcat安装

下载解压安装

1
2
3
wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.16/bin/apache-tomcat-8.5.16.tar.gz
tar -zxvf apache-tomcat-8.5.16.tar.gz
mv apache-tomcat-8.5.16 /usr/tomcat

运行

1
sh /usr/tomcat/apache-tomcat-8.5.16/bin/startup.sh

在浏览器输入http:ip地址:8080 测试;可以访问则表示成功,如果不可以访问需要配置防火墙规则

进行如下设置并重启防火墙,这里需要注意,由于centos7采用了firewall防火墙,配置方法有所不同,可以参考相关资料

1
2
# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
# service iptables restart

创建脚本文件方便tomcat启动

1
vim /etc/rc.d/init.d/tomcat

脚本文件如下,将Jdk和tomcat安装路径更换即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash  
# description: Tomcat7 Start Stop Restart
# processname: tomcat7
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.8.0_133
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/tomcat8
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0

设置文件属性和运行服务级别

1
2
# chmod a+x tomcat
# chkconfig --add tomcat

测试

1
2
3
4
service tomcat start
service tomcat stop
service tomcat restart
service tomcat status

安装mysql数据库

检查是否已经安装

1
2
rpm -q mysql-libs
yum remove mysql-libs /** if exists **/

下载安装mysql

1
2
3
4
5
6
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.56-1.el6.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.56-1.el6.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.56-1.el6.x86_64.rpm
rpm -ivh MySQL-server-5.5.56-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.5.56-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.5.56-1.el6.x86_64.rpm

安装时候需要注意centos系统为6是需要选择上面的版本

开启数据库

1
service mysql start

设置数据库root账户密码

1
2
3
4
mysql> use mysql;
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

数据库的配置

在mysql5.5中,默认是没有类似 /etc/my.cof的配置文件的,只有在/usr/share/mysql/下可以找到几个cnf后缀的配置文件,是根据内存大小来进行配置的,而如果想要修改编码,可以安装以下步骤

  1. 通过输入命令mysql --help | grep 'Default options' -A 1可以查看mysql5.5读取数据库配置文件的顺序,输出如下

    1
    2
    default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
  2. 创建配置文件 vi /etc/my.cnf

  3. 进行编码设置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [client]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    default-character-set=utf8
    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    character-set-server=utf8
    [mysql]
    no-auto-rehash
    default-character-set=utf8
  4. 重启mysqlservice mysql restart

  5. 查看是否生效mysql> show variables like 'char%';

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    mysql> show variables like 'char%';
    +--------------------------+----------------------------+
    | 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的配置安装也完成。