继开 | 博客

热爱生活,努力学习,实现自己的价值


  • 短诗的序

  • 迷途自渡

  • 寒星三两

  • 林深见鹿

  • 记昨日书

  • 顾探往昔

Centos8 安装Docker

发表于 2020-03-11
字数统计: 342 字 | 阅读时长 ≈ 2 min

此教程仅限于CentOS8 安装docker 其他linux版本并不适用

docker 安装前的准备

CentOS8 修改并更新源,解决yum无法使用问题(基础环境:CentOS Linux release 8.1.1911 (Core) )

  1. 备份旧的配置文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ 这里是改为阿里云的

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
3.生成缓存

yum makecache

docker 开始安装

1、yum 包更新到最新

yum update

2、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

yum install -y yum-utils device-mapper-persistent-data lvm2

3、 设置yum源

yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
如果出现错误提醒(尝试添加 ‘–skip-broken’ 来跳过无法安装的软件包 或 ‘–nobest’ 来不只使用最佳选择的软件包)

使用下面命令

yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
命令安装最新的 containerd.io、然后就可以顺利的安装Docker

4、 安装docker,出现输入的界面都按 y

yum install -y docker-ce

5、 查看docker版本,验证是否验证成功

docker -v

Linux 卸载 Redis

发表于 2020-03-10
字数统计: 189 字 | 阅读时长 ≈ 1 min

卸载Redis

1.首先查看redis-server是否启动

1
ps aux | grep redis
1
2
3
4
[root@iZ25rsnm9crfk8Z mydata]# ps aux | grep redis
systemd+ 333 0.1 1.4 40708 11956 ? Ssl 10:27 0:01 redis-server *:6379
root 627 0.0 0.1 12108 1088 pts/0 R+ 10:48 0:00 grep --color=auto redis
root 1269 0.0 0.3 43632 3308 ? Ssl Aug20 10:18 /usr/local/soft/redis5/bin/redis-server 0.0.0.0:16379

2.关闭这些进程

1
2
3
[root@iZ25rsnm9crfk8Z mydata]# kill 333
[root@iZ25rsnm9crfk8Z mydata]# kill 627
[root@iZ25rsnm9crfk8Z mydata]# kill 1269

3.删除redis相应的文件夹就可以了。

1
find / -name redis
1
2
3
4
[root@iZ25rsnm9crfk8Z mydata]# find / -name redis
/var/lib/selinux/targeted/active/modules/100/redis
/usr/share/selinux/targeted/default/active/modules/100/redis
/home/redis
1
2
3
rm -rf /var/lib/selinux/targeted/active/modules/100/redis 
rm -rf /usr/share/selinux/targeted/default/active/modules/100/redis
rm -rf /home/redis

Centos8 安装Redis 以及配置

发表于 2020-03-09
字数统计: 716 字 | 阅读时长 ≈ 4 min

#centos8安装redis

一、下载

  1. 官网地址:https://redis.io/
  2. 其他版本:http://download.redis.io/releases/
  3. 本文使用版本:redis-5.0.7.tar.gz
1
[root@localhost home]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz

二、解压

1
[root@localhost home]# tar -xzvf redis-5.0.7.tar.gz

三、准备编译

1. 请在操作前确认gcc是否已安装,

如未安装,可以执行这个命令安装:

1
[root@localhost home]# yum install gcc

2. 请在操作前确认tcl是否已安装

如未安装,可以执行这个命令安装:

1
[root@localhost redis-5.0.7]# yum install tcl

四、编译:

1
2
[root@localhost home]# cd redis-5.0.7/
[root@localhost redis-5.0.7]# make MALLOC=libc

说明:make 后加 MALLOC的参数的原因:

避免提示找不到 jemalloc/jemalloc.h

五、测试编译(此步可忽略)

1
[root@localhost redis-5.0.7]# make test

如果看到以下字样:表示无错误:

1
\o/ All tests passed without errors!

六、安装

1
2
3
4
5
6
7
8
9
[root@localhost redis-5.0.7]# mkdir /usr/local/soft/redis5
[root@localhost redis-5.0.7]# cd /usr/local/soft/redis5/
[root@localhost redis5]# mkdir bin
[root@localhost redis5]# mkdir conf
[root@localhost redis5]# cd bin/
[root@localhost bin]# cp /home/redis-5.0.7/src/redis-cli ./
[root@localhost bin]# cp /home/redis-5.0.7/src/redis-server ./
[root@localhost bin]# cd ../conf/
[root@localhost conf]# cp /home/redis-5.0.7/redis.conf ./

七、配置

1
[root@localhost conf]# vi redis.conf

设置

把no改成yes,后台运行

1
2
# daemonize no
daemonize yes

内存的最大使用限制

1
2
# maxmemory <bytes>
maxmemory 128MB

将这行代码注释或者设置成0.0.0.0,监听所有的ip地址,外网可以访问

1
2
#bind 127.0.0.1 
bind 0.0.0.0

把yes改成no,允许外网访问

1
2
#protected-mode yes
protected-mode no

可以修改端口号

1
port 6379

八、运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost conf]# /usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf
```

## 九、检查端口是否在使用中
``` linux
[root@localhost conf]# netstat -anp | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 16073/redis-server
```

## 十、查看redis的当前版本
``` linux
[root@localhost conf]# /usr/local/soft/redis5/bin/redis-server -v
Redis server v=5.0.7 sha=00000000:0 malloc=libc bits=64 build=8e31d2ed9a4c9593
```

## 十一、使redis可以用systemd方式启动和管理

#### 1.编辑service文件
``` linux
[root@localhost liuhongdi]# vim /lib/systemd/system/redis.service

2.service文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3.重载系统服务

1
2
3
4
5
6
7
8
[root@localhost liuhongdi]# systemctl daemon-reload
```

#### 4.管理redis

启动
``` linux
systemctl start redis

查看状态

1
2
3
4
5
systemctl status redis
```
使开机启动
``` linux
systemctl enable redis

十二、查看本地centos的版本

1
2
[root@localhost lib]# cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core)

Ttyd安装

发表于 2020-03-08
字数统计: 652 字 | 阅读时长 ≈ 3 min

简介:

ttyd 是一个简单的命令行工具,用于在 Web 上共享终端,简单点说就是可以实现在网页上使用SSH终端服务,并且该软件是免费开源的。

安装ttyd
ttyd作者已经提供编译好的二进制文件,直接下载即可使用,最新版下载地址为:
https://github.com/tsl0922/ttyd/releases,
这里以CentOS 7为例:

下载ttyd

1
wget -O ttyd https://github.com/tsl0922/ttyd/releases/download/1.6.0/ttyd_linux.x86_64

添加执行权限

1
chmod +x ttyd

移动目录

1
mv ttyd /usr/sbin

通过上面的几个步骤,我们已经完成ttyd安装,输入命令ttyd -v可查看当前版本:

1
2
[root@hosta29d0ffef5 ~]# ttyd -v
ttyd version 1.6.0-c15cfb7

运行ttyd

输入命令ttyd bash运行ttyd,注意防火墙需要放行7681端口,然后浏览器访问http://IP:7681即可打开WEB终端

1
ttyd bash

创建后台运行服务

上面ttyd并没有保持后台运行,访问7681也不需要任何密码验证,非常不安全,接下来我们为ttyd创建一个systemd服务并设置用户名、密码验证。

新建服务

创建一个ttyd.service文件:vi /etc/systemd/system/ttyd.service内容如下:

1
2
3
4
5
6
7
8
9
[Unit]
Description=ttyd
After=network.target

[Service]
ExecStart=/usr/sbin/ttyd -p 17681 -c xiaoz:xiaoz.me bash

[Install]
WantedBy=multi-user.target

让daemon生效

创建完毕后输入命令:

1
systemctl daemon-reload

-c参数,是设置用户名、密码验证,格式为-c 用户名:密码, 上面用户名为xiaoz,密码为xiaoz.me,请自行修改为自己的用户名、密码。
-p参数,是设置端口号,格式为-p 端口号, 上面端口号为:17681,请自行修改为自己需要的端口号。

使用systemd命令来进行管理

服务创建后,我们可以使用systemd了,命令如下:

1
2
3
4
5
6
7
8
#启动ttyd
systemctl start ttyd
#停止ttyd
systemctl stop ttyd
#重启ttyd
systemctl restart ttyd
#开机启动
systemctl enable ttyd

Nginx反向代理
如果您不喜欢通过IP + 端口的访问形式,也可以设置Nginx反向代理通过域名访问,配置如下:

如果是网站根目录

server{
   listen 80;
   charset utf-8;
   server_name 192.168.43.160;
    location / {
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://192.168.43.160:17681;
    }
}

如果是网站二级目录

location ~ ^/ttyd(.*)$ {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_pass http://127.0.0.1:7681/$1;
}
注意上面的ttyd可以修改为自己想要的路径。

Centos8 安装Git,并下载项目

发表于 2020-03-07
字数统计: 150 字 | 阅读时长 ≈ 1 min

安装

1
yum install git

第一个要配置的是你个人的用户名称和电子邮件地址。这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录:

1
2
3
git config --global user.name "Wjikai"

git config --global user.email 344746460@qq.com

查看信息

1
git config --list

配置客户端记住密码

1
2
3
git config --global credential.helper store

git clone https://gitee.com/wjikai/wangjikai.git

正克隆到 ‘wangjikai’…

1
2
Username for 'https://gitee.com': Wjikai
Password for 'https://Wjikai@gitee.com':

Telnet 不可用解决办法

发表于 2020-03-06
字数统计: 32 字 | 阅读时长 ≈ 1 min

当使用telnet的时候

1
2
[root@instance-nxxamr ~]# telnet 127.0.0.1 3306
-bash: telnet: command not found
1
yum install telnet-server
1
yum install telnet.*

Centos8 配置时间同步

发表于 2020-03-05
字数统计: 442 字 | 阅读时长 ≈ 2 min

在Centos8的以前版本,时间同步需要yum安装ntp软件,然后执行/usr/sbin/ntpdate time.windows.com.cn (/usr/sbin/ntpdate是同步命令,time.windows.com.cn时间服务器)命令,就能实现和互联网的时间服务器的时间一致。但是在Centos8中,yum install ntp时提示没有ntp安装软件。

ntpdate方法:

添加wlnmp的yum源:

1
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm

安装时间同步软件:

 yum install wntp

测试:

date#显示当前的时间

 date -s 2010/01/01#修改时间

date#显示修改后的当前时间

 ntpdate ntp1.aliyun.com  #同步时间

date#显示当前时间

可以把时间同步加入到定时同步,保证系统时间实时和互联网的时间一致。

CentOS系统时间与现在时间相差8小时解决方法
在安装完CentOS系统后发现时间与现在时间相差8小时,这是由于我们在安装系统的时选择的时区是上海,而CentOS默认bios时间是utc时间,所以时间相差了8小时。这个时候的bios的时间和系统的时间是不一致的,一个代表 utc 时间,一个代表cst(+8时区),即上海时间。

下面是同步时间的解决方法:
1、vi /etc/sysconfig/clock   #编辑文件
ZONE=”Asia/Shanghai”
UTC=false   #设置为false,硬件时钟不于utc时间一致
ARC=false
2、ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #linux的时区设置为上海
3、ntpdate asia.pool.ntp.org #对准时间,需要先安装ntp服务器 yum install ntp
4、/sbin/hwclock –systohc   #设置硬件时间和系统时间一致并校准

至此,linux系统时间和计算机硬件时间都是cst时间了,并且为上海时区。

Centos8 忘记Root密码如何操作

发表于 2020-03-04
字数统计: 395 字 | 阅读时长 ≈ 2 min

centos8 忘记root密码如何操作

在Linux运维过程中难免遇到忘记root超级管理员密码的问题,忘记root密码如何重置呢?

前提:能够修改Linux系统启动kernel参数

CentOS 8重置root密码

1)启动系统,选择kernel 启动菜单

2)选中第一行,按 e 字母键进入 编辑菜单

3)定位到 linux($root)行,在行尾追加内核参数:rd.break

4)按下ctrl+x启动系统,进入switch_root模式

5)switch_root模式:将原有系统的 / 根目录以只读模式挂载在/sysroot/目录下,修改root密码必须将原有系统的 / 根目录挂载为可读写模式

1
mount -l |grep /sysroot

6)重挂/sysroot目录为可读写模式

1
mount -o remount,rw /sysroot

7)将当前系统的 / 根目录切换到/sysroot,并设置语言为英文,若不设置,密码不为英文,重设密码不成功

1
chroot /sysroot
1
LANG=en (把语言改为英文)

8)修改root密码,无需输入原root密码,直接修改掉。

1
passwd root

9)自动重置/etc/passwd SELinux文件上下文

1
touch /.autorclabcl

10)exit退出shell

1
exit

11)再一次reboot退出 switch_root 模式并重启,等待系统重启完成

1
reboot

总结
重置root密码需要访问到kernel启动菜单,远程重置root密码需要远程控制卡访问物理Console,最后一定要等待系统自动重启完成,此过程要耐心点。一定要让系统自动重启完成,千万不要关闭系统或者硬重启。

1…35363738

继开

一辈子很短,努力的做好两件事就好:第一件事是热爱生活,好好的去爱身边的人;第二件事是努力学习,在工作中取得不一样的成绩,实现自己的价值,而不是仅仅为了赚钱。

303 日志
171 标签
RSS
gitee E-Mail
0%
鲁ICP备18007712号
© 2025 继开 | 站点字数统计: 262.2k
博客使用 Hexo 搭建
|
主题 — NexT.Mist v5.1.4
人访问 次查看