首頁 > 資訊科技 > CentOS > Centos7 設定篇-自動安裝懶人腳本
2016
04-29

Centos7 設定篇-自動安裝懶人腳本

環境設定篇........

 

腳本如下:

自動更新 Kernel 到 4.5
安裝 apache, PHP7, MariaDB.......

#!/bin/bash
SSH_PORT=22
localectl set-locale LANG=zh_TW.UTF-8
export PS1="\e[1;34m\u@\h \w> \e[m"
yum -y update
yum -y upgrade
yum install  -y yum-cron
sed -i 's/apply_updates = no/apply_updates = yes/g' /etc/yum/yum-cron.conf
systemctl start crond
systemctl start yum-cron
yum install -y net-tools wget unzip vim-enhanced p7zip p7zip-plugins yum-cron screen telnet git axel gcc iptables-services yum-utils ntp
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum -y install http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel -y install kernel-ml
sed -i '/saved_entry=/c \saved_entry=CentOS Linux (4.5.0-1.el7.elrepo.x86_64) 7 (Core)' /boot/grub2/grubenv
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port '$SSH_PORT'/' /etc/ssh/sshd_config
#修改本機 tty console (使用網路 SSH 來連,不需開太多的 Console 端)
echo 'ACTIVE_CONSOLES=/dev/tty[1-2]' >> /etc/sysconfig/init
service sshd restart >/dev/null 2>&1
echo "unset MAILCHECK" >> /etc/profile
#disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#disable services
systemctl stop firewalld
systemctl disable firewalld
#systemctl restart iptables.service
#systemctl enable iptables.service
chkconfig ip6tables off
chkconfig lvm2-monitor off
chkconfig mdmonitor off
chkconfig messagebus off
# setting starup timeout
sed -i 's/timeout=.*/timeout=1/' /etc/grub2.cfg
sed -i 's/timeout=.*/timeout=1/' /boot/grub2/grub.cfg
# setting ntp server
echo "ntpdate time.stdtime.gov.tw > /dev/null &" >> /etc/rc.local
cat >> /etc/sysconfig/network <<EOT
NETWORKING=yes
NETWORKING_IPV6=no
GATEWAY=x.x.x.x
EOT
cat >> /etc/sysctl.conf <<EOT
net.ipv4.ip_forward = 1
net.ipv4.tcp_keepalive_time = 86400
net.ipv4.tcp_syncookies = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_max_syn_backlog = 819200
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.core.rmem_default = 256960
net.core.rmem_max = 256960
net.core.wmem_default = 256960
net.core.wmem_max = 256960
net.core.netdev_max_backlog = 819200
net.core.somaxconn = 65535
kernel.shmmax = 17179869184
kernel.shmall = 4194304
EOT
cat >> /etc/vimrc <<EOT
set encoding=utf-8
set fileencodings=utf-8,cp950
syntax on
set nocompatible
set ai
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set number
set ruler
set backspace=2
set ic
set ru
set hlsearch
set incsearch
set smartindent
set confirm
set history=100
set cursorline
set laststatus=2
set statusline=%4*%<\%m%<[%f\%r%h%w]\ [%{&ff},%{&fileencoding},%Y]%=\[Position=%l,%v,%p%%]
colorscheme torte
EOT
sysctl -p
service network restart
chmod +x /etc/rc.d/rc.local
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
sed -i 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel.repo
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# Install fail2ban 
yum install fail2ban -y
# Install MariaDB
cat >> /etc/yum.repos.d/MariaDB.repo <<EOT
# MariaDB 10.0 CentOS repository list - created 2015-04-01 14:52 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOT
yum install -y MariaDB-server MariaDB-client
sed -i '/\[client\]/a\default-character-set=utf8' /etc/my.cnf.d/client.cnf
sed -i '/\[mysqld\]/a\character-set-server=utf8' /etc/my.cnf.d/server.cnf
sed -i '/\[mysqld\]/a\innodb_file_per_table = 1' /etc/my.cnf.d/server.cnf
systemctl restart mariadb
sed -i '/#ServerName www.example.com:80/a\ServerName localhost:80' /etc/httpd/conf/httpd.conf
systemctl start httpd
systemctl enable httpd
rpm -ivh http://copr-be.cloud.fedoraproject.org/results/nibbler/mydumper/epel-7-x86_64/mydumper-0.6.1-1.r144.fc20/mydumper-0.6.1-1.r144.el7.x86_64.rpm
/usr/bin/mysql -e "UPDATE mysql.user SET password=password('123456') WHERE user='root';"
/usr/bin/mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION; FLUSH PRIVILEGES;"
# install php
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum install -y --skip-broken php70w php70w-opcache php70w-bcmath php70w-cli php70w-mysql php70w-fpm php70w-gd php70w-ldap php70w-odbc php70w-pear php70w-xml php70w-xmlrpc php70w-mbstring php70w-snmp php70w-soap curl curl-devel php70w-common php70w-dba php70w-pdo  php70w-pecl-zendopcache
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/f/freetds-0.95.81-1.el7.x86_64.rpm
sed  -i 's/\[egServer50\]/[SYBASE]/g' /etc/freetds.conf
sed  -i 's/symachine.domain.com/192.168.10.3/g' /etc/freetds.conf
yum install -y php70w-mssql
sed -i '/date.timezone =/a\date.timezone = "Asia/Taipei"' /etc/php.ini
sed -i 's/short_open_tag =Off/short_open_tag = On/g' /etc/php.ini  
systemctl restart httpd

 

最後修改日:
作者:蔡 小翰

常見問題:

  1. 文章可以轉貼嗎?可以,不過請要註明出處並標示本站連結。
  2. 載點可以轉貼嗎?可以,歡迎隨意盜連,無須告知。
  3. 反盜版聲明:本站支持正版軟體,請勿討論破解版、快樂版、註冊碼、註冊機、序號...等違法主題。
  4. 檔案無法解壓縮或解壓縮時發生錯誤?請使用7-Zip解壓縮
  5. 更多細節請參閱使用條款及免責聲明


發表迴響