Linux 實現自動安裝服務元件以及優化核心引數
安裝好Linux裸機後(安裝請參考:http://blog.itpub.net/26230597/viewspace-1380155/),還需要在其上安裝一些基礎元件,一般是手動一個個安裝,比較繁複也許會遺漏,下面整理了下,做成一個指令碼,每次run下這個指令碼就完成了基礎元件的安裝了,並且附帶優化了Linux的核心引數。
1,先配置網路,check配置為最原始的狀態
[root@wgq_idc_web_1_50 ~]# more ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=de8199bd-d18e-45d4-85a0-7cbeb1d693f2
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
HWADDR=00:0C:29:BF:E2:AB
[root@wgq_idc_web_1_50 ~]#
手動配置網路服務:
ifconfig eth0 1xx.2xx.1.50 netmask 255.255.255.0
route add default gw 1xx.2xx.1.1
service network restart
2,設定初始化域名
[root@wgq-web-1-50 ~]# more /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
[root@wgq-web-1-50 ~]#
3,編寫初始化安裝指令碼
[root@wgq_idc_web_1_50 ~]# vim init_app_shell.sh
#!/bin/bash
#IP GATEWAY parameters
if [ $# != 3 ]
then
echo "USAGE: $0 IPADDR GATEWAY HostName"
echo "eg: $0 1xx.2xx.1.12 1xx.2xx.1.1 wgq_idc_mon_1_12"
exit 1
fi
#hostname configuration,注意sed後面帶變數的話,不能用'符號,因為會解析不了$3變數值。
hostname $3
sed -i "s/HOSTNAME=localhost.localdomain/HOSTNAME=$3/g" /etc/sysconfig/network
#chkconfig
yum install -y chkconfig
#stop services
chkconfig --list |grep ":on" |awk '{print $1}' > /tmp/allonservice.txt
for i in `cat /tmp/allonservice.txt`
do
chkconfig $i off
done
for k in NetworkManager crond messagebus network rsyslog sshd
do
chkconfig $k on
done
#network configuration
grep "DNS1" /etc/sysconfig/network-scripts/ifcfg-eth0
if [ $? != 0 ]
then
cat <
IPADDR=$1
NETMASK=255.255.255.0
GATEWAY=$2
DNS1=2xx.1xx.136.10
EOF
fi
sed -i 's/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart
#set nameserver
cat <
nameserver $4
EOF
#selinux disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/id:5:initdefault:/id:3:initdefault:/g' /etc/inittab
#kernel optimization
grep "net.ipv4.tcp_keepalive_time = 30" /etc/sysctl.conf
if [ $? != 0 ]
then
cat <
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
EOF
sed -i 's/net.bridge.bridge-nf-call-ip6tables = 0/#net.bridge.bridge-nf-call-ip6tables = 0/g' /etc/sysctl.conf
sed -i 's/net.bridge.bridge-nf-call-iptables = 0/#net.bridge.bridge-nf-call-iptables = 0/g' /etc/sysctl.conf
sed -i 's/net.bridge.bridge-nf-call-arptables = 0/#net.bridge.bridge-nf-call-arptables = 0/g' /etc/sysctl.conf
fi
sysctl -p
#epel yum source configuration
if [ ! -d /soft ]
then
mkdir /soft
fi
cd /soft
rpm -ivh epel-release-6-8.noarch.rpm && rm -rf epel-release-6-8.noarch.rpm
sed -i 's/#baseurl=/baseurl=/g' /etc/yum.repos.d/epel.repo
sed -i 's/irrorlist=/#irrorlist=/g' /etc/yum.repos.d/epel.repo
yum clean all
yum makecache
#system basic lib package install
yum install gcc gcc-c++ ncurses-devel.x86_64 cmake.x86_64 libaio.x86_64 bison.x86_64 gcc-c++.x86_64 bind-utils wget curl curl-devel perl openssh-clients setuptool sysstat -y
# restart the linux server
reboot
[root@wgq_idc_web_1_50 ~]#
4,環境準備
(1),去http://pan.baidu.com/s/1qWodCQg下載epel-release-6-8.noarch.rpm(對應centos下載相應的安裝包),放到/soft/目錄
(2),注意域名是初始化的,如果手動修改過了,建議改成原始的localhost.localdomain。
5,執行指令碼開始初始化安裝
開始執行,4個引數,P1:虛擬機器ip地址;P2
sh init_app_shell.sh 1xx.2xx.1.50 1xx.2xx.1.1 wgq_idc_web_1_50 202.xxx.xxx.64
6,除錯中一些報錯資訊記錄
(1),yum install gcc*報錯:
PYCURL ERROR - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo:base
需要新增路由
route add default gw 192.168.180.255
或者
route add add -net 0.0.0.0 gw 1xx.2xx.1.1
(2),yum安裝報錯 :
Error Downloading Packages:
grep-2.6.3-6.el6.x86_64: failure: Packages/grep-2.6.3-6.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
缺少dns,新增dns:
[root@wgq_idc_squid_1_11 ~]# vim /etc/resolv.conf
nameserver 2xx.1xx.136.10
重啟服務
ifconfig eth0 1xx.2xx.1.50 netmask 255.255.255.0
route add default gw 1xx.2xx.1.1
service network restart
(3),Error: Cannot find a valid baseurl for repo:base
需要安裝
yum install chkconfig
yum install greo -y
----------------------------------------------------------------------------------------------------------------
有,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!>
原部落格地址: http://blog.itpub.net/26230597/viewspace-1384144/
原作者:黃杉 (mchdba)
----------------------------------------------------------------------------------------------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26230597/viewspace-1384144/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux 核心引數優化(for oracle)Linux優化Oracle
- linux核心引數優化重要項Linux優化
- linux下安裝oracle的個別優化引數LinuxOracle優化
- Linux核心優化之TCP相關引數Linux優化TCP
- Linux核心引數以及Oracle引數調整(updated)LinuxOracle
- Linux核心引數調優Linux
- PXE實現系統自動化安裝
- ORACLE安裝核心引數配置_linux平臺OracleLinux
- oracle安裝linux時的核心引數解釋OracleLinux
- swoole優化核心引數調整優化
- linux核心啟動引數Linux
- 自動批量對linux伺服器安裝配置NTP服務Linux伺服器
- 鈑金件如何實現自動引數化設計
- Linux系統優化部分核心引數調優中文註釋Linux優化
- Cobbler實現自動化安裝作業系統作業系統
- Spring Boot 自動配置的原理、核心註解以及利用自動配置實現了自定義 Starter 元件Spring Boot元件
- Mac與Linux實現多種方式安裝Redis服務MacLinuxRedis
- 優化Linux核心引數提高伺服器負載能力優化Linux伺服器負載
- Google 雲服務搭建 git服務,實現Hexo自動部署GoGitHexo
- Linux核心調優部分引數說明Linux
- linux核心引數最佳化(七)Linux
- linux核心引數最佳化1Linux
- linux 安裝git服務LinuxGit
- mPaaS 服務端核心元件:移動分析服務 MAS 架構解析服務端元件架構
- mPaaS 服務端核心元件:移動同步服務 MSS 架構解析服務端元件架構
- 13、nginx服務叢集搭建以及優化Nginx優化
- Linux安裝SVN實現自動同步到Web目錄LinuxWeb
- 認識Tomcat核心元件及其啟動引數Tomcat元件
- Web自動化——介紹與安裝以及第一個web自動化程式(一)Web
- statspack 安裝以及相關引數說明
- linux 核心引數Linux
- Linux核心引數Linux
- 安裝oracle時核心引數的含義Oracle
- Linux 安裝Mosquitto服務LinuxUI
- iOS 元件化開發(四):fastlane實現pod自動化iOS元件化AST
- 通過自動化和現代化實現網路優化優化
- 華為工單寶:助力製造業實現數字化轉型,透過專案管理實現售後服務自動化專案管理
- 安裝ORACLE時在Linux上設定核心引數的含義OracleLinux