linuxcfg.sh [操作系统入门]
背景介绍:
今天跟导师聊了很多,感触颇深,差距颇大,收获颇多~
对基线和版本的控制有了更深入的了解。
-----------------------------------------------------------------------------------
每个人都有自己使用linux的环境,这些环境可以提升自己的工作效率,在岁月长河中,慢慢去完善这些“习惯”。
1 #!/bin/bash 23yesnoinput()
4{
5while :
6do
7 read ANSWER
8case $ANSWER in
9"yes"|"YES")
10 return 0
11 ;;
12"no"|"NO")
13 return 1
14 ;;
15 *)
16echo -n "[WARNING] Unknown input. "
17 ;;
18esac
19 printf "Please input [yes..no]: "
20done
21}
22
23iptablesconfig()
24{
25 iptables -P INPUT ACCEPT
26 iptables -P FORWARD ACCEPT
27 iptables -P OUTPUT ACCEPT
28
29 iptables -F
30 iptables -X
31 iptables -Z
32
33 iptables-save >/etc/sysconfig/iptables
34
35touch /etc/rc.d/rc.local
36chmod755 /etc/rc.d/rc.local
37sed -i /iptables/d /etc/rc.d/rc.local
38echo"iptables-restore < /etc/sysconfig/iptables" >>/etc/rc.d/rc.local
39
40sed -i ‘s/SELINUX=.*$/SELINUX=disabled/g‘ /etc/sysconfig/selinux &>/dev/null #centos7
41sed -i ‘s/SELINUX=.*$/SELINUX=disabled/g‘ /etc/selinux/config &>/dev/null #centos6
42
43 setenforce 0 &>/dev/null
44 systemctl stop firewalld &>/dev/null
45 systemctl disable firewalld &>/dev/null
46}
47
48systemconfig()
49{
50 #修改系统语言 需要为英文
51sed -i ‘s/^LANG=.*$/LANG="en_US.UTF-8"/g‘ /etc/locale.conf
52
53 #修改时区相差八小时问题
54ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
55
56 #ssh登陆慢
57sed -i ‘/^UseDNS/d‘ /etc/ssh/sshd_config
58sed -i ‘/^#UseDNS/aUseDNS no‘ /etc/ssh/sshd_config
59sed -i ‘/^GSSAPIAuthentication/d‘ /etc/ssh/sshd_config
60sed -i ‘/^#GSSAPIAuthentication/aGSSAPIAuthentication no‘ /etc/ssh/sshd_config
61 systemctl restart sshd
62
63 #配置DNS服务器
64echo"nameserver 114.114.114.114" >/etc/resolv.conf
65
66 #修改history相关属性
67mkdir -p /etc/profile.d
68
69echo"
70 PS1=‘[33[01;35m][u@h w]$ [33[00m]‘
71 HISTSIZE=1000000
72
73mkdir -p /root/.history
74 HISTFILE=/root/.history/history_`echo $SSH_CLIENT | cut -d‘‘ -f1`
75 HISTTIMEFORMAT="[%F %T] "
76export HISTTIMEFORMAT
77 export PROMPT_COMMAND="history -a"
78
79 export LANG=en_US.UTF-8
80 export LESSCHARSET=UTF-8
81
82" >/etc/profile.d/private.sh
83
84 source /etc/profile.d/private.sh
85
86}
87
88vimconfig()
89{
90touch ~/.vimrc
91
92echo"
93set nocompatible
94 set backspace=indent,eol,start
95""set backup
96syntax on
97set hlsearch
98filetype plugin on
99set ruler
100 set ts=4
101 set sw=4
102 set shiftwidth=4
103 set softtabstop=4
104set nu
105set autoindent
106""set textwidth=200
107set noexpandtab
108 set encoding=utf-8
109 set fileencoding=utf-8
110 set fileencodings=ucs-bom,utf-8,chinese
111set modeline
112 set t_vb=
113" > ~/.vimrc
114
115}
116
117gitconfig()
118{
119touch ~/.gitconfig
120
121echo"
122[user]
123 name =
124 email =
125[credential]
126 helper = store
127[http]
128 sslVerify = false
129[i18n]
130 logOutputEncoding = UTF-8
131 commitEncoding = UTF-8
132[core]
133 editor = vim
134 autocrlf = input
135 quotepath = false
136[push]
137 default = current
138[alias]
139 lg = log --graph --format=format:‘%C(cyan)[%ai]%C(reset) %C(bold blue)%h%C(reset) %C(bold green)(%ar)%C(reset) %C(bold red)%an%C(reset) %C(white)%s%C(reset) %C(bold yellow)%d%C(reset)‘
140 st = status
141ls = log --graph --format=format:‘%C(cyan)[%ai]%C(reset) %C(bold blue)%h%C(reset) %C(bold green)(%ar)%C(reset) %C(bold red)%an%C(reset) %C(white)%s%C(reset) %C(bold yellow)%d%C(reset)‘ --stat
142 so = show
143 cl = clean -xd
144[color]
145 ui = auto
146 [color "branch"]
147 current = yellow reverse bold
148 local = yellow bold
149 remote = green bold
150 [color "status"]
151 added = yellow bold
152 changed = red bold
153 untracked = green bold
154 [color "diff"]
155 meta = yellow bold
156 frag = magenta bold
157 commit = yellow bold
158 old = red bold
159 new = green bold
160 whitespace = red reverse
161 [color "diff-highlight"]
162 oldNormal = red bold
163 oldHighlight = red bold 52
164 newNormal = green bold
165 newHighlight = green bold 22
166" > ~/.gitconfig
167}
168
169yumconfig()
170{
171sed -i ‘s!cachedir=.*$!cachedir=/opt/yum/!g‘ /etc/yum.conf
172sed -i ‘s/^keepcache=.*$/keepcache=1/g‘ /etc/yum.conf
173sed -i ‘s/^gpgcheck=.*$/gpgcheck=0/g‘ /etc/yum.conf
174sed -i ‘s/^plugins=.*$/plugins=0/g‘ /etc/yum.conf
175sed -i ‘s/^enabled=.*$/enabled=0/g‘ /etc/yum/pluginconf.d/fastestmirror.conf
176
177mkdir -p /etc/yum.repos.d/
178rm -rf /etc/yum.repos.d/*
179
180 echo "
181[base]
182name=Base
183baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
184enabled=1
185
186[epel]
187name=epel
188baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
189enabled=1
190
191[extra]
192name=extra
193baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/
194enabled=0
195
196[docker]
197name=docker
198baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
199enabled=0
200
201[svn]
202name=svn
203baseurl=http://opensource.wandisco.com/centos/7/svn-1.11/RPMS/
204enabled=0
205
206[gitlab]
207name=gitlab-ee
208baseurl=https://packages.gitlab.com/gitlab/gitlab-ee/el/7/x86_64/
209enabled=0
210
211[intel]
212name=intel
213baseurl=https://download.01.org/QAT/repo
214enabled=0
215" >/etc/yum.repos.d/CentOS-Base.repo
216
217 yum clean all && yum makecache
218
219 # yum -y install vim git wget mlocate net-tools doxygen tree zip bzip2 file screen lrzsz
220 # yum -y install autoconf libtool automake gcc gcc-c++
221
222 # centos5.4 mirrors
223 # http://mirrors.aliyun.com/centos-vault/5.4/os/x86_64/
224 # http://archives.fedoraproject.org/pub/archive/epel/5/x86_64/
225 # http://mirrors.aliyun.com/centos-vault/5.4/extras/x86_64/
226 # http://mirrors.aliyun.com/centos-vault/5.4/centosplus/x86_64/
227 # http://mirrors.aliyun.com/centos-vault/5.4/updates/x86_64/
228 # http://opensource.wandisco.com/centos/5/svn-1.9/RPMS/
229}
230
231echo -n "[INFO] Are you sure to excute this script now?[yes/no]: "
232yesnoinput
233
234if [ "$?" -ne 0 ]; then
235 echo "Exit script!"
236 exit 1
237fi
238
239iptablesconfig
240systemconfig
241vimconfig
242gitconfig
243yumconfig
linuxcfg.sh
以上是 linuxcfg.sh [操作系统入门] 的全部内容, 来源链接: utcz.com/z/519364.html