Centos6.5下安装Python3.5

自带的是2.6的,已经不能满足需要了。

1、准备环境

yum groupinstall 'Development Tools'
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel readline-devel -y  #最后这个模块如果没有,解释器里方向键和退格将不能用。
 

- 阅读剩余部分 -

CentOS6.x最小化安装初始脚本

上次分享了《CentOS6.5最小化安装后的简单调优配置》,估计大家看了都嫌麻烦,其实旨在记录并说明,生产环境下装好系统后,一个脚本完成这些繁琐的设置才是我们要的,我知道大家都是懒癌晚期。。。

脚本如下:

#!/bin/bash
cat << EOF
+---------------------------------------------------------------------------+
| Initialize for the CentOS 6_installed. |
+---------------------------------------------------------------------------+
EOF
function format() {
 #sleep 1
 #echo -e "\033[42;37m ########### Finished ########### \033[0m\n"
 echo -e "\033[32m Install Success!!!\033[0m\n"
}
##########################################################################
# Create Log 创建该脚本运行记录日志
echo "Create log file."
DATE1=`date +"%F %H:%M"`
LOG=/var/log/sysinitinfo.log
echo $DATE1 >> $LOG
echo "------------------------------------------" >> $LOG
format
##########################################################################
# 更换yum源为阿里云镜像
echo "Install epel"
yum install -y wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum makecache &> /dev/null
format
##########################################################################
# Yum update bash and openssl 升级bash/openssl
echo "Update bash and openssl"
yum -y update bash openssl &> /dev/null
format
##########################################################################
#Yum install Development tools 安装开发包组及必备软件
echo "Install Development tools(It will be a moment)"
yum groupinstall -y "Development tools" &> /dev/null
yum install -y bind-utils lrzsz wget gcc gcc-c++ vim htop openssl &>/dev/null
format
##########################################################################
# Set time 时区/时间同步设置
yum -y install ntpdate
echo "* 4 * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1" >> /var/spool/cron/root
service crond restart
format
##########################################################################
# Disabled Selinux 禁用Selinux
echo "Disabled SELinux."
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
format
###########################################################################
# Stop iptables 禁用iptables
echo "Stop iptables."
service iptables stop &> /dev/null
chkconfig --level 235 iptables off
format
###########################################################################
# Disable ipv6 禁用IPV6
echo "Disable ipv6."
cat << EOF > /etc/modprobe.conf
alias net-pf-10 off
alias ipv6 off
EOF
chkconfig --level 2235 ip6tables off
format
###########################################################################
# Set ssh 设置ssh登录策略
echo "Set sshd."
sed -i "s/^#PermitEmptyPasswords/PermitEmptyPasswords/" /etc/ssh/sshd_config
sed -i "s/^#LoginGraceTime 2m/LoginGraceTime 6m/" /etc/ssh/sshd_config
grep "UseDNS no" /etc/ssh/sshd_config &>/dev/null
if [ $? -ne 0 ]
then
 echo "UseDNS no" >> /etc/ssh/sshd_config
fi
format
###########################################################################
#echo "Tunoff services." 服务调整
for i in `ls /etc/rc3.d/S*`
do
 servers=`echo $i|cut -c 15-`
 echo $servers
 case $servers in crond | irqbalance | microcode_ctl | network | random | postfix | sshd | rsyslog | local | smart | cpuspeed | mysqld | httpd | ntpd | php-fpm | nginx)
 echo -e "\033[31m Base services, Skip!\033[0m"
 ;;
 *)
 echo -e "\033[31m change $servers to off\033[0m"
 chkconfig --level 235 $servers off
 service $servers stop
 ;;
esac
done
format
###########################################################################
# Del unnecessary users 删除不必要的用户
echo "Del unnecessary users."
for USERS in adm lp sync shutdown halt mail news uucp operator games gopher
do
 grep $USERS /etc/passwd &>/dev/null
 if [ $? -eq 0 ]
 then
 userdel $USERS &> /dev/null
 fi
done
format
###########################################################################
# Del unnecessary groups 删除不必要的用户组
echo "Del unnecessary groups."
for GRP in adm lp mail news uucp games gopher mailnull floppy dip pppusers popusers slipusers daemon
do
 grep $GRP /etc/group &> /dev/null
 if [ $? -eq 0 ]
 then
 groupdel $GRP &> /dev/null
 fi
done
format
###########################################################################
# Disabled reboot by keys ctlaltdelete 禁用ctlaltdelete重启功能
echo "Disabled reboot by keys ctlaltdelete"
sed -i 's/^exec/#exec/' /etc/init/control-alt-delete.conf
format
###########################################################################
# Set ulimit 设置文件句柄数
echo "Set ulimit 65535"
cat << EOF > /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
EOF
echo "ulimit -SH 65535" >> /etc/rc.local 
#sed -i 's/102400/1000000/' /etc/security/limits.d/90-nproc.conf
format
###########################################################################
# Set login message 设置登录时显示的信息
#echo "Set login message."
#echo "This is not a public Server" > /etc/issue
#echo "This is not a public Server" > /etc/redhat-release
#format
###########################################################################
# Set sysctl.conf 设置内核参数
echo "Set sysctl.conf"
#可用于apache,nginx,squid多种等web应用
cat << EOF > /etc/sysctl.conf
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 65535
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 26843545
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
EOF
/sbin/sysctl -p > /dev/null
format

保存为xxx.sh,执行sh xxx.sh即可。
完整下载:centos6初始化脚本

CentOS6.5最小化安装后的简单调优配置

很长时间没有安装centos了,今天公司又托管了一台服务器,安装时发现记忆有些本来记的很牢的东西已经有点模糊了,时间真是个可怕的东西。

记录整理下安装配置过程,备忘吧。

系统选择的是的centos 6.5x64,据说各大互联网公司几乎都在用这个版本,我们也用吧。最小化安装然后自己选包,可能有些有洁癖的同学会说,干嘛要选包,我就是要mini安装,爱折腾,任性!好吧,我表示我选的都是我要用的。

1

2

34

如图,一共600个包。当然,没有哪个包是必须的,只是这些都是我要的,web服务的生产环境一般都会用的到。

装好后,开始配置吧。

1,配置网络

默认安装后是dhcp,每次开机都会自动获取1个随机的IP,这当然不是我要的,手动配置。

vi /etc/sysconfig/network-scripts/ifcfg-eth0

11

注意ONBOOT=yes 是开机启动,默认是no,改之!改好后:wq保存退出。

重启网卡使之生效。

/etc/init.d/network restart

12

ifconfig查看一下,没问题就OK了。

2,更新yum源

阿里云、网易、新浪等等都有提供镜像,任选,我这里选阿里云的了。

[root@web ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@web ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@web ~]# yum makecache

这里顺手更新一下系统补丁,因为一旦应用后,一般就不会再考虑升级了,所以这个时候把补丁打一下。

yum update (注意这个不会升级内核,不会升级版本,比如6.5-6.6这样,和yum upgrade要区分一下)

3,关闭selinux

这货在我印象里就完全没用,至于到底有什么用,也不清楚,反正做web应用的,这货绝对可以咔嚓掉!

sed –i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

不放心就再cat /etc/selinux/config一下。

setenforce 0

让修改立即生效,这个不做也没事,因为是全新安装,稍后会重启一次。

4,调整文件描述符大小

这里我们参照阿里云的设置,相信是没错的。vi /etc/security/limits.conf,在最后加上。

* soft noproc 65535
* hard noproc 65535
* soft nofile 65535
* hard nofile 65535

5,内核优化

#可用于apache,nginx,squid多种等web应用
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535


#以下参数是对centos6.x的iptables防火墙的优化,防火墙不开会有提示,可以忽略不理。
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120

/sbin/sysctl -p 使之立即生效。其实这个还是习惯脚本实现。

还有更改用户,限制root登录,修改ssh端口等一些安全设置就不写了。酌情处理吧。

CentOS最小化安装后没有wget的解决办法

准备学Python了,今天虚拟机装了个Centos,以前都是自己选包的,因为只用到Python,就选了个mini安装,好吧,结果各种坑啊。

准备更换下yum源然后更新下python到2.7,Centos6.4自带的是2.6.6,竟然没有wget,好吧,那就yum install wget,竟然提示没有可用的源。

什么鬼?更新一下先,

#yum update

#yum -y install wget

还是不行,看来是yum源里就没有wget,不科学嘛!手动换源!个人比较习惯用阿里云的yum源,下载后,winscp上传至/etc/yum.repos.d/,注意备份下原文件(这只是个好习惯而已,原来难的源连wget都没,真心没啥好保留的),重新执行!

#yum  clean  all 
#yum -y install  wget

OK,大功告成!

顺手再更新下,# yum update && yum upgrade,

Complete!
已加载插件:fastestmirror
设置升级进程
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com

可以看到yum源已经更换成阿里云的了。

python的升级过程就不写了,百度大把,提醒下自己和各位,生产环境下的Centos安装,最好是自己选包,适合自己的才是最好的!