1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
cd /root
vi linux_init.sh
[内容 start]
#!/bin/bash
#update: 2022.04.23
#version: 1.0.24
#Global var
WEBDIR=/data/webserver
WEBSITEDIR=/data/website
WWWDIR=/data/www
TOOLSDIR=/data/tools
EXTDIR=/data/tools/php-ext
CONFDIR=/data/conf
LOGDIR=/data/log
BACKUPDIR=/data/backup
DBDIR=/data/database
APPDIR=/data/application
SCPDIR=/data/scp
LOGFILE=/data/log/appinstall.log
LOCALDIR=/data/website/linux_init
#check net_type
default_route=$(ip route show)
default_interface=$(echo $default_route | sed -e 's/^.*dev \([^ ]*\).*$/\1/' | head -n 1)
address=$(ip addr show label $default_interface scope global | awk '$1 == "inet" { print $2,$4}')
#ip addressw
ip=$(echo $address | awk '{print $1 }')
LOCALIP=${ip%%/*}
LOCALDIR=$(cd "$(dirname "$0")"&& pwd)
function base_env ()
{
rpm -qa|grep wget && rpm -qa|grep make && rpm -qa|grep gcc && rpm -qa|grep lftp && rpm -qa|grep gcc-c++ && rpm -qa|grep ntpdate && rpm -qa|grep unzip && rpm -qa|grep git- && rpm -qa|grep vim> /dev/null
if [ $? -eq 1 ]
then
yum install -y zlib-devel openssl-devel perl net-snmp lsof wget ntpdate make gcc gcc-c++ ncurses* telnet lftp openssh-clients vim lrzsz htop iftop net-tools unzip git vim dos2unix
git config –global core.editor vim
git config --global credential.helper store
echo -e "\e[1;32m基础环境已更新\e[0m"
fi
cat /etc/profile |grep PS1 >> /dev/null
if [ $? -eq 1 ]
then
echo 'PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ "' >> /etc/profile
echo 'HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
echo 'export EDITOR="/usr/bin/vim"' >> /etc/profile
fi
mkdir -p $WEBDIR
mkdir -p $WEBSITEDIR
mkdir -p $TOOLSDIR
mkdir -p $DBDIR
mkdir -p $APPDIR
mkdir -p $SCPDIR
mkdir -p $LOGDIR
mkdir -p $BACKUPDIR
mkdir -p $CONFDIR
mkdir -p $EXTDIR
if [ `getenforce` == 'Enforcing' ]
then
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
echo -e "\e[1;32m已关闭selinux\e[0m"
fi
systemctl stop firewalld
echo -e "\e[1;32m已关闭系统防火墙\e[0m"
cp -pr ./tools/* $TOOLSDIR/
cp -pr ./conf/* $CONFDIR/
cp -pr ./code/* $WEBSITEDIR/
cp -pr ./scp/* $SCPDIR/
echo -e "\e[1;32m已安装工具包\e[0m"
}
#function end
echo -e "\e[1;32m======================================================\e[0m"
echo -e "\e[1;32m选择要安装的服务类型,目前支持以下项目:\e[0m"
echo -e "\e[1;36m(1): 创建规范目录,安装基础库环境,关闭selinux,配置时间同步
(q): 退出\e[0m"
echo -e "\e[1;32m请输入序号:\e[0m"
read options
function main ()
{
case "$options" in
1)
clear
base_env
echo -e "\e[1;32m基础环境配置完毕\e[0m"
cd $LOCALDIR
sh ./init.sh
;;
q)
echo "退出脚本"
exit
;;
*)
clear
echo -e "\e[1;31m请输入正确的选项\e[0m"
cd $LOCALDIR
sh ./init.sh
esac
}
main $@
exit $?
[内容 end]
chmod +x linux_init.sh
./init.sh
选0 回车
|