markdown Ubuntu部署数字海洋
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Ubuntu部署数字海洋相关的知识,希望对你有一定的参考价值。
DIGITAL OCEAN
----------------------
```
curl -sSL https://agent.digitalocean.com/install.sh | sh
```
New user
```
adduser djangodeploy
usermod -aG sudo djangodeploy
```
Create ssh-key
```
ssh-keygen
ssh-copy-id <username@gmail.com>
or
cat ~/.ssh/id_rsa.pub
```
su - djangodeploy
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
:paste public key:
chmod 600 ~/.ssh/authorized_keys
exit
sudo nano /etc/ssh/sshd_config
-------------
EnableRootLogin no
:OTHER:
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
-------------
sudo systemctl reload sshd
sudo ufw app list
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
sudo apt-get update
sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx
sudo -u postgres psql
-------------
CREATE DATABASE myproject;
CREATE USER dbusername WITH PASSWORD 'password'
ALTER ROLE dbusername SET client_encoding TO 'utf8';
ALTER ROLE dbusername SET default_transaction_isolation TO 'read committed';
ALTER ROLE dbusername SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE myproject TO dbusername;
\q
-------------
sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv
mkdir ~/myproject
cd ~/myproject
git clone <repo>
mv <repo> src
virtualenv venv
source ./venv/bin/activate
cd src
pip install -r requirements.txt
:POSGRESQL:
pip install gunicorn psycopg2
:MYSQL:
pip install gunicorn mysqlclient
django-admin.py startproject main ~/myproject/src
nano ~/myproject/src/main/settings.py
------------
try:
from .local_settings import *
except ImportError:
pass
------------
~/myproject/src/manage.py makemigrations
~/myproject/src/manage.py migrate
~/myproject/src/manage.py createsuperuser
~/myproject/src/manage.py collectstatic
sudo ufw allow 8000
~/myproject/src/manage.py runserver 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000
gunicorn --bind 0.0.0.0:8000 main.wsgi
control + c
deactivate
sudo nano /etc/systemd/system/gunicorn.service
-------------
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=djangodeploy
Group=www-data
WorkingDirectory=/home/djangodeploy/bb/src
ExecStart=/home/djangodeploy/bb/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/djangodeploy/bb/bb.sock main.wsgi:application
[Install]
WantedBy=multi-user.target
-------------
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo systemctl status gunicorn
:if errors:
sudo journalctl -u gunicorn
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
sudo nano /etc/nginx/sites-available/myproject
-------------
server {
listen 80;
server_name partners.bonosbienestar.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/djangodeploy/bb/src;
}
location /media/ {
root /home/djangodeploy/bb/src;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/djangodeploy/bb/src/bb.sock;
}
}
-------------
sudo ln -s /etc/nginx/sites-available/bb /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
sudo ufw delete allow 8000
sudo ufw allow 'Nginx Full'
:if errors:
sudo tail -F /var/log/nginx/error.log
:clean:
dpkg --get-selections |grep mysql
dpkg --purge mysql-server
:install:
sudo apt-get update
sudo apt-get install mariadb-server mariadb-client
sudo mysql_secure_installation
sudo mysql -u root -p
or
mysql -u root -p
----------
use mysql;
update user set plugin='mysql_native_password' where user='root';
flush privileges;
quit;
----------
sudo nano/etc/mysql/my.cnf
---------
[mysqld]
skip-grant-tables
---------
service mysql restart
mysql
---------
UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass')
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
---------
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
use mysql
update user set password=PASSWORD('newpass') where User='root';
flush priveileges;
:remote access:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf:
-----------
kip-external-locking
bind-address = 0.0.0.0
-----------
sudo ufw allow 3306
mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'password';
:create user:
CREATE USER 'nombre_usuario'@'localhost' IDENTIFIED BY 'tu_contrasena';
GRANT ALL PRIVILEGES ON * . * TO 'nombre_usuario'@'localhost';
FLUSH PRIVILEGES;
:solving errors:
Failed to restart mysql.service: Unit mysql.service is masked.
>> systemctl unmask mysql.service
>> sudo service mysql start
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
>> ps -A|grep mysql
>> sudo pkill mysql
>> sudo service mysql start
以上是关于markdown Ubuntu部署数字海洋的主要内容,如果未能解决你的问题,请参考以下文章