1. sudo vi /etc/sysconfig/network-scripts/ifcfg-ens192
  1. # 添加配置 ONBOOT=yes
  2. IPADDR=192.168.72.122
  3. GATEWAY=192.168.72.254
  4. NETMASK=255.255.255.0
  5. DNS1=114.114.114.114
  6. DNS2=8.8.8.8
  1. sudo service network restart

使用xshell连接服务器

设置免密操作

  1. # 授权可编辑/etc/sudoers 文件
  2. sudo chmod -v u+w /etc/sudoers
  1. sudo vi /etc/sudoers

添加如下内容(xcsoft为需要免密操作的用户名)
image.png

  1. xcsoft ALL=(ALL) NOPASSWD:ALL
  2. %wheel ALL=(ALL) NOPASSWD:ALL
  1. # 取消sudoers文件写权限
  2. sudo chmod -v u-w /etc/sudoers

断开ssh重新连接

配置软件源

  1. # 备份系统旧配置文件
  2. sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  3. # 编辑源
  4. sudo vi /etc/yum.repos.d/CentOS-Base.repo
  1. # CentOS-Base.repo
  2. #
  3. # The mirror system uses the connecting IP address of the client and the
  4. # update status of each mirror to pick mirrors that are updated to and
  5. # geographically close to the client. You should use this for CentOS updates
  6. # unless you are manually picking other mirrors.
  7. #
  8. # If the mirrorlist= does not work for you, as a fall back you can try the
  9. # remarked out baseurl= line instead.
  10. #
  11. #
  12. [os]
  13. name=Qcloud centos os - $basearch
  14. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch/
  15. enabled=1
  16. gpgcheck=1
  17. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  18. [updates]
  19. name=Qcloud centos updates - $basearch
  20. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/updates/$basearch/
  21. enabled=1
  22. gpgcheck=1
  23. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  24. [centosplus]
  25. name=Qcloud centosplus - $basearch
  26. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/centosplus/$basearch/
  27. enabled=0
  28. gpgcheck=1
  29. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  30. [cloud]
  31. name=Qcloud centos contrib - $basearch
  32. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/cloud/$basearch/openstack-kilo/
  33. enabled=0
  34. gpgcheck=1
  35. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  36. [cr]
  37. name=Qcloud centos cr - $basearch
  38. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/cr/$basearch/
  39. enabled=0
  40. gpgcheck=1
  41. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  42. [extras]
  43. name=Qcloud centos extras - $basearch
  44. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch/
  45. enabled=1
  46. gpgcheck=1
  47. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  48. [fasttrack]
  49. name=Qcloud centos fasttrack - $basearch
  50. baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/fasttrack/$basearch/
  51. enabled=0
  52. gpgcheck=1
  53. gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
  1. sudo yum clean all
  2. sudo yum makecache
  3. sudo yum update

安装基础软件

  1. sudo yum install -y vim wget
  1. # 安装 epel源
  2. sudo mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
  3. sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
  4. sudo yum clean all
  5. sudo yum makecache

禁用ROOT登录

  1. sudo vim /etc/ssh/sshd_config
  1. PermitRootLogin no
  1. sudo service sshd restart

防止暴力破解

  1. # 安装 Fail2ban
  2. sudo yum install -y fail2ban
  3. # 进入fail2ban目录
  4. cd /etc/fail2ban
  5. # 复制一份配置文件
  6. sudo cp fail2ban.conf fail2ban.local
  7. sudo cp jail.conf jail.local
  8. vim jail.d/sshd.local
  1. [sshd]
  2. enabled=true
  3. bandtime=1y
  4. findtime=1m
  5. maxretry=5
  1. sudo service fail2ban restart
  2. #重启
  3. sudo fail2ban-client status
  4. #查看sshd的详细状态
  5. sudo fail2ban-client status sshd
  6. sudo tail -f /var/log/fail2ban.log
  7. sudo service fail2ban restart
  8. sudo systemctl enable fail2ban

设置hostname

  1. sudo hostnamectl set-hostname bigdata01

配置zabbix-agent2

  1. sudo setenforce 0
  2. sudo sed -i -e"s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
  3. echo "关闭selinux"
  4. sudo firewall-cmd --permanent --add-port=10050/tcp
  5. sudo firewall-cmd --reload
  6. echo "打开10050端口"
  7. sudo yum install ntpdate -y
  8. sudo ntpdate -u ntp.aliyun.com
  9. echo "同步时间"
  10. sudo mv /etc/localtime{,.bak}
  11. sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  12. echo "统一时区"
  13. sudo rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
  14. sudo sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
  15. sudo yum install zabbix-agent2 -y
  16. echo "安装zabbix-agent2"
  17. sudo sed -i -e"s/127.0.0.1/10.161.17.29/" /etc/zabbix/zabbix_agent2.conf
  18. sudo sed -i -e"s/Hostname=Zabbix server/Hostname=`cat /etc/hostname`/" /etc/zabbix/zabbix_agent2.conf
  19. sudo sed -i -e "s/# HostMetadata=/HostMetadata=xcsoft/" /etc/zabbix/zabbix_agent2.conf
  20. echo "修改配置"
  21. sudo systemctl enable --now zabbix-agent2
  22. echo "启动zabbix-agent2"