部署一臺子服務器的總體思路html
當你拿到一臺服務器以後第一件該作的就是看一下服務器的內存和磁盤的空間,而後再進行清理環境,下載你所須要的東西,而後就是打開防火牆iptables看一下規則,有規則的話就所有清理掉;而後就是配置epel源和zabbix源,下載密鑰,安裝zabbix客戶端還有同步數據所須要對的東西,以防萬一仍是要看一下環境有沒有清理乾淨。以後配置zabbix文件還有實時同步的文件,而後重啓服務器以後,配置你所須要的貴規則,同步你所須要的數據資料,最後重啓服務器防火牆等,這臺服務器就配置完成啦。linux
第一步:看空間內存並下載你會用到的工具nginx
# df -h vim
# free -m安全
# yum install wget net-tools vnstat lsof lrzszbash
第二步:配置源服務器
# vim /etc/yum.repos.d/zabbix.repo添加下面文件tcp
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591工具
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
# vim /etc/yum.repos.d/epel.repo網站
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
#
#
弄好環境以後,就能夠安裝zabbix
# yum install -y zabbix-agent iptables* rsync nginx
第三步:清理環境
# getenforce ——查看selinux的狀態
#vim /etc/selinux/config
把SELINUX=enforcing改爲SELINUX=disabled
重啓後生效。
# systemctl status firewalld ——查看firewalld的狀態
# systemctl stop firewalld ——臨時關閉firewalld
# systemctl disable firewalld ——永久關閉firewalld
# systemctl status iptables ——查看防火牆iptables的狀態
# systemctl stop iptables ——臨時關閉防火牆
# systemctlt disable iptables ——永久關閉防火牆
# systemctl status NetworkManager ——查看刷新環境的狀態
# systemctl stop NetworkManager ——臨時關閉刷新環境
# systemctl disable NetworkManager ——永久關閉刷新環境
第四步:配置服務器文件
# vim /etc/rsyncd.conf添加下面內容
[ziliao]
path = /software
read only = false
uid=xiaoke
gid=xiaoke
# vim /etc/nginx/nginx.conf把include下的內容註釋掉,下面我已經註釋好了
include /etc/nginx/kis/*.conf;
# location / {
# }
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
# vim /etc/zabbix/zabbix-agentd.conf修改一下幾項
Hostname=101.1.10 ——本機的IP
ServerActive=45.45.20.231 ——監控機的IP
ListenPort=10050 ——打開端口
Server=45.45.20.231 ——監控機的IP
# mkdir /software 存放網站的目錄
# mkdir /etc/nginx/kis 存放綁定域名配置文件的目錄
# mkdir /etc/nginx/conf 存放證書的目錄
# systemctl enable rsyncd ——開機自啓(下同)
# systemctl enable nginx
# systemctl enable zabbix-agend
第五步:添加規則
# systemctl start iptables
# iptables -F
# iptables -F -t nat
# iptables -F -t mangle
# iptables -A INPUT -p udp -m multiport --dport 53 -j ACCEPT ——yum install----通道
# iptables -A OUTPUT -p udp -m state --state established -j ACCEPT
# iptables -A OUTPUT -p udp -m state --state new,established -j ACCEPT
# iptables -A INPUT -p udp -m multiport --sport 53 -j ACCEPT
# iptables -A INPUT -p tcp -m multiport --dport 22 -j ACCEPT ——SSH服務
# iptables -A OUTPUT -p tcp -m state --state established -j ACCEPT
# iptables -A OUTPUT -p tcp -m state --state new,established -j ACCEPT
# iptables -A INPUT -p tcp -m multiport --sport 22 -j ACCEPT
# iptables -A INPUT -p tcp -m multiport --dport 80,443,873,10050,10051 -j ACCEPT ——nginx所須要端口
# iptables -A OUTPUT -p tcp -m state --state established -j ACCEPT
# iptables -A OUTPUT -p tcp -m state --state new,established -j ACCEPT
# iptables -A INPUT -p tcp -m multiport --sport 80,443,873,10050,10051 -j ACCEPT
# iptables -A INPUT -p icmp -j ACCEPT
# iptables -A OUTPUT -p icmp -j ACCEPT
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# service iptables save
第六步:同步數據
# cd /software/
# systemctl start rsyncd
# systemctl restart iptables
# rsync -av 要同步的主機的IP(45.0.0.10)::ziliao .
# bash 2軟鏈接到nginx配置.sh
# bash 6拷貝證書到linux下.sh
# nginx -t
第七步:全部服務器重啓
# systemctl restart nginx
# systemctl restart zabbix-agent
# systemctl restat rsyncd
# systemctl restart iptables
# systemctl enable nginx
# systemctl enable zabbix-agent
# systemctl enable iptables
# systemcyl enable rsyncd
檢查一下端口有沒有起來
# lsof -i:443
# lsof -i:80
# lsof -i:10050
# vim /etc/sudoers
xiaoke ALL=(ALL) NOPASSWORD:ALL
# vim /etc/resolv.conf添加DNS
servername 114.114.114.114
servername 8.8.8.8
若是不放心的話能夠檢查一下環境是否安全而後重啓服務器就能夠了。