ubuntu18.04 shell脚本安装新版本nginx mongodb redis-server
Ubuntu 18.04 shell 在线安装新版本服务
#!/bin/bash #1.确定系统版本代号 Codename=$(cat /etc/os-release | grep VERSION_CODENAME |awk -F'=' '{print $2}') echo "检测到您的Ubuntu系统版本为:$Codename" #2.选择镜像源 echo "**********************************" echo "请选择镜像源:" echo " 1.阿里 2.清华 3.网易 4.中科大 " echo "**********************************" read -s -n1 sourceChoice if [ $sourceChoice -ne 1 ] && [ $sourceChoice -ne 2 ] && [ $sourceChoice -ne 3 ] && [ $sourceChoice -ne 4 ];then echo echo '输入有误,Good Bye.' exit fi case $sourceChoice in 1) choose='aliyun' ;; 2) choose='tsinghua' ;; 3) choose='163' ;; 4) choose='ustc' ;; esac case $choose in aliyun) sourceweb='http://mirrors.aliyun.com' ;; tsinghua) sourceweb='https://mirrors.tuna.tsinghua.edu.cn' ;; 163) sourceweb='http://mirrors.163.com' ;; ustc) sourceweb='http://mirrors.ustc.edu.cn' ;; esac # 3.备份换源 echo "备份sources.list..." sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup echo "设置新的镜像源..." echo "\ deb $sourceweb/ubuntu/ $Codename main restricted universe multiverse deb $sourceweb/ubuntu/ $Codename-security main restricted universe multiverse deb $sourceweb/ubuntu/ $Codename-updates main restricted universe multiverse deb $sourceweb/ubuntu/ $Codename-proposed main restricted universe multiverse deb $sourceweb/ubuntu/ $Codename-backports main restricted universe multiverse deb-src $sourceweb/ubuntu/ $Codename main restricted universe multiverse deb-src $sourceweb/ubuntu/ $Codename-security main restricted universe multiverse deb-src $sourceweb/ubuntu/ $Codename-updates main restricted universe multiverse deb-src $sourceweb/ubuntu/ $Codename-proposed main restricted universe multiverse deb-src $sourceweb/ubuntu/ $Codename-backports main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ bionic nginx deb-src http://nginx.org/packages/mainline/ubuntu/ bionic nginx">/etc/apt/sources.list echo "更新源..." wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - sudo wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo apt-mark hold openssh-server sudo apt-get update sudo apt-get upgrade -y sudo apt-get install build-essential -y echo "安装python3.9" sudo apt-get install libffi-dev zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev gcc make wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz tar -zxvf Python-3.9.0.tgz cd Python-3.9.0 ./configure --prefix=/usr/local/python39 #--prefix后面自定义python安装路径 make && sudo make install ln -s /usr/local/python39/bin/python3 /usr/bin/python39 ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3 #### 8.安装python虚拟环境 apt install virtualenv -y virtualenv --no-site-packages -p python39 /root/OniRiseurVenv ## 安装libreoffice sudo apt-get install libreoffice -y #安装中文 sudo apt-get install fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming -y ## 安装Nginx echo "安装Nginx" #apt update apt install nginx -y sudo systemctl restart nginx echo "查看nginx版本*********************************" nginx -v #nginx -v 1.20.2 echo "安装Mongodb" sudo apt install mongodb-org -y echo "查看mongodb版本" mongo --version #mongodb -v 5.0.5 sudo systemctl start mongod.service #MongoDB修改内存使用 echo "mongodb 修改内存" mongo admin --eval 'db.adminCommand({setParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:335544320});' mongo admin --eval 'db.adminCommand({getParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:1});' ## 安装PostgreSQL sudo apt-get install postgresql-10 -y sudo apt install postgresql-contrib -y sudo systemctl start postgresql.service # 设置数据库命令 sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'secdomain@2022';" echo "创建zhangsan数据库" sudo -u postgres psql -c "create database zhangsan;" echo "查看数据库" sudo -u postgres psql -c '\l' echo "查看数据最大连接数" sudo -u postgres psql -c 'SHOW max_connections;' echo "修改数据最大连接数:50000" sudo -u postgres psql -c "ALTER SYSTEM SET max_connections TO '10000';" systemctl restart postgresql.service echo "查看数据最大连接数" sudo -u postgres psql -c 'SHOW max_connections;' parse=`grep "listen_addresses = '\*'" /etc/postgresql/10/main/postgresql.conf &>> error.txt` if [ -n "$parse" ];then echo "listen_addresses = '*' 已存在!!!,无需修改!!" else echo "listen_addresses = '*'" >>/etc/postgresql/10/main/postgresql.conf fi pg_hba_parse=`grep "host all oniriseur 0.0.0.0/0 md5" /etc/postgresql/10/main/pg_hba.conf` if [ -n "$pg_hba_parse" ];then echo "pa_ha_parse 已修改,无需操作!!!" else echo "host all oniriseur 0.0.0.0/0 md5" >>/etc/postgresql/10/main/pg_hba.conf fi #重启数据库 sudo /etc/init.d/postgresql restart #停止数据库 #sudo /etc/init.d/postgresql stop #安装redis 服务 sudo add-apt-repository ppa:redislabs/redis -y sudo apt-get update sudo apt install redis-server -y #设置redis sed -i "s/protected-mode yes/protected-mode no/g" /etc/redis/redis.conf sed -i "s/supervised auto/supervised systemd/g" /etc/redis/redis.conf #重启redis sudo systemctl restart redis-server.service sudo systemctl status redis-server.service echo "redis-server 版本:***************" redis-server -v echo "deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse" >>/etc/apt/sources.list systemctl enable nginx.service systemctl enable mongod.service systemctl enable redis-server.service systemctl enable postgresql.service systemctl restart nginx.service systemctl restart mongod.service systemctl restart redis-server.service systemctl restart postgresql.service #查看中文安装 echo -e "\033[32m 查看中文安装:**************中文测试*******************************\033[0m" fc-list :lang=zh-cn #查看nginx安装 echo -e "\033[32m 查看nginx安装目录:**************nginx目录*******************************\033[0m" whereis nginx nginx -v #查看mongodb 版本 echo -e "\033[32m 查看mongodb版本:**************mongodb版本为:*******************************\033[0m" mongo --version echo -e "\033[32m mongodb 修改内存:**************mongodb修改内存*******************************\033[0m" mongo test --eval 'db.adminCommand({getParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:1});' echo -e "\033[32m ************** 重启postgresql数据库 ******************************* \033[0m" sudo /etc/init.d/postgresql restart echo -e "\033[32m ************** 查看redis-server 服务器版本 ******************************* \033[0m" redis-server -v mongo admin --eval 'db.adminCommand({setParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:335544320});' mongo admin --eval 'db.adminCommand({getParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:1});' echo -e "\033[32m ************** 查看启动服务 ******************************* \033[0m" sudo netstat -tupln