版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32447301/article/details/82774699
1.docker.sh
docker安装
#!/usr/bin/env bash
yum install -y docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://fy707np5.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
2.htop.sh
查看进程安装
#!/usr/bin/env bash
yum install ncurses-devel
wget http://sourceforge.net/projects/htop/files/htop/1.0.2/htop-1.0.2.tar.gz
tar zxvf htop-1.0.2.tar.gz
cd htop-1.0.2
./configure --disable-unicode --prefix=/usr/local/htop
make
make install
ln -s /usr/local/htop/bin/htop /usr/local/bin/htop
3.jdk.sh
jdk1.8版本安装
#!/usr/bin/env bash
#install_jdk
wget http://7lrxhn.com1.z0.glb.clouddn.com/jdk-8u111-linux-x64.tar.gz
tar zxvf jdk-8u111-linux-x64.tar.gz
rm -rf jdk-8u111-linux-x64.tar.gz
mv jdk1.8.0_111 /usr/local/
ln -s /usr/local/jdk1.8.0_111/bin/java /usr/bin/java
echo -e "JAVA_HOME=/usr/local/jdk1.8.0_111;\nexport PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile
source /etc/profile
4.mysql57.sh
mysql5.7安装
#!/usr/bin/env bash
rpm -ivh http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm --force --nodeps
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
tar xvf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm --force --nodeps
#初始化密码
mysqld --initialize
cat /var/log/mysqld.log
#启动
systemctl start mysqld.service
mysql -u root -p
set password=password('123456');
5.nginx.sh
nginx反向代理负载均衡安装
#!/usr/bin/env bash
yum install -y zlib-devel
wget http://nginx.org/download/nginx-1.11.7.tar.gz
tar zxvf nginx-1.11.7.tar.gz
cd nginx-1.11.7
./configure --prefix=/usr/local/nginx --without-http_rewrite_module --without-http_gzip_module
make && make install
cd ..
rm -rf nginx*
echo "export PATH=\$PATH:/usr/local/nginx/sbin" >> /etc/profile
source /etc/profile
nginx
#开机启动
cat > /usr/lib/systemd/system/nginxd.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nginxd.service
6.redis.sh
redis缓存安装
#!/usr/bin/env bash
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
tar -zxvf redis-3.2.11.tar.gz
cd redis-3.2.11
make PREFIX=/usr/local/redis install
cp init_server/redis.conf /usr/local/redis/
#开机启动
cat > /usr/lib/systemd/system/redis.service <<EOF
[Unit]
Description=redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
[Install]
WantedBy=multi-user.target
EOF
systemctl enable redis.service
7.tomcat.sh
tomcat服务器安装
#install_tomcat
wget http://7lrxhn.com1.z0.glb.clouddn.com/apache-tomcat-8.5.14.tar.gz
tar zxvf apache-tomcat-8.5.14.tar.gz
rm -rf apache-tomcat-8.5.14.tar.gz
mv apache-tomcat-8.5.14 /usr/local/tomcat
#开机启动
cat > /etc/systemd/system/tomcat.service <<EOF
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/jdk1.8.0_101
Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/local/tomcat
Environment=CATALINA_BASE=/usr/local/tomcat
ExecStart=/usr/local/tomcat/bin/catalina.sh start
ExecStop=/bin/kill -15 $CATALINA_PID
[Install]
WantedBy=multi-user.target
EOF
systemctl enable tomcat.service
8.shadowsocks.sh
翻墙工具安装
wget --no-check-certificate -O shadowsocks.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh
chmod +x shadowsocks.sh
./shadowsocks.sh 2>&1 | tee shadowsocks.log
9.sync.sh
文件共享安装
#安装必要的软件包
yum -y install wget unzip
#下载脚本
wget https://github.com/helloxz/Resilio-Sync/archive/master.zip
#解压并安装
unzip master.zip && cd Resilio-Sync-master && chmod +x mysync.sh sync.sh && ./sync.sh
10.install_seafile.sh
网盘安装
yum -y install wget
wget https://raw.githubusercontent.com/helloxz/seafile/master/install_seafile.sh
chmod +x install_seafile.sh && ./install_seafile.sh
11.oneinstack.sh
搭建网站安装
yum -y install wget screen curl python #for CentOS/Redhat
wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz
tar xzf oneinstack-full.tar.gz
cd oneinstack
screen -S oneinstack
./install.sh
12.bbr.sh
google BBR 提高TCP传输速度
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
13.oracle.sh
oracle安装
注:如果安装Oracle_Linux,需要修改脚本中yum源的配置的公钥。
#!/bin/bash
# oracle 11g R2 for linux 安装辅助脚本
# Redkey
# version 1.2
# date 2013.08.27
#定义常量
SYSCTL=/etc/sysctl.conf
LIMITS=/etc/security/limits.conf
PAM=/etc/pam.d/login
PROFILE=/etc/profile
BASH_PROFILE=/home/oracle/.bash_profile
#循环变量
i=1
#定义显示颜色
#颜色定义 信息(33黄色) 警示(31红色) 过程(36浅蓝)
#判断执行用户是否root
isroot()
{
if [ $USER != "root" ];then
echo -e "\n\e[1;31m the user must be root,and now you user is $USER,please su to root. \e[0m"
exit4
else
echo -e "\n\e[1;36m check root ... OK! \e[0m"
fi
}
#挂在光盘到/mnt/cdrom目录下
mount_cdrom()
{
echo -e "\n\e[1;31m please insert RHEL to CDROM,press any key ...\e[0m"
read -n 1
if [ -d /mnt/cdrom ];then
mount -t auto -o ro /dev/cdrom /mnt/cdrom
else
mkdir -p /mnt/cdrom
mount -t auto -o ro /dev/cdrom /mnt/cdrom
fi
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m CDROM mount on /mnt/cdrom ... OK! \e[0m"
fi
}
#设置yum本地光盘源
yum_repo()
{
rm -rf /etc/yum.repos.d/* && cat <<EOF >> /etc/yum.repos.d/Server.repo
[Server]
name=MyRPM
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m /etc/yum.repos.d/Server.repo ... OK! \e[0m"
fi
}
#添加oracle用户,添加oracle用户所属组oinstall及附加组dba
ouseradd()
{
if [[ `grep "oracle" /etc/passwd` != "" ]];then
userdel -r oracle
fi
if [[ `grep "oinstall" /etc/group` = "" ]];then
groupadd oinstall
fi
if [[ `grep "dba" /etc/group` = "" ]];then
groupadd dba
fi
useradd oracle -g oinstall -G dba && echo $1 |passwd oracle --stdin
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m oracle's password updated successfully --- OK! \e[0m"
else
echo -e "\n\e[1;31m oracle's password set faild. --- NO!\e[0m"
fi
}
#检查oracle所需软件包并安装
packagecheck()
{
for package in binutils compat-libcap1 compat-libstdc++ gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat
do
rpm -q $package 2> /dev/null
if [ $? != 0 ];then
yum -y install $package
echo -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
fi
done
}
#安装桌面套件 X Window System / Desktop
xdesk()
{
LANG=C yum -y groupinstall "X Window System" "Desktop"
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
fi
}
# 设置内核参数
kernelset()
{
cp $SYSCTL{,.bak} && cat <<EOF >>$SYSCTL
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048575
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m kernel parameters updated successfully --- OK! \e[0m"
fi
sysctl -p
}
#设置oracle资源限制
oralimit()
{
cp $LIMITS{,.bak} && cat <<EOF >> $LIMITS
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $LIMITS updated successfully ... OK! \e[0m"
fi
}
#设置login文件
setlogin()
{
cp $PAM{,.bak} && cat <<EOF >>$PAM
session required pam_limits.so
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $PAM updated successfully ... OK! \e[0m"
fi
}
#设置profile文件
setprofile()
{
cp $PROFILE{,.bak} && cat <<EOF >>$PROFILE
if [ $USER = "oracle" ];then
if [ $SHELL = "/bin/ksh" ];then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $PROFILE updated successfully ... OK! \e[0m"
fi
}
#设置oracle的profile文件
setbash_profile()
{
cp $BASH_PROFILE{,.bak} && cat <<EOF >> $BASH_PROFILE
umask 022
ORACLE_BASE=$1
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_SID=$2
PATH=$ORACLE_HOME/bin/:$PATH
LANG=en_US.UTF-8
export ORACLE_BASE ORACLE_HOME ORACLE_SID
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $BASH_PROFILE updated successfully ... OK! \e[0m"
fi
. $BASH_PROFILE
}
#系统环境检查
oscheck()
{
#查看内存大小是否大于1G
echo -e "\n check MEM Size ..."
if [ `cat /proc/meminfo | grep MemTotal | awk '{print $2}'` -lt 1048576 ];then
echo -e "\n\e[1;33m Memory Small \e[0m"
exit 1
else
echo -e "\n\e[1;36m Memory checked PASS \e[0m"
fi
#查看tmp空间大小
echo -e "\n check tmpfs Size ..."
cp /etc/fstab{,.bak}
while true;do
if [ `df | awk '/tmpfs/ {print $2}'` -lt 1048576 ];then
echo -e "\n\e[1;33m tmpfs Smaill \e[0m"
sed -i '/tmpfs/s/defaults/defaults,size=1G/' /etc/fstab && mount -o remount /dev/shm
if [ $? != 0 ];then
i=i+1
if [ $i -eq 3 ];then
echo -e "\n\e[1;31m set tmpfs faild. \e[0m"
exit 3
fi
else
echo -e "\n\e[1;36 tmpfs updated successfully. \e[0m"
break
fi
else
echo -e "\n\e[1;36m tmpfs checked PASS \e[0m"
break
fi
done
}
#停止防火墙IPTABLES
service iptables stop
chkconfig iptables off
#关闭SELINUX
cp /etc/selinux/config{,.bak} && sed -i '/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/' /etc/selinux/config
setenforce 0
#执行以上函数
isroot
oscheck
yum_repo
mount_cdrom
packagecheck
xdesk
kernelset
oralimit
setlogin
setprofile
echo -e "\n\e[1;33m please input oracle's user passwd: \e[0m"
read oraclepw
ouseradd $oraclepw
setbash_profile
echo -e "\n\e[1;33m please input oracle install PATH(default /oracle/db) \e[0m"
read oraclepath
if [ -z $oraclepath ];then
oraclepath=/oracle/db
fi
echo -e "\n\e[1;33m please input oracle_sid (default fxcx) \e[0m"
read orasid
if [ -z orasid ];then
orasid=fxcx
fi
setbash_profile $oraclepath $orasid
mkdir -p $oraclepath && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath
unset i
echo -e "\n\e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle \e[0m"
《参考:https://gitee.com/liaoshixiong/init_server》
《参考:http://blog.51cto.com/redkey/1283792》