Skip to content

Commit 79ac21f

Browse files
committed
🔖 更新环境部署脚本
1 parent 4cd8db7 commit 79ac21f

4 files changed

Lines changed: 157 additions & 100 deletions

File tree

codes/deploy/sys/config-env.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env bash
2+
3+
###################################################################################
4+
# Linux Centos7 设置环境配置脚本(根据需要选择)
5+
# 注:不了解脚本中配置意图的情况下,不要贸然执行此脚本
6+
# Author: Zhang Peng
7+
###################################################################################
8+
9+
# 获取当前机器 IP
10+
ip=""
11+
function getDeviceIp() {
12+
ip=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
13+
if [ "$ip" == "" ]
14+
then
15+
ip=`ifconfig ens32 | grep "inet"|grep "broadcast" | awk '{ print $2}' | awk -F: '{print $1}'`
16+
fi
17+
18+
if [ "$ip" == "" ]
19+
then
20+
ip=`echo $1`
21+
fi
22+
23+
if [ "${ip}" == "" ]
24+
then
25+
echo "无法获取IP地址"
26+
exit 0
27+
fi
28+
}
29+
30+
function setDNS() {
31+
getDeviceIp
32+
host=`hostname`
33+
cat >> /etc/hosts << EOF
34+
${ip} ${host}
35+
EOF
36+
}
37+
38+
function setNameServer() {
39+
echo "添加域名服务器"
40+
echo "nameserver 218.2.135.1" >> /etc/resolv.conf
41+
}
42+
43+
function setNtp() {
44+
# 时钟同步工具
45+
yum -y install ntp
46+
# 同步上海交通大学网络中心NTP服务器
47+
echo "* 4 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn > /dev/null 2>&1" >> /var/spool/cron/root
48+
# 以一个服务器时间为标准定时更新时间(有时需要以公司中的服务器作为标准)
49+
#echo "*/30 * * * * /usr/local/bin/ntpdate 192.168.16.182" >> /var/spool/cron/root
50+
}
51+
52+
function setLimit() {
53+
cat >> /etc/security/limits.conf << EOF
54+
* - nofile 65535
55+
* - nproc 65535
56+
EOF
57+
}
58+
59+
function setLang() {
60+
cat > /etc/sysconfig/i18n << EOF
61+
LANG="zh_CN.UTF-8"
62+
EOF
63+
}
64+
65+
function closeShutdownShortkey() {
66+
echo "关闭 Ctrl+Alt+Del 快捷键防止重新启动"
67+
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf
68+
}
69+
70+
function closeSelinux() {
71+
echo "关闭 selinux"
72+
73+
# see http://blog.51cto.com/13570193/2093299
74+
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
75+
}
76+
77+
function closeFirewall() {
78+
echo "关闭防火墙"
79+
80+
# see https://www.cnblogs.com/moxiaoan/p/5683743.html
81+
systemctl stop firewalld
82+
systemctl disable firewalld
83+
}
84+
85+
function setBootMode() {
86+
# 1. 停机(记得不要把 initdefault 配置为 0,因为这样会使 Linux 不能启动)
87+
# 2. 单用户模式,就像 Win9X 下的安全模式
88+
# 3. 多用户,但是没有 NFS
89+
# 4. 完全多用户模式,准则的运行级
90+
# 5. 通常不用,在一些特殊情况下可以用它来做一些事情
91+
# 6. X11,即进到 X-Window 系统
92+
# 7. 重新启动 (记得不要把 initdefault 配置为 6,因为这样会使 Linux 不断地重新启动)
93+
echo "设置 Linux 启动模式"
94+
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab
95+
}
96+
97+
function configIpv4(){
98+
echo "配置 ipv4"
99+
100+
cat >> /etc/sysctl.conf << EOF
101+
net.ipv4.tcp_tw_reuse = 1
102+
net.ipv4.tcp_tw_recycle = 1
103+
net.ipv4.tcp_fin_timeout = 2
104+
net.ipv4.tcp_syncookies = 1
105+
net.ipv4.tcp_keepalive_time = 1200
106+
net.ipv4.tcp_max_syn_backlog = 16384
107+
net.core.netdev_max_backlog = 16384
108+
net.core.somaxconn = 32768
109+
net.core.wmem_default = 8388608
110+
net.core.rmem_default = 8388608
111+
net.core.rmem_max = 16777216
112+
net.core.wmem_max = 16777216
113+
net.ipv4.tcp_timestamps = 0
114+
net.ipv4.route.gc_timeout = 100
115+
net.ipv4.tcp_synack_retries = 1
116+
net.ipv4.tcp_syn_retries = 1
117+
net.ipv4.tcp_mem = 94500000 915000000 927000000
118+
net.ipv4.tcp_max_orphans = 3276800
119+
net.ipv4.ip_local_port_range = 2000 65535
120+
net.ipv4.tcp_max_tw_buckets = 5000
121+
vm.swappiness=10
122+
EOF
123+
}
124+
125+
function closeIpv6() {
126+
echo "关闭 ipv6"
127+
128+
cat > /etc/modprobe.d/ipv6.conf << EOF
129+
alias net-pf-10 off
130+
options ipv6 disable=1
131+
EOF
132+
133+
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
134+
}
135+
136+
######################################## MAIN ########################################
137+
echo -e "\n>>>>>>>>> 配置系统环境"
138+
139+
# 关闭 selinux
140+
closeSelinux
141+
142+
# 关闭防火墙
143+
closeFirewall
144+
145+
# 设置 DNS 服务器和本机 Host
146+
setNameServer
147+
setDNS
148+
149+
# 设置时间同步
150+
setNtp
151+
152+
echo -e "\n>>>>>>>>> 配置系统环境结束"

codes/deploy/sys/init.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ EOF
1313

1414
filepath=$(cd "$(dirname "$0")"; pwd)
1515

16-
# 设置环境配置,不了解具体修改内容的情况下,请勿执行
17-
# ${filepath}/set-config.sh
18-
19-
# 替换 yum 镜像
16+
# 替换 yum 镜像(使用国内镜像,加速下载)
2017
${filepath}/yum/change-yum-repo.sh
2118

19+
# 设置环境配置,不了解具体修改内容的情况下,请勿执行
20+
${filepath}/config-env.sh
21+
2222
# 安装命令行工具
2323
${filepath}/install-cmd-tool.sh
2424

25-
# 时钟同步工具
26-
yum -y install ntp
27-
# 同步上海交通大学网络中心NTP服务器
28-
echo "* 4 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn > /dev/null 2>&1" >> /var/spool/cron/root
29-
# 以一个服务器时间为标准定时更新时间(有时需要以公司中的服务器作为标准)
30-
#echo "*/30 * * * * /usr/local/bin/ntpdate 192.168.16.182" >> /var/spool/cron/root
31-
3225
cat << EOF
3326
***********************************************************************************
3427
* The initialization of linux environment is over.

codes/deploy/sys/set-config.sh

Lines changed: 0 additions & 88 deletions
This file was deleted.

codes/deploy/sys/yum/change-yum-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
###################################################################################
4-
# 本脚本用于替换 yum repo
4+
# 本脚本用于替换 yum repo,使用国内 yum 仓库,加速下载
55
# 要求:仅适用于 Linux Centos 发行版本,并且环境必须已支持 yum 、lsb_release 命令
66
# Author: Zhang Peng
77
###################################################################################

0 commit comments

Comments
 (0)