搭建高效服务器环境

发表于 2019-03-16 10:09:21
阅读 33

规范

命名规范

主机命名

规范

host_[主机名称]

范例

host_web
host_db
host_cache

软件服务命名

规范

server_[服务名称]

范例

server_apache
server_mysql
server_redis

启动

开机启动

我们要在服务器启动后做下面几件事

  • 启动所有应用容器

  • 为应用容器设置防火墙规则

启动所有容器

启动所有容器就是要让 docker 服务自动启动

systemctl enable docker

把需要自动启动的容器的 restart 设置为 always

PortsCtrlr autostart containerName on

设置防火墙

设置防火墙规则文件(对外服务)

[root@tongfunet]# cat > /etc/ports_ctrlr/public.rules <<EOF
# web
docker_to_public  80   10.16.1.60
docker_to_public  443  10.16.1.60
EOF

设置防火墙规则文件(维护服务)

[root@tongfunet]# cat > /etc/ports_ctrlr/maintain.rules <<EOF
# SSH
port_to_hosts     22   10.16.1.60
EOF

设置防火墙白名单文件(维护服务)

[root@tongfunet]# cat > /etc/ports_ctrlr/xxx.allow_hosts <<EOF
# maintain IP
192.168.1.118

# maintain host
maintain-xxx.gnway.cc
EOF

将对外服务规则启动命令放置在 /etc/rc.d/rc.local 内

[root@tongfunet]# cat >> /etc/rc.d/rc.local <<EOF
PortsCtrlr force -if eth2 -key public # force to set firewall rules for public
EOF

将维护服务规则更新命令放置在 crontab 内

[root@tongfunet]# crontab -e

* * * * * /data/shell/PortsCtrlr.sh map -if eth2 -key maintain > /dev/null 2>&1 & ### auto update firewall ruels for maintain

待续。。。