#!/bin/bash
echo "-----只用於新購伺服器初始化,有需要的自己可以寫進去-----"
echo "-----只用於centos7.0版本---------------"
echo "-----其他版本差異,可以自行修改------"
read -p "是否繼續 y/n": yn
if [ $yn != y ];then
exit 3
fi#檢視系統版本
linux_release=`cat /etc/redhat-release`
release_centos6="release 6."
release_centos7="release 7."
#關閉防火牆並禁止開機自啟
if [[ $linux_release =~ $release_centos7 ]];then
systemctl stop firewalld.service && systemctl disable firewalld.service
elif [[ $linux_release =~ $release_centos6 ]];then
service iptables stop && chkconfig iptables off
fi#關閉核心機制
#sed -i 's/selinux=enforcing/selinux=disabled/' /etc/sysconfig/selinux && setenforce 0
if [[ $linux_release =~ $release_centos6 ]];then
sed -i 's/selinux=enforcing/selinux=disabled/' /etc/sysconfig/selinux
elif [[ $linux_release =~ $release_centos7 ]];then
sed -i "s#selinux=enforcing#selinux=disabled#g" /etc/selinux/config
fi#安裝初始工具
yum install gcc* gcc-* zlib-devel pcre-devel openssh-clients net-tools ntp rsync -y
#修改ssh預設埠
netstat -anpt | grep 22
if [ $? = 0 ];then
sed -i 's/#port 22/port 12022/' /etc/ssh/sshd_config
if [[ $linux_release =~ $release_centos7 ]];then
systemctl restart sshd
elif [[ $linux_release =~ $release_centos6 ]];then
service sshd restart
fifi
#獲取ip位址 (centos7版本網絡卡預設是ens33 阿里雲已更改為eth,請根據實際更改)更改主機名
ip=$(ip add | grep -w "inet" | grep eth0 |sed 's/^.*inet //g'|sed 's/\/[0-9][0-9].*$//g')
name=$(echo $ip|awk -f"." '')
if [[ $linux_release =~ $release_centos6 ]];then
sed -i "/hostname=*/c hostname=aliyun.$" /etc/sysconfig/network
elif [[ $linux_release =~ $release_centos7 ]];then
hostnamectl set-hostname aliyun$
fi#安裝zabbix-agent
wget && bash add_zabbix.sh
#建立普通使用者web
user=`cat /etc/passwd |awk -f: ''|grep web`
if [ -z $ ];then
useradd web
fi#設定密碼
passwd web << eof
ajdw**x8z
ajdw**x8z
eof#判斷/home/web目錄是否存在
if [ ! -d "/home/web" ]; then
/bin/mkdir /home/web/
chown -r web:web /home/web/
else
chown -r web:web /home/web/
fi#判斷/home/web/.ssh目錄是否存在,不存在則建立
if [ ! -d "/home/web/.ssh" ]; then
/bin/mkdir /home/web/.ssh
chown -r web:web /home/web/.ssh
fi#判斷/home/web/.ssh/authorized_keys目錄是否存在,不存在則建立
if [ ! -f "/home/web/.ssh/authorized_keys" ]; then
/bin/touch /home/web/.ssh/authorized_keys
/bin/chmod 600 /home/web/.ssh/authorized_keys
else
/bin/chmod 600 /home/web/.ssh/authorized_keys
fi#把zabbix伺服器上的web使用者的key追加到認證檔案中
/bin/grep web@zabbix /home/web/.ssh/authorized_keys || echo "ssh-rsa ******xx web@zabbix" >> /home/web/.ssh/authorized_keys
#建立讀取日誌使用者
user=readlog
/bin/grep $ /etc/passwd || useradd $
#設定readlog使用者密碼
passwd $ << eof
maqglc2mqz
maqglc2mqz
eof#判斷/home/readlog/.ssh目錄是否存在,不存在則建立
if [ ! -d "/home/$/.ssh" ]; then
/bin/mkdir "/home/$/.ssh"
fi#判斷/home/web/.ssh/authorized_keys目錄是否存在,不存在則建立
if [ ! -f "/home/$/.ssh/authorized_keys" ]; then
/bin/touch /home/$/.ssh/authorized_keys
chown -r $:$ /home/$/.ssh/
/bin/chmod 600 /home/$/.ssh/authorized_keys
fi#把zabbix伺服器上的readlog使用者的key追加到認證檔案中
/bin/grep $@zabbix /home/$/.ssh/authorized_keys || echo "ssh-rsa ******x readlog@zabbix" >> /home/$/.ssh/authorized_keys
#判斷/root/.ssh目錄是否存在,不存在則建立
if [ ! -d "/root/.ssh" ]; then
/bin/mkdir "/root/.ssh"
fi#判斷/root/.ssh/authorized_keys目錄是否存在,不存在則建立
if [ ! -f "/root/.ssh/authorized_keys" ]; then
/bin/touch /root/.ssh/authorized_keys
/bin/chmod 600 /root/.ssh/authorized_keys
fi#把zabbix伺服器上的root使用者的key追加到認證檔案中
/bin/grep root@zabbix /root/.ssh/authorized_keys || echo "ssh-rsa ************ root@zabbix" >> /root/.ssh/authorized_keys
echo "建立基礎應用目錄"
mkdir -pv /opt/deploy/tomcat
mkdir -pv /opt/deploy/service
mkdir -pv /opt/deploy/repository
mkdir -pv /opt/logs/service
mkdir -pv /opt/logs/tomcat
chown -r web.web /opt
#休眠三十秒,重啟系統
sleep 10
shutdown -r now
LINUX 系統初始化指令碼
bin bash the system first start configuretion for install copy right by donglei 1 配置sysctl mv etc sysctl.conf etc sysctl.bak echo the new config for s...
centos7初始化指令碼
centos7初始化指令碼 新裝的虛擬機器或者linux伺服器的初始化指令碼 功能 永久關閉防火牆,selinux 安裝常用工具 配置靜態ip位址 配置阿里源 usr bin bash centos初始化指令碼 time 2020 04 01 防火牆設定 echo 關閉防火牆和selinux sys...
CentOS 7 6 初始化指令碼
自己安裝的系統,根據自己需求做一些統一的初始化設定 bin sh 更新系統 yum y update 安裝基礎軟體 yum y install net tools lrzsz wget vim 關閉防火牆 systemctl stop firewalld systemctl disable fire...