1. 程式人生 > 其它 >ubuntu18.04 shell指令碼安裝新版本nginx mongodb redis-server

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