1. 最小化安裝centos
- 分區(qū)
| 分區(qū) | 大小 |
|---|---|
| /swap | 內(nèi)存大小 X 2 |
| /boot | 300M ~ 500M |
| / | 剩余大小 |
- 掛載第二塊硬盤到/data
mv /var/log /data && ln -sf /data/log /var/log
- 網(wǎng)絡(luò)配置
使用“ifconfig”命令查看系統(tǒng)已經(jīng)識別并已激活的網(wǎng)絡(luò)接口
ONBOOT=yes (自啟動)
BOOTPROTO=statics (statics靜太IP地址,dhcp為自動獲取IP)
IPADDR=192.168.1.33 (IP地址)
NETMASK=255.255.255.0 (子網(wǎng)掩碼)
GATEWAY=192.168.1.1 (網(wǎng)關(guān))
DNS1=192.168.1.1 (DNS)
2. 更新系統(tǒng)到最新版
su
yum -y update && yum -y upgrade
# yum -y update 升級所有包,改變軟件設(shè)置和系統(tǒng)設(shè)置,系統(tǒng)版本內(nèi)核都升級
# yum -y upgrade 升級所有包,不改變軟件設(shè)置和系統(tǒng)設(shè)置,系統(tǒng)版本升級,內(nèi)核不改變
3. 安裝網(wǎng)絡(luò)組件
yum -y install net-tools
4. 修改主機名
echo "主機名" > /etc/hostname
# 查看當(dāng)前的主機名
hostname
5. 配置sudo賬號
# 將需要sudo權(quán)限的賬戶添加到wheel組
usermod -a -G wheel <賬號>
6. 配置sshd
# 修改/etc/ssh/ssh_config
vim /etc/ssh/ssh_config
# Protocol 2,1 修改為 Protocol 2
# PermitRootLogin yes 修改為 PermitRootLogin no
systemctl restart sshd.service
7. 安裝其它服務(wù)
如nginx、php、mysql等
8. 啟用iptables
yum install iptables-services
systemctl stop firewalld
systemctl disable firewalld
systemctl start iptables
systemctl enable iptables
# 編輯防火墻配置文件,請確認開放ssh(22)端口后再執(zhí)行重啟sshd,否則將無人等登錄到該服務(wù)器
vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! # 保存退出
# 配置完成后
systemctl restart iptables.service
# 請確認數(shù)據(jù)庫,cache等無需從公網(wǎng)訪問的端口都被禁止遠程訪問