Created
December 30, 2018 20:24
-
-
Save kovenko/13e193b5dfe7e1dc736cc5aeafd3500c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Обновление системы | |
| apt update | |
| apt upgrade | |
| apt dist upgrade | |
| # Установка пакетов | |
| apt install -y sudo mc net-tools openssh-server nginx php7.0-fpm git qemu-guest-agent ntpdate curl libpq-dev dirmngr ffmpeg apt-transport-https | |
| touch /etc/apt/sources.list.d/pgdg.list | |
| echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/pgdg.list | |
| chown root:root /etc/apt/sources.list.d/pgdg.list | |
| wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | |
| apt-get update | |
| apt install postgresql-11 -y | |
| su postgres | |
| psql | |
| postgres=# ALTER USER wifi WITH SUPERUSER; | |
| # Установка приложения | |
| # Установка RVM | |
| gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
| curl -L https://get.rvm.io | bash -s | |
| usermod -a -G rvm root | |
| # Отключиться и зайти под root | |
| source /etc/profile.d/rvm.sh | |
| rvm -v | |
| gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
| rvm get stable | |
| rvm requirements | |
| rvm install 2.3.0 | |
| rvm use 2.3.0 | |
| gem install --user-install executable-hooks | |
| # Добавляю пользователя | |
| useradd -m -d /home/deploy -s /bin/bash deploy | |
| passwd deploy | |
| ###usermod -a -G rvm deploy | |
| # Зайти под deploy | |
| rvm user gemsets | |
| rvm use 2.3.0 | |
| /bin/bash --login | |
| rvm use 2.3.0 | |
| rvm gemset create 2wifi | |
| rvm use ruby-2.3.0@2wifi | |
| # Проверить соответствие версии ruby и gemset | |
| rvm list | |
| rvm gemset list | |
| gem install --user-install executable-hooks | |
| gem install rake --version='10.5.0' | |
| =================================== | |
| source /etc/profile.d/rvm.sh | |
| # Отключиться и зайти под deploy | |
| rvm user gemsets | |
| #rvm_path=/home/deploy/.rvm | |
| #rvm_prefix=/home/deploy | |
| # Добавить строку в файл ~/.rvmrc | |
| export rvm_gemset_create_on_use_flag=1 | |
| rvm_autoupdate_flag=0 | |
| # Проверить на содержимое .bash_profile | |
| [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile | |
| [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
| # Отключиться и зайти под deploy | |
| rvm install 2.3.0 | |
| rvm use 2.3.0 | |
| # На проде сейчас gemset wifi | |
| rvm gemset create 2wifi | |
| /bin/bash --login | |
| rvm use ruby-2.3.0@2wifi | |
| # Проверить соответствие версии ruby и gemset | |
| rvm list | |
| rvm gemset list | |
| В ~/.rvmrc добавить строку echo rvm_autoupdate_flag=0 | |
| =================================== | |
| # Скопировать ssh ключи в id_rsa и id_rsa.pub | |
| chmod 600 ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa.pub | |
| # В /etc/hosts добавить серый адрес | |
| # 192.168.1.110 gitlab.2wifi.ru | |
| # 192.168.1.108 staging.2wifi.ru | |
| git config --global user.email [email protected] | |
| mkdir ~/2wifi | |
| mkdir ~/xorit | |
| mkdir ~/xorit/api | |
| mkdir ~/2wifi/shared | |
| mkdir ~/2wifi/shared/config | |
| mkdir ~/2wifi/shared/log | |
| # Протестировать подключение к GitLab | |
| git clone [email protected]:snuff/2wifi.git | |
| cd 2wifi | |
| bundle install | |
| # Скопировать конфигурационные файлы | |
| bundle exec rake assets:precompile | |
| bundle exec rake db:migrate | |
| # Скопировать /etc/init.d/wifi | |
| chmod 755 /etc/init.d/wifi | |
| # В /etc/sudoers добавить | |
| # deploy ALL=(ALL:ALL) NOPASSWD:ALL | |
| # DNS | |
| # Добавить каноническую запись для staging.2wifi.ru в DNS | |
| # Старая запись была vpn | |
| # Подготовка к деплою на staging с developer | |
| # vm.2wifi.ru 907 | |
| # ~/Ruby/2wifi/config/deploy/staging.rb | |
| # server 'staging.2wifi.ru', user: 'deploy', roles: %w(web app), port: 22 | |
| # set :deploy_to, '/home/deploy/2wifi' | |
| # set :branch, 'production' | |
| # Nginx проброс на staging.2wifi.ru http порта | |
| # Создать прокси в Nginx на 80 порт виртуального хоста | |
| # staging.2wifi.ru.conf | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name staging.2wifi.ru; | |
| location / { | |
| proxy_pass http://192.168.1.108:80; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| } | |
| } | |
| # Настройка nginx на staging.2wifi.ru | |
| # staging.2wifi.ru.conf | |
| upstream wifi_unicorn { | |
| server unix:/home/deploy/2wifi/current/tmp/unicorn.sock fail_timeout=0; | |
| } | |
| server { | |
| listen *:80; | |
| #listen *:443 ssl; | |
| #ssl on; | |
| #ssl_certificate /etc/nginx/ssl/admin.2wifi.ru.crt; | |
| #ssl_certificate_key /etc/nginx/ssl/admin.2wifi.ru.key; | |
| server_name staging.2wifi.ru localhost; | |
| root /home/deploy/2wifi/current/public; | |
| access_log /home/deploy/2wifi/shared/log/nginx.access.log; | |
| error_log /home/deploy/2wifi/shared/log/nginx.error.log; | |
| try_files $uri/index.html $uri @wifi_unicorn; | |
| location ~ /\. { | |
| deny all; | |
| } | |
| location ~ /xorit/api/.+\.php$ { | |
| root "/home/deploy"; | |
| index index.php index.html; | |
| try_files $uri =404; | |
| include /etc/nginx/fastcgi.conf; | |
| fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
| } | |
| location @wifi_unicorn { | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header Host $http_host; | |
| proxy_redirect off; | |
| proxy_pass http://wifi_unicorn; | |
| proxy_read_timeout 300s; | |
| proxy_send_timeout 300s; | |
| } | |
| client_max_body_size 4G; | |
| keepalive_timeout 300; | |
| error_page 500 502 504 /500.html; | |
| error_page 503 @503; | |
| } | |
| service php7.0-fpm start | |
| service nginx restart | |
| # Скопировать из директории xorit php скрипты | |
| # В ~/2wifi/shared/config скопировать | |
| # database.yml | |
| # offsite_payments.yml | |
| # secrets.yml | |
| # sniffer_config.yml | |
| # yandex_segment.yml | |
| # unicorn.rb | |
| bundle config git.allow_insecure true | |
| rake assets:precompile | |
| sudo -u postgres psql | |
| CREATE DATABASE wifi; | |
| CREATE USER wifi WITH password ''; | |
| GRANT ALL ON DATABASE wifi TO wifi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment