install_r45_on_ubuntu_1804l.../install_orbit_environment.sh

189 lines
8.7 KiB
Bash
Raw Normal View History

#!/bin/bash
ubuntu_version=$(lsb_release -rs)
sudo apt update
2022-08-24 06:55:16 +00:00
sudo apt install -y git
sudo apt install -y make
2022-02-09 11:26:06 +00:00
org_pwd=$(pwd)
if [[ $ubuntu_version =~ '14' ]]; then
2022-02-09 10:48:06 +00:00
sudo apt install libgmp-dev -y
fi
echo "postfix postfix/mailname string $USER" | sudo debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Local only'" | sudo debconf-set-selections
sudo apt-get install -y postfix
sudo service postfix start
2022-08-04 07:33:40 +00:00
#install nginx 1.23.1
wget http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/install_nginx.sh -O install_nginx.sh
bash install_nginx.sh
2022-05-24 07:46:03 +00:00
sudo nginx -t
nginx_status="$(echo $?)"
if [ $nginx_status != 0 ]; then
sudo sed -i 's/\([^#]include \/etc\/nginx\/sites-enabled\/*\)/\#\1/g' /etc/nginx/nginx.conf
fi
sudo service nginx restart
cd /etc/nginx/
sudo mkdir orbit_sites/
2022-02-09 11:26:06 +00:00
if [ -z "$(grep 'orbit_sites' nginx.conf)" ]; then
sudo sed -i 's/\(include\ \/etc\/nginx\/sites-enabled\/\*\;\)/\1\n\tinclude\ \/etc\/nginx\/orbit_sites\/*;/g' nginx.conf
fi
cd $org_pwd
sudo apt-get install gnupg -y
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# install mongod 5.0
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
2022-03-23 02:55:09 +00:00
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=5.0.6 mongodb-org-database=5.0.6 mongodb-org-server=5.0.6 mongodb-org-shell=5.0.6 mongodb-org-mongos=5.0.6 mongodb-org-tools=5.0.6
sudo service mongod stop
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
if [ -f /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
else
mongo --eval "db.version()" --quiet
exit_code="$(echo $?)"
#if mongo 5 core dump, then install mongo 4.4
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then
sudo apt-get purge mongodb-org* -y
sudo rm -rf /var/log/mongodb
sudo rm -rf /var/lib/mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=4.4.11 mongodb-org-server=4.4.11 mongodb-org-shell=4.4.11 mongodb-org-mongos=4.4.11 mongodb-org-tools=4.4.11
2022-05-12 08:47:02 +00:00
sudo service mongod restart
sleep 10
if [ -f /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
else
echo "mongo not yet start!"
echo "Please check mongo status!"
fi
else
echo "mongo not yet start!"
echo "Please check mongo status!"
fi
fi
2022-02-09 11:26:06 +00:00
# build ImageMagick and install
2022-02-09 10:48:06 +00:00
if [ -z $(which convert) ]; then
2022-08-24 06:57:54 +00:00
tmp_pwd="$(pwd)"
sudo bash -l -c "cd /root && \
2022-02-09 10:48:06 +00:00
apt-get install libjpeg62 -y && \
wget -nc http://download.sourceforge.net/libpng/libpng-1.5.13.tar.gz && \
tar xvfz libpng-1.5.13.tar.gz && \
cd libpng-1.5.13/ && \
./configure && \
make && sudo make install && \
apt install -y libltdl-dev graphviz libpng-dev libfftw3-dev && \
apt-get install -y libjpeg-turbo8-dev && \
apt install -y libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev && \
apt install -y cmake pkg-config libbrotli-dev && \
2022-07-12 02:55:17 +00:00
wget -nc https://imagemagick.org/archive/ImageMagick.tar.gz && \
2022-02-09 10:48:06 +00:00
tar xvfz ImageMagick.tar.gz && \
2022-08-24 06:55:16 +00:00
cd $(ls -d /root/libpng-1.5.13/ImageMagick-7*) && \
chown $USER:$USER . -R && \
2022-08-24 06:57:54 +00:00
./configure --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes --disable-shared --with-modules && \
2022-02-09 10:48:06 +00:00
make && make install && \
ln -s /usr/local/lib/* /usr/lib/. && \
ln -s /usr/local/lib/pkgconfig/* /usr/lib/pkgconfig/. && \
2022-08-24 06:57:54 +00:00
ln -s /usr/local/bin/* /usr/bin/. && \
convert -list configure"
cd $tmp_pwd
2022-02-09 10:48:06 +00:00
fi
2022-02-09 11:26:06 +00:00
## install rvm
2022-02-09 10:48:06 +00:00
if [ -z $(which rvm) ]; then
sudo apt-get install software-properties-common -y
sudo apt-get install --reinstall ca-certificates -y
sudo apt-get install dpkg -y
2022-02-09 10:48:06 +00:00
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sudo apt-get install rvm -y
sudo usermod -a -G rvm $USER
echo 'source "/etc/profile.d/rvm.sh"' >> ~/.bashrc
source "/etc/profile.d/rvm.sh"
sudo chown $USER:$USER $HOME -R
rvm user gemsets
2022-02-09 11:26:06 +00:00
sudo chown $USER:$USER /usr/share/rvm -R
2022-02-09 10:48:06 +00:00
fi
2022-02-09 11:26:06 +00:00
source "/etc/profile.d/rvm.sh"
# install ruby 2.1.10
rvm install 2.1.10
rvm --default use 2.1.10
2022-03-06 08:27:38 +00:00
gem install zip
gem install nokogiri -v 1.7.0.1
2022-02-09 10:48:06 +00:00
sudo apt-get install screen -y
sudo sed -i 's/#cron\.\*/cron\.\*/g' /etc/rsyslog.d/50-default.conf
sudo service rsyslog restart
sudo mkdir /home/backup/db/ -p
sudo mkdir /home/backup/orbit/ -p
sudo apt-get install rsnapshot -y
sudo sed -i 's/^[^#]etain/#retain/g' /etc/rsnapshot.conf
sudo sed -i 's/\(retain\tdelta\t3\)/\1\nretain\tdaily\t7/g' /etc/rsnapshot.conf
sudo sed -i 's/snapshot_root.*/snapshot_root\t\/home\/backup\/orbit/g' /etc/rsnapshot.conf
sudo sed -i 's/^\(backup\t.*\)/#\1/g' /etc/rsnapshot.conf
matched_backup_home=$(grep -P "backup\t$HOME" /etc/rsnapshot.conf|xargs)
if [ -z $matched_backup_home ]; then
sudo sed -i "$(echo "s/^\(#backup\t\/home\/\t\)/backup\t$(echo $HOME|sed 's/\//\\\//g')\tlocalhost\/\n\1/g")" /etc/rsnapshot.conf
2022-03-19 02:56:28 +00:00
else
matched_backup_home=$(grep -P "(^|\s+)backup\t$HOME" /etc/rsnapshot.conf|xargs)
if [ -z $matched_backup_home ]; then
sudo sed -i "$(echo "s/[#\s\t]*backup\t$(echo $HOME|sed 's/\//\\\//g')/backup\t$(echo $HOME|sed 's/\//\\\//g')/g")" /etc/rsnapshot.conf
fi
fi
2022-02-09 10:48:06 +00:00
sudo wget -nc http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/orbit_logrotate -O /etc/logrotate.d/orbit
sudo sed -i "s/rulingcom/$USER/g" /etc/logrotate.d/orbit
sudo logrotate -d /etc/logrotate.conf
sudo /usr/sbin/logrotate -f /etc/logrotate.conf
2022-02-09 10:48:06 +00:00
sudo wget -nc http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/orbit_service.sh -O /etc/init.d/orbit
sudo sed -i "s/ORBIT_USER=.*/ORBIT_USER=$USER/g" /etc/init.d/orbit
sudo chmod 755 /etc/init.d/orbit
sudo update-rc.d orbit defaults
sudo systemctl enable mongod.service
sudo_crontab_jobs=$(sudo crontab -l)
2022-02-09 10:48:06 +00:00
if [[ "$sudo_crontab_jobs" =~ "@reboot /bin/bash -l -c" ]]; then
echo "Already exist reboot crontab!"
else
echo "Adding reboot crontab!"
2022-02-09 10:48:06 +00:00
echo "$sudo_crontab_jobs"$'\n''@reboot /bin/bash -l -c "rm -f /tmp/mongodb-27017.sock && chown mongodb:mongodb /var/lib/mongodb/ -R && chown mongodb:mongodb /var/log/mongodb -R && /usr/sbin/service mongod restart && /etc/init.d/orbit restart"'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
2022-02-09 10:48:06 +00:00
if [[ "$sudo_crontab_jobs" =~ "mongodump -o /" ]]; then
echo "Already exist mongodump crontab!"
else
echo "Adding mongodump crontab!"
2022-02-09 10:48:06 +00:00
echo "$sudo_crontab_jobs"$'\n''0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
2022-02-09 10:48:06 +00:00
if [[ `echo "$sudo_crontab_jobs" | grep -P "rm -fr.*/db/"` ]]; then
echo "Already exist remove old mongo backup crontab!"
else
echo "Adding remove old mongo backup crontab!"
2022-02-09 10:48:06 +00:00
echo "$sudo_crontab_jobs"$'\n''0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
2022-02-09 10:48:06 +00:00
if [[ "$sudo_crontab_jobs" =~ "/usr/bin/rsnapshot" ]]; then
echo "Already exist rsnapshot crontab!"
else
echo "Adding rsnapshot crontab!"
2022-02-09 10:48:06 +00:00
echo "$sudo_crontab_jobs"$'\n''15 4 * * * /usr/bin/rsnapshot daily'| sudo crontab -
fi
echo "Finish setting orbit environment!"
echo "Please install orbit web app and setting nginx for single web by yourself!"