linuxcfg.sh

背景介绍:

今天跟导师聊了很多,感触颇深,差距颇大,收获颇多~

对基线和版本的控制有了更深入的了解。

-----------------------------------------------------------------------------------

每个人都有自己使用linux的环境,这些环境可以提升自己的工作效率,在岁月长河中,慢慢去完善这些“习惯”。

  1 #!/bin/bash
  2 
  3 yesnoinput()
  4 {
  5     while :
  6     do
  7         read ANSWER
  8         case $ANSWER in
  9         "yes"|"YES")
 10             return 0
 11             ;;
 12         "no"|"NO")
 13             return 1
 14             ;;
 15         *)
 16             echo -n "[WARNING] Unknown input. "
 17             ;;
 18         esac
 19         printf "Please input [yes..no]: "
 20     done
 21 }
 22 
 23 iptablesconfig()
 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     
 35     touch /etc/rc.d/rc.local
 36     chmod 755 /etc/rc.d/rc.local
 37     sed -i /iptables/d /etc/rc.d/rc.local
 38     echo "iptables-restore < /etc/sysconfig/iptables" >>/etc/rc.d/rc.local
 39     
 40     sed -i 's/SELINUX=.*$/SELINUX=disabled/g' /etc/sysconfig/selinux &>/dev/null    #centos7
 41     sed -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 
 48 systemconfig()
 49 {
 50     #修改系统语言 需要为英文
 51     sed -i 's/^LANG=.*$/LANG="en_US.UTF-8"/g' /etc/locale.conf
 52     
 53     #修改时区相差八小时问题
 54     ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 55     
 56     #ssh登陆慢
 57     sed -i '/^UseDNS/d' /etc/ssh/sshd_config
 58     sed -i '/^#UseDNS/a\UseDNS no' /etc/ssh/sshd_config
 59     sed -i '/^GSSAPIAuthentication/d' /etc/ssh/sshd_config
 60     sed -i '/^#GSSAPIAuthentication/a\GSSAPIAuthentication no' /etc/ssh/sshd_config
 61     systemctl restart sshd
 62     
 63     #配置DNS服务器
 64     echo "nameserver 114.114.114.114"  >/etc/resolv.conf
 65     
 66     #修改history相关属性
 67     mkdir -p /etc/profile.d
 68     
 69     echo "
 70 PS1='\[\033[01;35m\][\u@\h \w]\\\$ \[\033[00m\]'
 71 HISTSIZE=1000000
 72 
 73 mkdir -p /root/.history
 74 HISTFILE=/root/.history/history_\`echo \$SSH_CLIENT | cut -d' ' -f1\`
 75 HISTTIMEFORMAT=\"[%F %T] \"
 76 export 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 
 88 vimconfig()
 89 {
 90     touch ~/.vimrc
 91     
 92     echo "
 93 set nocompatible
 94 set backspace=indent,eol,start
 95 \"\"set backup
 96 syntax on
 97 set hlsearch
 98 filetype plugin on
 99 set ruler
100 set ts=4
101 set sw=4
102 set shiftwidth=4
103 set softtabstop=4
104 set nu
105 set autoindent
106 \"\"set textwidth=200
107 set noexpandtab
108 set encoding=utf-8
109 set fileencoding=utf-8
110 set fileencodings=ucs-bom,utf-8,chinese
111 set modeline
112 set t_vb=
113 " > ~/.vimrc
114 
115 }
116 
117 gitconfig()
118 {
119     touch ~/.gitconfig
120     
121     echo "
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 
141     ls = 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 
169 yumconfig()
170 {
171     sed -i 's!cachedir=.*$!cachedir=/opt/yum/!g' /etc/yum.conf
172     sed -i 's/^keepcache=.*$/keepcache=1/g' /etc/yum.conf
173     sed -i 's/^gpgcheck=.*$/gpgcheck=0/g' /etc/yum.conf
174     sed -i 's/^plugins=.*$/plugins=0/g' /etc/yum.conf
175     sed -i 's/^enabled=.*$/enabled=0/g' /etc/yum/pluginconf.d/fastestmirror.conf
176     
177     mkdir -p /etc/yum.repos.d/
178     rm -rf /etc/yum.repos.d/*
179 
180     echo "
181 [base]
182 name=Base
183 baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
184 enabled=1
185 
186 [epel]
187 name=epel
188 baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
189 enabled=1
190 
191 [extra]
192 name=extra
193 baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/
194 enabled=0
195 
196 [docker]
197 name=docker
198 baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
199 enabled=0
200 
201 [svn]
202 name=svn
203 baseurl=http://opensource.wandisco.com/centos/7/svn-1.11/RPMS/
204 enabled=0
205 
206 [gitlab]
207 name=gitlab-ee
208 baseurl=https://packages.gitlab.com/gitlab/gitlab-ee/el/7/x86_64/
209 enabled=0
210 
211 [intel]
212 name=intel
213 baseurl=https://download.01.org/QAT/repo
214 enabled=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 
231 echo -n "[INFO] Are you sure to excute this script now?[yes/no]: "
232 yesnoinput
233 
234 if [ "$?" -ne 0 ]; then
235     echo "Exit script!"
236     exit 1
237 fi
238 
239 iptablesconfig
240 systemconfig
241 vimconfig
242 gitconfig
243 yumconfig

 

posted @ 2020-10-16 00:21  charseki  阅读(202)  评论(0编辑  收藏  举报