本文以CentOS7.9为例,分别使用RPM安装、解压安装和YUM三种安装方式,安装几个常用的软件如JDK、Tomcat、MySQL…
1、RPM命令的使用
RPM 是Red-Hat Package Manager(红帽软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始的设计理念是开放式的,包括OpenLinux、S.u.S.E.以及Turbo Linux等众多的Linux发行版都有采用 (Ubuntu默认不支持RPM,它用的是deb软件包),也就是说学了RPM之后我们就可以在CentOS上安装、卸载软件啦。
现在安装软件包不会使用RPM方式,会使用YUM安装,因为RPM不能解决软件包的依赖问题。例如在基于RPM安装MySQL8.0就会遇到软件包的依赖问题,而基于YUM安装可以解决这个问题。
RPM命令的使用
1、rpm -qa 查看系统已安装过的所有RPM软件包
[root@baidou987 ~]
[root@baidou987 ~]
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2020a-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
2、rpm -e --nodeps <RPM软件包名> 删除指定的RPM软件包
[root@baidou987 ~]
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2020a-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@baidou987 ~]
[root@baidou987 ~]
[root@baidou987 ~]
[root@baidou987 ~]
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2020a-1.el7.noarch
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
3、rpm -ivh <RPM软件包名> 安装指定的RPM软件
[root@baidou987 ~]
验证JDK的安装:
[root@baidou987 ~]
javac 1.8.0_202
[root@baidou987 ~]
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
rpm默认把文件安装到 /usr 目录下:
2、安装JDK8
JDK下载地址:https://www.oracle.com/java/technologies/downloads/archive/
JDK8下载地址:https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
JDK11下载地址:https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html
这里介绍一种适合所有Linux发行版的安装方式:
1、卸载系统上自带的OPenJDK
[root@baidou987 ~]
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2020a-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@baidou987 ~]
[root@baidou987 ~]
[root@baidou987 ~]
[root@baidou987 ~]
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2020a-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
2、到官网下载JDK8的解压版(tar.gz包)
jdk-8u202-linux-x64.tar.gz
3、将下载成功后的文件上传到CentOS虚拟机中
4、解压jdk-8u202-linux-x64.tar.gz文件到 /usr/loal/java 目录下
[root@baidou987 ~]
[root@baidou987 ~]
5、配置环境变量
[root@baidou987 ~]
export JAVA_HOME=/usr/local/java/jdk1.8.0_202
export PATH=$JAVA_HOME/bin:$PATH
[root@baidou987 ~]
6、验证JDK是否配置成功
[root@baidou987 ~]
javac 1.8.0_202
[root@baidou987 ~]
/usr/local/java/jdk1.8.0_202
wget下载JDK
[root@baidou987 ~]
3、安装Tomcat9
wget方式下载Tomcat9
Apache Tomcat 官网地址:https://tomcat.apache.org/
Apache Tomcat 下载地址:https://archive.apache.org/dist/tomcat/
Apache Tomcat 国内镜像下载地址:https://mirrors.cnnic.cn/apache/tomcat/ Tomcat9下载地址:https://mirrors.cnnic.cn/apache/tomcat/tomcat-9/v9.0.62/bin/apache-tomcat-9.0.62.tar.gz
1、复制下载链接,在命令行中使用wget命令下载Tomcat9
[root@baidou987 ~]
[root@baidou987 ~]
总用量 11292
-rw-r--r--. 1 root root 11560971 3月 31 22:40 apache-tomcat-9.0.62.tar.gz
drwxr-xr-x. 7 10 143 245 12月 16 2018 jdk1.8.0_202
2、解压apache-tomcat-9.0.62.tar.gz文件到 /usr/loal/tomcat 目录下
[root@baidou987 ~]
[root@baidou987 ~]
3、防火墙放行8080端口
[root@baidou987 ~]
[root@baidou987 ~]
running
[root@baidou987 ~]
no
[root@baidou987 ~]
success
[root@baidou987 ~]
[root@baidou987 ~]
yes
?
4、启动Tomcat服务器
[root@baidou987 ~]
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.62
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.62
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.62/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_202
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.62/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.62/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
测试访问 http://192.168.31.140:8080/
5、关闭Tomcat服务器
[root@baidou987 ~]
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.62
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.62
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.62/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_202
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.62/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.62/bin/tomcat-juli.jar
Using CATALINA_OPTS:
4、安装MySQL8.0
使用YUM安装MySQL8.0
MySQL官网地址:https://www.mysql.com/
MySQL文档地址:https://dev.mysql.com/doc/
MySQL8.0文档地址:https://dev.mysql.com/doc/refman/8.0/en/
MySQL8.0安装文档地址:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
MySQL8.0社区版下载地址:https://dev.mysql.com/downloads/repo/yum/
1、添加MySQL YUM源仓库到系统本地
[root@baidou987 ~]
[root@baidou987 ~]
[root@baidou987 ~]
mysql-connectors-community/x86_64 MySQL Connectors Community 192
mysql-tools-community/x86_64 MySQL Tools Community 90
mysql80-community/x86_64 MySQL 8.0 Community Server 343
2、安装MySQL
[root@baidou987 ~]
ok 执行这个命令后命令行会弹出个错误:
获取 GPG 密钥失败:[Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022”
解决方法:参考这篇文章https://www.edoou.com/articles/1574384642704824和官方文档将如下文件进行修改
[root@baidou987 ~]
- gpgcheck=1 ,在安装的时候进行源的检查
- gpgcheck=0 ,在安装的时候不进行源的检查
修改文件后,再次执行上述安装命令即可!
3、启动MySQL8.0服务
[root@baidou987 ~]
[root@baidou987 ~]
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2022-05-04 20:45:30 CST; 3min 34s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 19803 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 19837 (mysqld)
Status: "Server is operational"
Tasks: 37
CGroup: /system.slice/mysqld.service
└─19837 /usr/sbin/mysqld
5月 04 20:45:25 baidou987 systemd[1]: Starting MySQL Server...
5月 04 20:45:30 baidou987 systemd[1]: Started MySQL Server.
4、查看mysql默认生成的初始密码
[root@baidou987 mysql-8.0]
2022-05-04T12:44:28.096551Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: bi7:Js;:3-6i
5、登录MySQL客户端
[root@baidou987 mysql-8.0]
6、修改root登录密码
>ALTER USER 'root'@'localhost' IDENTIFIED BY 'Java666..';
Query OK, 0 rows affected (0.04 sec)
>flush privileges;
7、允许远程登录
mysql> create user 'root'@'%' identified by 'Java666..';
Query OK, 0 rows affected (0.05 sec)
mysql> grant all on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
8、放行3306端口
[root@baidou987 ~]
success
[root@baidou987 ~]
success
[root@baidou987 ~]
yes
ok ,我们可以远程访问啦!
使用RPM方式安装MySQL5.7
文章地址:https://blog.csdn.net/qq_46921028/article/details/122814156
完结撒花!!!
|