Java

卸载系统自带的JDK

查看系统安装的JDK

使用rpm -qa | grep jdk命令查看当前系统安装的JDK。

1
2
3
4
5
6
[root@192 ~]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.362.b08-1.el7_9.x86_64
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
copy-jdk-configs-3.3-11.el7_9.noarch
java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64

卸载安装的JDK

使用rpm -e --nodeps的命令去卸载上述查询到的JDK。

1
2
3
4
5
6
7
8
[root@192 ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.362.b08-1.el7_9.x86_64
[root@192 ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@192 ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@192 ~]# rpm -e --nodeps copy-jdk-configs-3.3-11.el7_9.noarch
[root@192 ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64
[root@192 ~]# rpm -qa | grep jdk
[root@192 ~]# java -version
bash: java: 未找到命令...

使用yum方式安装Java

查看可以安装的版本

使用命令yum -y list java*查询可以安装的Java版本。

1
2
3
4
5
6
7
8
9
[root@192 ~]# yum -y list java*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
已安装的软件包
javapackages-tools.noarch 3.4.1-11.el7 @anaconda可安装的软件包
.......

安装JDK

这里选择安装1.8的版本。

1
[root@192 ~]# yum -y install java-1.8.0-openjdk*

查看JDK安装的目录

1
2
3
[root@192 /]# cd /usr/lib/jvm/java-1.8.0-openjdk
[root@192 java-1.8.0-openjdk]# ls
ASSEMBLY_EXCEPTION bin demo include jre lib LICENSE sample src.zip tapset THIRD_PARTY_README

卸载yum下载的JDK

1
[root@192 /]# yum -y remove java-1.8.0-openjdk*

手动安装JDK

下载安装包

安装包的下载可以去oracle的官网去下载,这里选择下载Java8的版本。

下载地址

根据自己的系统,选择对应的版本即可,这里选择x64 Compressed Archive的安装包。

jdk-8u361-linux-x64.tar.gz安装包上传到服务器。

解压安装包

这里将Java放在了/usr/local/java的文件夹中,把安装包解压到该文件夹即可。

1
[root@192 java]# tar -zxvf jdk-8u361-linux-x64.tar.gz -C ./

配置环境变量

/etc/profile文件尾部,加入以下的JDK的环境配置。

1
2
3
4
JAVA_HOME=/usr/local/java/jdk1.8.0_361
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

执行以下命令,使环境变量生效。

1
[root@192 /]# source /etc/profile

这条命令,在重启之后会失效,需要再次执行,不想再次执行,需要在/etc/bashrc尾部加入该条命令。

1
source /etc/profile

卸载JDK

想卸载的话,就将上述的压缩包的文件和环境变量删掉即可。

Redis

Redis离线安装

  1. 下载Redis

    Redis的安装包直接去官网下载即可。

    下载地址

  2. 将安装包解压

    这里放到/usr/local/redis下,并执行下面命令进行解压。

    1
    [root@192 redis]# tar -zxvf redis-7.0.10.tar.gz 
  3. 编译安装

    进入redis源码文件夹,执行以下命令,编译redis并进行安装。

    1
    2
    3
    4
    5
    # 编译安装
    make
    make install
    # 官方建议使用test测试
    make test
  4. 查看是否安装成功,在系统命令中出现redis的命令表示安装成功了。

    1
    2
    3
    [root@192 redis-7.0.10]# cd /usr/local/bin/
    [root@192 bin]# ls
    redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
  5. 将Redis安装到系统服务

    使用Redis的脚本工具,将Redis安装到系统服务上。

    1
    2
    3
    4
    5
    6
    7
    [root@192 redis-7.0.10]# cd utils/
    [root@192 utils]# ./install_server.sh
    Welcome to the redis service installer
    This script will help you easily set up a running redis server

    This systems seems to use systemd.
    Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

    发现有问题,得换种方法。

    utils目录下的systemd-redis_server.service文件拷贝到系统配置目录下,并改名为redis.server

    1
    2
    3
    [root@192 utils]# cp systemd-redis_server.service /usr/lib/systemd/system
    [root@192 utils]# cd /usr/lib/systemd/system
    [root@192 system]# mv systemd-redis_server.service redis.service

    编辑redis.server.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 原来为ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
    [Service]
    ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis-7.0.10/redis.conf --supervised systemd

    # 不修改启动可能会超时
    #Type=notify
    PrivateTmp=yes
    TimeoutStartSec=15
    TimeoutStopSec=15
  6. 编辑redis的配置文件

    1
    2
    3
    4
    5
    6
    7
    ################################# GENERAL #####################################
    # 配置日志文件位置
    logfile /var/log/redis/redis.log

    ################################ SNAPSHOTTING ################################
    # 数据目录
    dir /var/redis/6379
  7. 基础命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # 重新加载服务文件
    systemctl daemon-reload
    # 设置自启
    systemctl enable redis
    # 启动
    systemctl start redis
    # 停止
    systemctl stop redis
    # 重启
    systemctl restart redis
    # 查看状态
    systemctl status redis

Redis配置文件修改

redis有些配置需要更改,不然使用起来会出现问题。配置文件就在源码文件夹中的redis.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 需设置为 0.0.0.0 以允许所有 IP 访问,默认只能本地127.0.0.1本地IP访问
bind 0.0.0.0
# 关闭protected-mode模式,此时外部网络可以直接访问
protected-mode no
# 设置密码,不设置就需要自己注意
requirepass 123456
# 是否以守护进程模式运行(后台运行),默认为no
daemonize yes
# 日志文件存放
logfile "/data/redis/log/redis.log"
# 持久化存放文件的路径
dir /data/redis/data
# 启用 AOF 持久化
appendonly yes
# 指定 AOF 文件名
appendfilename "redis_data.aof"

Nginx

APT包管理安装

1
2
3
4
5
6
7
# 更新
apt update
# 下载nginx
apt install nginx
# 验证nginx
nginx -v
# nginx配置/etc/nginx

源码离线安装

Nginx依赖下载

Nginx还需要下载一些依赖库。

1
2
3
4
5
6
7
# PCRE https://github.com/PCRE2Project/pcre2/releases,例如pcre2-10.45.tar.gz
# PCRE编译安装
tar -zxvf pcre2-10.45.tar.gz
cd pcre2-10.45
./configure
make
make install
1
2
3
4
5
6
7
# Zlib https://www.zlib.net/,例如zlib-1.3.1.tar.gz
# Zlib编译安装
tar -zxvf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure
make
make install
1
2
3
4
5
6
7
# OpenSSL https://openssl-library.org/source/,例如openssl-3.5.1.tar.gz
# OpenSSL编译安装
tar -zxvf openssl-3.5.1.tar.gz
cd openssl-3.5.1
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make
make install

尽量添加sudo执行命令,避免权限出现的问题。

编译安装Nginx

首先需要先去下载nginx的源码

下载地址

比如这里的nginx-1.28.0.tar.gz。

1
2
3
4
5
6
7
8
9
10
11
12
13
# 解压
tar -zxvf nginx-1.28.0.tar.gz
cd nginx-1.28.0
# 配置编译参数,请自行替换刚刚的依赖源码路径
./configure \
--prefix=/etc/nginx \
--with-pcre=/data/nginx/pcre2-10.45 \
--with-zlib=/data/nginx/zlib-1.3.1 \
--with-openssl=/data/openssl-3.5.1 \
--with-http_ssl_module
# 编译安装
make
make install

配置 Systemd 服务

创建服务文件/etc/systemd/system/nginx.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/etc/nginx/sbin/nginx -t
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/etc/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
1
2
sudo systemctl enable nginx
sudo systemctl start nginx

Mysql

官网DEB包安装

https://downloads.mysql.com/archives/community/

选择官网适配有的操作系统,这里就选择Ubantu Linux,版本自己选择。

要是没有对应的版本,就看看使用的操作系统是基于什么的,也可以尝试一下,实在不行就只能试试使用源码进行编译了。

我这里下载的就是第一个Ubuntu Linux 24.10 (x86, 64-bit), DEB Bundle,包含了所有的数据库依赖了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 解压
tar -xvf mysql-server_8.0.41-1ubuntu24.10_amd64.deb-bundle.tar
# 里面包含这些依赖包
libmysqlclient-dev_8.0.41-1ubuntu24.10_amd64.deb
libmysqlclient21_8.0.41-1ubuntu24.10_amd64.deb
mysql-client_8.0.41-1ubuntu24.10_amd64.deb
mysql-common_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-client-core_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-client-plugins_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-client_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-server-core_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-server-debug_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-server_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-test-debug_8.0.41-1ubuntu24.10_amd64.deb
mysql-community-test_8.0.41-1ubuntu24.10_amd64.deb
mysql-server_8.0.41-1ubuntu24.10_amd64.deb
mysql-testsuite_8.0.41-1ubuntu24.10_amd64.deb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 依次按顺序安装依赖包
# 基础组件
sudo dpkg -i mysql-common_8.0.41-1ubuntu24.10_amd64.deb
# 核心库
sudo dpkg -i libmysqlclient21_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i libmysqlclient-dev_8.0.41-1ubuntu24.10_amd64.deb
# 客户端组件
sudo dpkg -i mysql-community-client-core_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-community-client-plugins_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-community-client_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-client_8.0.41-1ubuntu24.10_amd64.deb
# 服务器组件
sudo dpkg -i mysql-community-server-core_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-community-server_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-server_8.0.41-1ubuntu24.10_amd64.deb
# 测试调试组件
sudo dpkg -i mysql-community-test_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-community-test-debug_8.0.41-1ubuntu24.10_amd64.deb
sudo dpkg -i mysql-testsuite_8.0.41-1ubuntu24.10_amd64.deb

Docker

卸载旧版本

1
2
3
4
5
6
7
8
9
10
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

安装Docker

使用yum安装

安装所需要的依赖包。

1
$ sudo yum install -y yum-utils

鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。

执行下面的命令添加 yum 软件源:

1
2
3
4
5
$ sudo yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

$ sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

有了依赖包之后,就可以直接安装Docker了。

1
$ sudo yum install docker-ce docker-ce-cli containerd.io

使用脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装,另外可以通过 --mirror 选项使用国内源进行安装:

1
2
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun

执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker 的稳定(stable)版本安装在系统中。

启动Docker

1
2
$ sudo systemctl enable docker
$ sudo systemctl start docker

建立docker用户组

建立docker

1
$ sudo groupadd docker

将当前用户加入docker组中

1
$ sudo usermod -aG docker $USER

镜像加速

镜像加速器

  1. 阿里云加速器,可以去阿里云的关于镜像的管理控制台去获取。
  2. 网易云加速器,https://hub-mirror.c.163.com
  3. 百度云加速器,https://mirror.baidubce.com

配置docker加速器

查看之前是否配置过镜像地址。

1
$ systemctl cat docker | grep '\-\-registry\-mirror'

如果该命令有输出,那么请执行 $ systemctl cat docker 查看 ExecStart= 出现的位置,修改对应的文件内容去掉 --registry-mirror 参数及其值,并按接下来的步骤进行配置。

如果以上命令没有任何输出,那么就可以在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):

1
2
3
4
5
6
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}

重启docker服务

1
2
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

测试Docker是否安装成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~]# docker run --rm hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

出现以上内容则表示安装成功。

Docker离线安装

下载Docker离线安装包。

下载地址

系统配置文件docker.service

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
28
29
30
31
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network - online.target firewalld.service
Wants=network - online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --ipv6=false
ExecReload=/bin/kill -s HUP $MAINPID
# Having non - zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container - local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on - failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi - user.target

安装脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh

echo '解压tar包'
tar -xvf $1
echo '将docker目录下所有文件复制到/usr/bin目录'
cp docker/* /usr/bin
echo '将docker.service 复制到/etc/systemd/system/目录'
cp $2 /etc/systemd/system/
echo '添加文件可执行权限'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件'
systemctl daemon-reload
echo '启动docker'
systemctl start docker
echo '设置开机自启'
systemctl enable docker.service
echo 'docker安装成功'
docker -v

卸载脚本。

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh

echo '停止docker'
systemctl stop docker
echo '删除docker.service'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功'

通过安装包,执行安装脚本。

1
sh install.sh docker-23.0.3.tgz docker.service

声明

以上基本都是网上搜集的教程,基本都是复制粘贴,有些已经找不到出处,有出处的我尽量标明在以下链接。

Docker

Docker离线安装

Java安装

Redis离线安装

离线安装nginx