2019年7月

一、系统安装

1、重新生成SSH host key

参考How To: Ubuntu / Debian Linux Regenerate OpenSSH Host Keys

# 删除原来的host keys
/bin/rm -v /etc/ssh/ssh_host_*
# 重新生成keys
dpkg-reconfigure openssh-server
# 重启ssh
/etc/init.d/ssh restart

在需要访问服务器端客户端上更新ssh指纹:

ssh-keygen -R <your_server_host>

2、更新包管理器及更新软件apt-get updateapt-get upgrade

设置apt源

比如我这里测试中国科技大学综合效果最好,更改sources.list中配置的源:

vim /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/debian/ stretch main
deb-src http://mirrors.ustc.edu.cn/debian/ stretch main

deb http://mirrors.ustc.edu.cn/debian-security stretch/updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian-security stretch/updates main contrib non-free

deb http://mirrors.ustc.edu.cn/debian/ stretch-updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ stretch-updates main contrib non-free

更新源中包数据库

  1. apt-get update出现:TypeError: 'NoneType' object is not callable

apt-get.jpg
解决:(参考Python 3.5 issues during apt-get update/upgradeopenmediavault omv3升级omv4)
打开文件:/usr/lib/python3.5/weakref.py,
109行由def remove(wr, selfref=ref(self)):改为:

def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):

117行由_remove_dead_weakref(d, wr.key)改为:

_atomic_removal(d, wr.key)
  1. apt-get update出现:Certificate verification failed: The certificate is NOT trusted. The certificate chain uses not yet valid certificate. Could not handshake: Error in the certificate verification.

出现这个问题可能是服务器本地时间不正常,导致证书验证错误,此时可以看下服务器时间:

root@aml:~# date
# 当前操作时间是:2021-03-22 09:58
Tue 26 Nov 2019 08:47:23 AM UTC

# 重新修改服务器时间
# 设置时区
timedatectl set-timezone "Asia/Shanghai"
# 设置时间
date -s "2021-03-22 09:58:00"

完成后,就可以正常执行:

apt-get update
apt-get upgrade

3、安装常用软件

  • 安装apt-get的扩展软件aptitude

    apt-get update aptitude
  • 用于替换nanovi的编辑vim

    aptitude install vim

4、设置区域、时区并同步时间

# 设置区域
dpkg-reconfigure locales
# 设置时区
dpkg-reconfigure tzdata

如果可以的话,与ntp服务器同步下时间:

apt-get install ntpdate
ntpdate ntp1.aliyun.com

5、设置bash环境变量

vim ~/.bashrc

设置内容,然后使设置生效source /root/.bashrc

6、设置vim环境变量

  • 创建vim环境变量文件touch ~/.vimrc
  • 设置环境变量内容:

    syntax on
    set fencs=utf-8,gbk
    set shiftwidth=4
    set softtabstop=4
    set tabstop=4
    set number

7、添加用户

# 添加用户
useradd -d /home/{username} -m -s /bin/bash -U {username}
# 设置新加用户密码
passwd {username}

这样用户就添加成功了,但是可能由于ssh的配置文件sshd_config限制了指定组才能通过ssh登录,比如:AllowGroups root ssh,限定只有用户属于组rootssh的用户才能登录。将我们新加的用户添加都允许登录的组:

usermod -a -G ssh {username}

8、设置ssh配置信息

ssh默认端口22,安全起见强烈建议更改为其他端口号并限制root账号直接通过ssh登录。

vim /etc/ssh/sshd_config
# 更改端口
Port xxxxx
# 禁用root账号直接登录
PermitRootLogin no
# 仅允许root和ssh组使用
AllowGroups root ssh
# 重启ssh服务
/etc/init.d/ssh restart

9、添加swap交换文件(可选)

  • 添加swap文件:(设置512M:1024 512MB = 524288;设置1G:1024 1024 = 1048576;设置2G:1024 1024 2 = 2097152)

    dd if=/dev/zero of=/swapfile bs=1024 count=1048576
  • 设置swap文件用户即权限

    chown root:root swapfile
    chmod 777 swapfile
  • 将文件转为交换文件并激活

    mkswap /swapfile
    swapon /swapfile
  • 自动挂载交换分区文件

    vim /etc/fstab
    # 新起一行添加
    /swapfile swap swap defaults 0 0
  • swap交换文件优先等级

    # 查看你的系统里面的swappiness (默认是:60)
    cat /proc/sys/vm/swappiness
    
    # 临时修改swappiness值
    sysctl vm.swappiness=90
    
    # 永久更改swappiness(如果配置文件没有,可以在配置文件最后追加)
    vim /etc/sysctl.conf
    vm.swappiness = 90
    
    # 使设置生效
    sysctl -p

10.安装omv-extras

参考:omv-extras Guides
支持deb安装和命令行安装,这里用命令行:

wget -O - http://omv-extras.org/install | bash

二、安装软件

1、安装MySQL 5.6

参考:MySQL :: A Quick Guide to Using the MySQL APT RepositoryHow To Install MySQL on Debian 9 (Stretch)

  • 添加MySQLAPT 仓库

    cd /tmp
    wget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
    dpkg -i mysql-apt-config_0.8.13-1_all.deb
  • 安装MySQL

    apt-get update
    aptitude install mysql-server
  • MySQL Secure Installation

    # 重启MySQL服务
    systemctl restart mysql
    
    # 调用
    mysql_secure_installation