Linux 实现自动安装服务组件以及优化内核参数 (转)
2016-09-08 17:08
465 查看
安装好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 <<EOF>> /etc/sysconfig/network-scripts/ifcfg-eth0
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 <<EOF>> /etc/resolv.conf
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 <<EOF>> /etc/sysctl.conf
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
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 <<EOF>> /etc/sysconfig/network-scripts/ifcfg-eth0
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 <<EOF>> /etc/resolv.conf
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 <<EOF>> /etc/sysctl.conf
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
相关文章推荐
- Linux 实现自动安装服务组件以及优化内核参数
- linux下nginx服务应用总结(2)--突破10万高并发的nginx性能优化经验(含内核参数优化)
- 五、优化Linux内核参数【LNMP安装 】
- linux下SVN配置实现项目目录自动更新以及源码安装
- InstallShield中IIS服务的检测和组件自动安装的实现
- linux下nginx服务应用总结--突破10万高并发的nginx性能优化经验(含内核参数优化
- linux下SVN配置实现项目目录自动更新以及源码安装的操作方法
- Linux系统最小化安装之后的系统基础环境安装以及内核优化脚本
- [置顶] 编写shell脚本以及利用函数实现批量安装Linux服务配置
- linux 下安装Oracle 自动设置sysctl.conf 相关内核参数的脚本
- CentOS 5.2,Linux 2.6+ 内核 ,Apache+MySQL+PHP 安装及基本配置过程记录 && 将apache安装为系统服务
- shell脚本实现linux下自动安装Oracle10g
- 利用PHP安装windows自动运行的服务,PHP程序可以实现长时间、自动运行、定时更新功能,直接可以用在项目中的类源代码
- Kickstart+HTTP+DHCP+TFTP+PXElinux实现RedHat的网络自动安装
- Linux下安装Oracle参数自动初始化脚本
- 【转】优化Linux内核参数
- Linux内核编译以及perfctr模块安装
- nagios监控linux主机、web等各种服务,并实现飞信自动报警
- Linux 系统内核参数 sysctl.conf优化方案
- Linux系统优化部分内核参数调优中文注释