Linux 软件安装

目录

一、Linux

1、Linux异常解决

1、JDK安装

1、Linux卸载JDK

2、Linux安装JDK

2、Redis安装


一、Linux

1、Linux异常解决

1、Another app is currently holding the yum lock; waiting for it to exit...

解决办法:
rm -f /var/run/yum.pid

1、杀死这个应用程序
ps aux | grep yum(查询有关yum的进程,找到那个更新进程)
命令:kill -s 9 2833 pid
kill 的用法: kill [信号代码] 进程ID
注:信号代码可以省略;我们常用的信号代码是 -s 9 ,表示强制终止;
2833是这个进程的ID
2、强制关掉yum进程,并重新运行yum
#rm -f /var/run/yum.pid
注:强制删除:#rm -f
解释:强制删除文件:  /var/run/yum.pid
如果上面方法不行的话,尝试使用下面的方法。

1、JDK安装

1、Linux卸载JDK

1、查看java -version查看linux系统是否已经安装jdk

[root@localhost java]# java -version
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)

2、查看jdk安装的路径:which java

[root@localhost java]# which java
/usr/java/jdk1.8.0_202/bin/java

3、卸载jdk

rm -rf /usr/java/jdk1.8.0_202/bin/java

4、删除环境变量:export开头的三行


[root@localhost java]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_202
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

5、检查下系统自带的jdk,并删除它

rpm -qa |grep java
rpm -qa |grep jdk
rpm -qa |grep gcj

2、Linux安装JDK

JDK官方下载地址

1、将文件jdk-21.0.1_linux-x64_bin.tar.gz移动到/usr/java下,usr下没有java文件夹,可以先创建java文件夹:mkdir java

[root@localhost java]# ls
jdk-21.0.1_linux-x64_bin.tar.gz

2、解压

[root@localhost java]# tar -zxvf jdk-21.0.1_linux-x64_bin.tar.gz

3、在/etc/profile文件中,配置环境变量,使JDK在所有用户中生效

编辑文件,在最后添加如下三行:

export JAVA_HOME=/usr/java/jdk-21.0.1
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

4、保存退出后,执行source /etc/profile使修改的环境变量生效

[root@localhost java]# source /etc/profile

5、使用java -version命令测试是否成功

[root@localhost etc]# java -version
java version "21.0.1" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)

3、Linux安装OpenJDK

openjdk-jdk-shenandoah下载地址

[root@localhost java]# tar -zxvf openjdk-jdk-shenandoah-linux-x86_64-server-release-gcc12-glibc2.36.tar.xz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

//这个压缩包没有用gzip格式压缩,所以不用加z参数,所以不是所有的解压包都得用 -zxvf 
[root@localhost java]# tar -xvf openjdk-jdk-shenandoah-linux-x86_64-server-release-gcc12-glibc2.36.tar.xz
jdk/
jdk/legal/
jdk/legal/jdk.accessibility/
jdk/legal/jdk.accessibility/ADDITIONAL_LICENSE_INFO
jdk/legal/jdk.accessibility/ASSEMBLY_EXCEPTION
jdk/legal/jdk.accessibility/LICENSE
....

参照上面把jdk路径配置到环境变量/etc/profile文件中

[root@localhost java]# java -version
java: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by java)
java: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by /usr/java/jdk/bin/../lib/libjli.so)
java: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by /usr/java/jdk/bin/../lib/libjli.so)

重新安装ubuntu操作系统22.4.3版本,再安装成功。

root@admin:/usr/java# java -version
openjdk version "22-testing" 2024-03-19
OpenJDK Runtime Environment (build 22-testing-builds.shipilev.net-openjdk-jdk-shenandoah-b171-20231209)
OpenJDK 64-Bit Server VM (build 22-testing-builds.shipilev.net-openjdk-jdk-shenandoah-b171-20231209, mixed mode, sharing)
root@admin:/usr/java#

解决"lib64/libc.so.6: version `GLIBC_2.34' not found"错误

原因:某些库依赖特定的系统库版本,当我们运行程序时,如果系统库版本过低,可能会出现版本不匹配的错误。

解决步骤:

1、确认系统中GLIBC版本 ldd -version

[root@localhost ~]# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
[root@localhost ~]#

2、下载高版本的GLIBC

下载地址:http://ftp.gnu.org/gnu/glibc/glibc-2.34.tar.gz 

3、安装高版本的GLIBC

centos版本低。升级不成功,果断换操作系统,重新安装ubuntu操作系统22.4.3版本

root@admin:~# ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.5) 2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

2、Redis安装

Redis是基于c语言编写的需要安装依赖,需要安装gcc:

yum install gcc-c++

查看gcc版本:

 gcc -v

下载Redis

wget http://download.redis.io/releases/redis-7.2.3.tar.gz

[root@localhost redis]# wget http://download.redis.io/releases/redis-7.2.3.tar.gz                                                 --2023-11-24 00:18:22--  http://download.redis.io/releases/redis-7.2.3.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3384816 (3.2M) [application/octet-stream]
Saving to: ‘redis-7.2.3.tar.gz’

100%[========================================================================================>] 3,384,816    200KB/s   in 23s

2023-11-24 00:18:56 (146 KB/s) - ‘redis-7.2.3.tar.gz’ saved [3384816/3384816]

解压并安装Redis

tar -zvxf redis-7.2.3.tar.gz
cd redis-7.2.3/
make

[root@localhost redis-7.2.3]# make install
cd src && make install
which: no python3 in (/usr/java/jdk-21.0.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/usr/lwz_tools/redis/redis-7.2.3/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/lwz_tools/redis/redis-7.2.3/src'
which: no python3 in (/usr/java/jdk-21.0.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/usr/lwz_tools/redis/redis-7.2.3/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
make[1]: Leaving directory `/usr/lwz_tools/redis/redis-7.2.3/src'
[root@localhost redis-7.2.3]#

redis默认安装路径:/usr/local/bin

[root@localhost redis-7.2.3]# cd /usr/local/bin
[root@localhost bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

redis默认不是后台启动,更改启动方式

有关redis配置文件的一些说明:

然后修改redis.conf文件中的一些配置

# 允许访问的地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问,生产环境不要设置为0.0.0.0
bind 0.0.0.0
# 守护进程,修改为yes后即可后台运行
daemonize yes 
# 密码,设置后访问Redis必须输入密码
requirepass 123456

# 监听的端口
port 6379
# 工作目录,默认是当前目录,也就是运行redis-server时的命令,日志、持久化等文件会保存在这个目录
dir .
# 数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0~15
databases 1
# 设置redis能够使用的最大内存
maxmemory 512mb
# 日志文件,默认为空,不记录日志,可以指定日志文件名
logfile "redis.log"

启动redis-server服务

通过指定配置文件启动服务

redis-server redisconfig/redis.conf

使用redis-cli连接测试

redis-cli -p 6379

[root@localhost bin]# redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

#有密码需要 auth 你的密码

查看redis的进程是否开启(新开一个会话)

[root@localhost ~]# ps -ef|grep redis
root      7328     1  0 02:06 ?        00:00:00 redis-server 0.0.0.0:6379
root      7333  1565  0 02:06 pts/0    00:00:00 redis-cli -p 6379
root      7384  7345  0 02:12 pts/1    00:00:00 grep --color=auto redis
[root@localhost ~]#

如何关闭redis服务

127.0.0.1:6379> shutdown
not connected> exit
[root@localhost bin]#

再次查看服务:

[root@localhost ~]# ps -ef|grep redis
root      7386  7345  0 02:14 pts/1    00:00:00 grep --color=auto redis

设置Redis开机自启动

首先,新建一个系统服务文件:

vi /etc/systemd/system/redis.service

内容  /usr/local/bin/redis.conf指定配置文件路径可修改

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

然后重载系统服务:

systemctl daemon-reload

现在,我们可以用下面这组命令来操作redis了:

# 启动
systemctl start redis
# 停止
systemctl stop redis
# 重启
systemctl restart redis
# 查看状态
systemctl status redis

执行下面的命令,可以让redis开机自启:

systemctl enable redis

性能测试

redis 性能测试的基本命令如下:

redis-benchmark [option] [option value]

测试100个并发链接,每个并发100000请求

redis-benchmark -h localhost -p 6379 -c 100 -n 100000
Summary:
  throughput summary: 10989.01 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        5.135     1.600     4.479     9.823    13.223    25.231
====== LRANGE_600 (first 600 elements) ======
  100000 requests completed in 10.48 seconds     #100000个请求  所有请求在10.48秒完成
  100 parallel clients                           #100个客户端
  3 bytes payload                                #每次3个字节
  keep alive: 1                                  #活跃1个
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

Latency by percentile distribution:
0.000% <= 1.463 milliseconds (cumulative count 1)
50.000% <= 5.175 milliseconds (cumulative count 50271)
75.000% <= 5.999 milliseconds (cumulative count 75004)
87.500% <= 8.087 milliseconds (cumulative count 87514)
93.750% <= 10.631 milliseconds (cumulative count 93761)
96.875% <= 13.255 milliseconds (cumulative count 96875)
98.438% <= 15.199 milliseconds (cumulative count 98438)
99.219% <= 17.823 milliseconds (cumulative count 99221)
99.609% <= 20.319 milliseconds (cumulative count 99611)
99.805% <= 23.279 milliseconds (cumulative count 99807)
99.902% <= 25.503 milliseconds (cumulative count 99903)
99.951% <= 26.863 milliseconds (cumulative count 99952)
99.976% <= 27.727 milliseconds (cumulative count 99976)
99.988% <= 28.351 milliseconds (cumulative count 99988)
99.994% <= 28.847 milliseconds (cumulative count 99994)
99.997% <= 29.087 milliseconds (cumulative count 99997)
99.998% <= 29.279 milliseconds (cumulative count 99999)
99.999% <= 29.391 milliseconds (cumulative count 100000)
100.000% <= 29.391 milliseconds (cumulative count 100000)

Linux常用命令

干我们这行,啥时候懈怠,就意味着长进的停止,长进的停止就意味着被淘汰,只能往前冲,直到凤凰涅槃的一天!

你可能感兴趣的:(linux,运维,服务器)