vps常用操作
杂项
1.释放内存
1 2 3 4 5 6 7
| echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
echo 4 > /proc/sys/vm/drop_caches
|
2.关闭防火墙
1 2 3
| systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service
|
3.切换镜像
1 2 3
| wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache
|
4.epel
1 2 3 4 5
| yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm sed -i 's|^#baseurl=http://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* yum clean all yum makecache
|
5.清除packagekit
1 2 3
| systemctl stop packagekit systemctl disable packagekit yum remove PackageKit
|
6.清除内核
1 2 3 4
| uname --r rpm -q kernel dpkg -l | grep linux-image yum remove []
|
7.update-alternatives
一、重装系统-vnc(grub2+iPXE) centos7
1.下载内核:
1
| wget https://boot.netboot.xyz/ipxe/netboot.xyz.lkrn -O /boot/generic-ipxe.lkrn
|
2.新建initrd:
1
| vi /boot/netboot.xyz-initrd
|
写入内容:
1 2 3 4 5 6 7
| #!ipxe #/boot/netboot.xyz-initrd imgfree dhcp set dns 8.8.8.8 #应该可以改 ifopen net0 chain --autofree https://boot.netboot.xyz
|
3.编辑40_custom文件:
1
| vi /etc/grub.d/40_custom
|
添加grub2的开始菜单:
1 2 3 4 5
| menuentry 'netboot.xyz' { set root='hd0,msdos1' linux16 /boot/generic-ipxe.lkrn initrd16 /boot/netboot.xyz-initrd }
|
4.调整grub2的开始菜单显示时间:
1
| echo "GRUB_TIMEOUT=60" >> /etc/default/grub #改为显示60秒
|
或直接修改对应文件中的GRUB_TIMEOUT
一项,改成任意时间长度
如显示时间修改不生效,调整内核启动顺序:
1
| awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
|
将回显的netboot.xyz内核设为默认启动内核:
5.使配置生效
1
| grub2-mkconfig -o /etc/grub2.cfg
|
6.重启进入vnc,选择netboot.xyz内核.
二、docker相关操作
1.安装-见官方文档
1
| https://docs.docker.com/engine/install/
|
2.安装后启用docker-centos
3.下载并运行镜像
附加参数:
1 2
| -d 后台运行 -p 443:443 端口映射,前为实际端口,后为容器内端口
|
三、ssh连接相关
1.清除ssh连接缓存
2.生成ssh密钥
1 2
| ssh-keygen 可以附加参数-t指定密钥类型,缺省为ras ssh-keygen -t ras/ed25519 -C "注释信息"
|
3.上传公钥至远程服务器
1
| ssh-copy-id -i ~/.ssh/id_rsa.pub host@IP
|
或者服务器后安装(~/.ssh/ 目录下)
1
| cat id_rsa.pub >> authorized_keys
|
4.关闭密码登陆,打开root登陆等
修改/etc/ssh/sshd_config
文件,修改内容如下
1 2 3 4
| RSAAuthentication yes PubkeyAuthentication yes 启用密钥登陆 PermitRootLogin yes 允许root用户登陆 PasswordAuthentication no 禁用密码登陆
|
重启ssh服务
可能需要设置权限
1 2 3
| chmod 600 authorized_keys ~/.ssh目录下 chmod 700 ~/.ssh
|
安装 grub-imageboot,下载iso文件至/boot/images,更新update-grub2,重启
可能需要修改/etc/default/grub-imageboot文件