Linux之OVH cloud server CentOS 7 init

ovh cloud root用户登录方法

[admin@server-1 ~]$ sudo passwd root 修改root用户密码
[admin@server-1 ~]$ su - #输入上面设置的密码
[root@server-1 ~]# sed -ri 's/^(PasswordAuthentication ).*/\1yes/' /etc/ssh/sshd_config
[root@server-1 ~]# sed -ri 's/^#(PermitRootLogin yes)/\1/' /etc/ssh/sshd_config #修改配置文件
[root@server-1 ~]# sed -ri 's/^/#/;s/sleep 10"\s+/&\n/' /root/.ssh/authorized_keys
[root@server-1 ~]# systemctl restart sshd.service && exit ##然后重新登录就可以直接用root用户登录了

一键初始化

wget -4qO- onekey.sh/centos_init|bash

初始化脚本适用CentOS6 7

#!/bin/bash
#########################################################################
# File Name: ovh_CentOS_6_init.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: Thu 16 Jul 2015 08:35:58 PM CST
#########################################################################

if [ $(id -u) != "0" ]; then
	echo "Please use the root user to run this script."
	exit 1
fi

checkOSinfo() {
	if [ -f /etc/centos-release ]; then 
		release=`awk '{print int(($3~/^[0-9]/?$3:$4))}' /etc/centos-release`
		OS=CentOS
	elif [ -f /etc/redhad-release ]; then 
		release=`awk '{print int(($3~/^[0-9]/?$3:$4))}' /etc/redhad-release`
		OS=RedHat
	elif [ -f /etc/os-release ]; then
		. /etc/os-release
		if [ "`awk '{print $1}' <<<$NAME`" = "Ubuntu" ]; then 
			release=`awk '{print int($1)}' <<<$VERSION_ID`
			OS=`awk '{print $1}' <<<$NAME`
		elif [ "`awk '{print $1}' <<<$NAME`" = "Debian" ]; then 
			release=$VERSION_ID
			OS=`awk '{print $1}' <<<$NAME`
		fi
	fi

	if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 32 ]; then
		BIT=32
	else
		BIT=64
	fi

	if [ "$OS" != "CentOS" -a "$OS" != "RedHat" ]; then
		echo "Your Server OS it's CentOS or RedHat"
		exit 1
	fi
}

setssh() {
	sed -ri 's/^(PasswordAuthentication).*/\1 yes/' /etc/ssh/sshd_config
	sed -ri 's/.*(PermitRootLogin).*/\1 yes/' /etc/ssh/sshd_config
	service sshd restart

	[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=--- /root/.ssh
	cat > /root/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhGitgDKxQidZXLHS3DFalTvmzTwQ4UH3etQJUE7/iPNwLs6ZDzbR5pqTPfK1YdhUTuJOoNQZ71Fr9qwLtF6aLdgO+ybmK/8sNrMeTvGmKyr4YQ5k02vVIbBnQIEr08eXpV1y206CMWQ7FiiMlFvaeFZhj8trchiffhAUJdZOjl/BikzDJcYdp/sRXrFA4G21yXU0ffOn9aAAvqOqRBRoDhpLnSWaovGjd419Cy/pdhu4Vuispz1x834l975fLv4PIh+3nW9WMbhrmIXzWoTsxnc8OUbT4FnRdA33G8T3JXQc1n1UjX7H4BGfzKA6eax574rspAk51cslaydby2vX
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCX6UoKH83dbzhVT5Zxz5EDgYdG4pWS5zlxpZovlOW/qS94FSNaV0qBcki858mkqHUXbjZK6cXxO1ZT786umW6J3jCkvjpPUSMNbXlvUfOapF72o/RBHv60D4fxaVk5zoeTuCC9h9ISq0sdyrDvDIdws/MPIYyLIiQMCEHltTccfK8CsP52wtkOKeZ5rSZMFi8x9zCPS4y07B5+x9+SdyatV6+gqPjeJrYo+d8e5azHuQGDraZZkIv8K+d7Xy93b5l/UByR7tfyviNhojEhuUmFucKBARglB3pPx9gvosecBltAOQzBgWuGb6TlGzMzQOUso5Qm6xN73eV4UdNWkOBP
EOF

}

addYUM() {
	if ! rpm -qa|grep epel >/dev/null 2>&1; then yum -y install epel*; fi
	if ! rpm -qa|grep rpmforge-release >/dev/null 2>&1; then
		if [ "$BIT" = "64" ]; then
			while true; do
				rpmURL=`curl -s http://repoforge.org/use/|awk -F'[ "><]+' '/rpmforge-release-/{for (i=1;i<=NF;i++)if ($i~/^http/)print $i}' | grep "el${release}.*64.rpm"`
				[ -n "$rpmURL" ] && break
			done
		else
			while true; do
				rpmURL=`curl -s http://repoforge.org/use/|awk -F'[ "><]+' '/rpmforge-release-/{for (i=1;i<=NF;i++)if ($i~/^http/)print $i}' | grep "el${release}.*86.rpm"`
				[ -n "$rpmURL" ] && break
				done
		fi
		yum -y install $rpmURL
	fi
}

updateYUM() {
	yum clean all && yum makecache
			yum -y install screen htop lshw vim tree bash-completion git xorg-x11-xauth xterm gettext axel tmux
		. /etc/bash_completion
	if [ "$release" = "6" ]; then
		yum -y groupinstall "Development tools" "Server Platform Development"
	elif [ "$release" = "7" ]; then
		yum -y groups install "Development Tools" "Server Platform Development"
	fi
}

changZHCN() {
	if [ "$release" = "6" ]; then
		yum groupinstall "Chinese Support" -y
		cat > /etc/sysconfig/i18n <<EOF
#LANG=C
#SYSFONT=latarcyrheb-sun16
LANG="zh_CN.UTF-8"
SYSFONT="latarcyrheb-sun16"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
EOF
	elif [ "$release" = "7" ]; then
		localectl set-locale LANG=zh_CN.utf8
		localectl set-keymap cn
		localectl set-x11-keymap cn
	fi
}

addBINscript() {
	[ -x /bin/systeminfo ] && break
	wget -cq http://www.dwhd.org/script/securityremove -O /bin/securityremove
	wget -cq http://www.dwhd.org/script/lsmod -O /bin/lsmod
	wget -cq http://www.dwhd.org/script/systeminfo -O /bin/systeminfo
	wget -cq http://www.dwhd.org/script/vim.tar.gz
	chmod +x /bin/{securityremove,lsmod,systeminfo}
	test -f /etc/bash.bashrc && sed -i "/securityremove/d" /etc/bash.bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bash.bashrc && . /etc/bash.bashrc
	test -f /etc/bashrc && sed -i "/securityremove/d" /etc/bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bashrc && . /etc/bashrc
	test -f /root/.bashrc && sed -i "/alias rm/d" /root/.bashrc && echo 'alias rm="/bin/securityremove"' >> /root/.bashrc && . /root/.bashrc
	echo 'alias ls="/bin/lsmod"' >> ~/.bashrc && . ~/.bashrc
	tar xf vim.tar.gz -C /root/ && /bin/rm -rf vim.tar.gz
	if ! grep "alias vi='vim'" /root/.bashrc &>/dev/null; then
		cat >> /root/.bashrc << EOF
alias vi='vim'
alias grep='grep --color=auto'
export VISUAL=vim
export EDITOR=vim
EOF
		sed -i 's/.*set hlsearch.*/"&/' /etc/vimrc
	fi
}

setPS1() {
	echo -e "\nunset MAILCHECK" >> /etc/profile
	echo "PS1='[\[\033[0;34m\]\u\[\033[0;37m\]@\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[0;37m\]]\[\033[0;31m\]\\$\[\033[00m\] '" >>/etc/profile
	echo "export PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date \"+%F %H:%M:%S\"):\$user:\`pwd\`/:\$msg ---- \$(who am i); } >> /tmp/\`date \"+%F\"\`.\`hostname\`.\`whoami\`.history-timestamp'" >> /etc/profile
}

setSELinux() {
	sed -i 's/^SELINUX=.*/#&/;s/^SELINUXTYPE=.*/#&/;/SELINUX=.*/a SELINUX=disabled' /etc/sysconfig/selinux && /usr/sbin/setenforce 0
}

iPython_install() {
	if which ipython >/dev/null 2>&1; then break;fi
	wget -cq http://www.dwhd.org/script/tar_gz_bz2/Python-2.7.10.tar.xz
	wget -cq http://www.dwhd.org/script/tar_gz_bz2/ipython-3.0.0.tar.gz
	yum install readline-devel sqlite-devel -y
	tar xf Python-2.7.10.tar.xz
	tar xf ipython-3.0.0.tar.gz
	cd Python-2.7.10/
	./configure --prefix=/usr/local/python2.7.10
	make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
	cd ../ipython-3.0.0/
	/usr/local/python2.7.10/bin/python2.7 setup.py build
	/usr/local/python2.7.10/bin/python2.7 setup.py install
	cd ..
	ln -sv /usr/local/python2.7.10/bin/ipython /usr/bin/
	ln -sv /usr/local/python2.7.10/bin/python2.7 /usr/bin/
	rm -rf Python-2.7.10* ipython-3.0.0* && clear
	ipython -c "print 'Hello, This is iPython print!'"
}

naliINSTALL() {
	if which nali >/dev/null 2>&1; then break;fi
	mkdir /tmp/src && cd /tmp/src
	wget -cq http://www.dwhd.org/wp-content/uploads/2015/08/nali-0.2.tar.gz
	tar xf nali-0.2.tar.gz && cd nali-0.2
	./configure && make && make install && nali-update
	cd ~ && /bin/rm -rf /tmp/src
}

#if ! which ipython >/dev/null 2>&1; then iPython_install;fi

setWGET() {
	mv /usr/share/locale/zh_CN/LC_MESSAGES/wget.{mo,mo.back}
	msgunfmt /usr/share/locale/zh_CN/LC_MESSAGES/wget.mo.back -o - | sed 's/eta(英国中部时间)/ETA/' | msgfmt - -o /usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
}


[ -f $0 ] && FunctionName=(`awk -F'[)( ]+' '/^([a-z]|[A-Z])+_?\w+\(\)\s\{/{print $1}' <<< $0`)

if [ "$?" != "0" ]; then
	#FunctionName=(checkOSinfo setssh addYUM updateYUM changZHCN addBINscript setPS1 setSELinux iPython_install naliINSTALL setWGET)
	FunctionName=(checkOSinfo setssh addYUM updateYUM changZHCN addBINscript setPS1 setSELinux naliINSTALL setWGET)
fi

for i in ${FunctionName[@]}; do
	$i
done

[ -x /bin/systeminfo ] && clear; systeminfo all
lookback
  • 本文由 发表于 2015年10月5日20:40:35
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: