一般程序安装的目录/user/local
mkdir /user/local/Java
mv ~/jdk-8u11-linux-x64.tar.gz /user/local/Java/
tar -zxvf jdk-8u11-linux-x64.tar.gz
whereis java #查找java在哪
vim /etc/profile
#输入G到文件末尾,增加2个环境变量
JAVA_HOME=/usr/local/Java/jdk1.8.0_11
export PATH=$JAVA_HOME/bin:$PATH
#重新加载文件
source /etc/profile
测试:
[vagrant@v1 ~]$ java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
[vagrant@v1 ~]$ cd
[vagrant@v1 ~]$ vim Hello.java
#输入如下内容
public class Hello {
public static void main(String[] args) {
System.out.println("hello java");
}
}
注意: 类名要与文件名称一致
#编译
[vagrant@v1 ~]$ javac Hello.java
[vagrant@v1 ~]$ ll
total 12
-rw-rw-r-- 1 vagrant vagrant 414 Jul 10 16:26 Hello.class
-rw-rw-r-- 1 vagrant vagrant 112 Jul 10 16:26 Hello.java
drwxrwxr-x 4 vagrant vagrant 27 Jul 10 14:16 java_project
-rwxrwxrwx 1 root users 729 Jul 10 16:25 User.java
#运行
[vagrant@v1 ~]$ java Hello
hello java
mv ~/apache-tomcat-8.5.56.tar.gz /user/local/Java
tar -zxvf apache-tomcat-8.5.56.tar.gz
[root@v1 ~] cd /user/local/Java
[root@v1 Java] /apache-tomcat-8.5.56/bin/startup.sh #启动
Using CATALINA_BASE: /user/local/Java/apache-tomcat-8.5.56
Using CATALINA_HOME: /user/local/Java/apache-tomcat-8.5.56
Using CATALINA_TMPDIR: /user/local/Java/apache-tomcat-8.5.56/temp
Using JRE_HOME: /user/local/Java/jdk1.8.0_11
Using CLASSPATH: /user/local/Java/apache-tomcat-8.5.56/bin/bootstrap.jar:/user/local/Java/apache-tomcat-8.5.56/bin/tomcat-juli.jar
Tomcat started.
#jps java的一个工具,跟javac一样,查看java的进程
[root@v1 ~] jps
21184 Jps
21113 Bootstrap
#显示网络状态信息,查看端口占用情况
[root@v1 ~] netstat -tunpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 949/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1651/master
tcp6 0 0 :::8080 :::* LISTEN 21113/java
tcp6 0 0 :::22 :::* LISTEN 949/sshd
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 21113/java
udp 0 0 0.0.0.0:68 0.0.0.0:* 7626/dhclient
udp 0 0 0.0.0.0:61822 0.0.0.0:* 7626/dhclient
udp6 0 0 :::24956 :::* 7626/dhclient
[root@v1 ~]#
在宿主机浏览器访问http://192.168.56.81:8080/index.jsp
测试修改/usr/local/Java/apache-tomcat-8.5.56/webapp/ROOT/index.jsp
vim /usr/local/Java/apache-tomcat-8.5.56/webapp/ROOT/index.jsp
使用curl命令
curl http://localhost:8080/index.jsp
下载地址 https://downloads.mysql.com/archives/community/,如图9-12所示。
拷贝mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz到/root目录下
cd ~
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
解压完成后重命名
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
mv mysql-5.7.28 /user/local/
检查mysql组和用户是否存在,如果没有则创建
cat /etc/group|grep mysql
groupadd mysql
useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
安装数据库
创建data目录
cd /user/local/mysql-5.7.28
mkdir data
将/user/local/mysql-5.7.28的所有者及所属组改为mysql
chown -R mysql.mysql /user/local/mysql-5.7.28
在/usr/local/mysql-5.7.28/support-files目录下创建my_default.cnf
cd /user/local/mysql-5.7.28/support-files
vim my_default.cnf
具体配置内容如下:
[mysqld]
#设置mysql的安装目录
basedir =/user/local/mysql-5.7.28
#设置mysql数据库的数据存放目录
datadir = /user/local/mysql-5.7.28/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /user/local/mysql-5.7.28/data/mysqld.log
pid-file = /user/local/mysql-5.7.28/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
拷贝配置文件,是否覆盖,是
cp my_default.cnf /etc/my.cnf
初始化Mysql
cd /user/local/mysql-5.7.28/
./bin/mysqld --initialize --user=mysql --basedir=/user/local/mysql-5.7.28/ --datadir=/user/local/mysql-5.7.28/data/
如果报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or 就安装libaio,如果没有则跳过
yum install libaio
初始化完成之后查看日志
cat /user/local/mysql-5.7.28/data/mysqld.log
红框里的是临时密码,如图9-13所示。
把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
启动mysql
service mysql start
进入mysql并更改密码
cd /user/local/mysql-5.7.28
[root@v1 mysql-5.7.28]# ./bin/mysql -u root -p
Enter password: #输入上面生成的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.28
Copyright (c) 2000, 2019, 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');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
如果更改时报错:ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’,就先查询一下是否已更改,最后执行刷新。
重启mysql生效
service mysql restart
● 启动service mysql start
● 关闭service mysql stop
● 重启service mysql restart