系统:centos7.2
本文主要有以下四个部分组成:
1、centos7.2 jdk安装;
2、centos7.2安装Tomcat9.0;
3、centos7 安装mariadb;
4、java web项目的部署;
centos7.2 jdk安装
1、安装JDK
上传新的jdk-8u111-linux-x64.rpm软件到/usr/local/执行以下操作:
[root@zck local]# rpm -ivh jdk-8u111-linux-x64.rpm
JDK默认安装在/usr/java中。
2、验证安装
执行以下操作,查看信息是否正常:
[root@localhost ~]# java
[root@localhost ~]# javac
[root@localhost ~]# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
3、配置环境变量
修改系统环境变量文件
vi + /etc/profile
向文件里面追加以下内容:
JAVA_HOME=/usr/java/jdk1.8.0_111
JRE_HOME=/usr/java/jdk1.8.0_111/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
使修改生效
[root@localhost ~]# source /etc/profile //使修改立即生效
4、查看系统环境状态
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_111/bin:/usr/java/jdk1.8.0_111/jre/bin
centos7.2安装Tomcat9.0
1、下载:apache-tomcat-9.0.0.M11.tar.gz
网址:http://tomcat.apache.org/download-90.cgi
2、安装tomcat
将apache-tomcat-9.0.0.M11.tar.gz文件上传到/usr/local中执行以下操作:
[root@iZwz9bvemtte4yl4836a58Z local]# cd /usr/local
[root@iZwz9bvemtte4yl4836a58Z local]# tar -zxv -f apache-tomcat-9.0.0.M11.tar.gz // 解压压缩包
[root@iZwz9bvemtte4yl4836a58Z local]# rm -rf apache-tomcat-9.0.0.M11.tar.gz // 删除压缩包
[root@iZwz9bvemtte4yl4836a58Z local]# mv apache-tomcat-7.0.29 tomcat
3、启动Tomcat
[root@iZwz9bvemtte4yl4836a58Z ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.8.0_111/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
4、防火墙开放8080端口
增加8080端口到防火墙配置中,执行以下操作:
[root@iZwz9bvemtte4yl4836a58Z ~]# vi + /etc/sysconfig/iptables
增加以下代码:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
5、重启防火墙
[root@iZwz9bvemtte4yl4836a58Z ~]# service iptables retart
6、检验Tomcat安装运行
通过以下地址查看tomcat是否运行正常:
http://120.75.121.75:8080/
看到tomcat系统界面,说明安装成功!
7、停止Tomcat
[root@iZwz9bvemtte4yl4836a58Z~]#/usr/local/tomcat/bin/shutdown.sh
//停止tomcat
centos7 安装mariadb
1、安装MariaDB
安装命令:
yum -y install mariadb mariadb-server
首先启动MariaDB:
systemctl start mariadb
设置开机启动:
systemctl enable mariadb
MariaDB的相关简单配置
mysql_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
mysql -uroot -ppassword
完成。
2、配置MariaDB的字符集
执行vi /etc/my.cnf,在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
执行vi /etc/my.cnf.d/client.cnf,在[client]中添加
default-character-set=utf8
执行vi /etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加
default-character-set=utf8
全部配置完成,重启mariadb
systemctl restart mariadb
查看是否配置成功:如下
[root@iZwz9bvemtte4yl4836a58Z ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.50-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> 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)
MariaDB [(none)]> show variables like "%collation%";
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>
3、添加用户,设置权限
注释:mysql的操作中,分号不能忘了。
[root@iZwz9bvemtte4yl4836a58Z ~]# mysql -uroot -p
创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on *.* to username@localhost indentified by 'password';
授予外网登陆权限
mysql>grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
刷新系统权限表
mysql>flush privileges;
详细如下:
[root@iZwz9bvemtte4yl4836a58Z ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.50-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> create user un@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *1314DBFF97A917A817B1C56321B088B291664619 |
| root | 127.0.0.1 | *1314DBFF97A917A817B1C56321B088B291664619 |
| root | ::1 | *1314DBFF97A917A817B1C56321B088B291664619 |
| un | % | *484EE53A91F439428F0030CE471E3C00303E754D |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)
注释:其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
4、补充
创建用户并设置密码
mysql> insert into mysql.user(Host,User,Password) values("localhost","admin",password("admin"));
mysql>flush privileges;
创建数据库并授权
create database mydb;
//授权admin用户拥有mydb数据库的所有权限。
>grant all privileges on mydb.* to admin@localhost identified by 'admin';
mysql>flush privileges;
删除数据库和用户
mysql>DELETE FROM user WHERE User="admin" and Host="localhost";
mysql>flush privileges;
mysql>drop database mydb;
修改密码
mysql>update mysql.user set password=password('新密码') where User="admin" and Host="localhost";
java web项目的部署
1、获取war包;
2、将xftp上传到tomcat/webapps目录下;
3、重启tomcat;
This is not the end but a beginning,come on!