Linux: System related configurations
一、用户的创建与python3.6环境的安装
新的虚拟机或服务器,首先添加用户:useradd -m ice
为用户添加密码:passwd ice
-
新建的用户不能使用sudo, 为创建的普通用户添加sudo权限:
usermod -a -G adm wcy usermod -a -G sudo wcy vim /etc/sudoers 修改用户权限
Copy after login -
修改~/.vimrc配置
syntax on set nu set autoindent set smartindent set tabstop=4 set shiftwidth=4 set showmatch set ruler set cindent set background=dark set mouse=a set mouse=h
Copy after login -
安装python3.6
sudo apt-get update sudo apt-get install software-properties-common sudo add-apt-repository ppa:jonathonf/python-3.6 sudo apt-get update sudo apt-get install python3.6 cd /usr/bin ls | grep python sudo rm python sudo ln -s python3.6 python sudo apt-get install python3-pip pip --version sudo python pip install --upgrade pip pip --version
Copy after login -
安装虚拟环境
sudo pip install virtualenv sudo pip install virtualenvwrapper mkdir ~/.virtualenvs sudo vim ~/.bashrc 添加export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
Copy after login
二、安装MySQL
-
安装过程中输入用户名和密码:
sudo apt-get install mysql-server
Copy after login -
登录数据库:
sudo mysql -u root -p
Copy after login -
开启root用户的全称访问权限
mysql –u root –p use mysql; update user set host = '%' where user = 'root'; grant all privileges on *.* to 'root'@'%' identified by '你的密码'; flush privileges; quit;
Copy after loginCopy after login -
修改my.conf中的ip绑定
mysql –u root –p use mysql; update user set host = '%' where user = 'root'; grant all privileges on *.* to 'root'@'%' identified by '你的密码'; flush privileges; quit;
Copy after loginCopy after login -
重启服务:
sudo service mysql restart
Copy after login
三、安装mongodb
远程上传至服务器
-
若在linux直接使用scp协议:
切换至所要上传的文件目录下
scp -r 文件名 用户名@IP(或域名):上传至服务器所在 的路径
scp 用户名@IP(或域名):上传至服务器所在的路径 本地路径
使用winscp可以直接拖动
使用gitbash可以模拟linux系统,方法与(1)相同
mongodb的安装与配置
tar -zxvf mongodb-linux-x86_64-ubuntu1604-3.4.0.tgz sudo mv mongodb-linux-x86_64-ubuntu1604-3.4.0/ /usr/local/mongodb
sudo vim /etc/profile 最后一行添加export PATH=/usr/local/mongodb/bin:$PATH 保存退出 source /etc/profile
sudo vim /etc/mongod.conf verbose=true port=27017 logpath=/var/log/mongodb/logs/mongodb.log logappend=true dbpath=/var/lib/mongodb/db directoryperdb=true auth=false fork=true quiet=true
sudo mkdir /var/log/mongodb/logs/ -p sudo touch /var/log/mongodb/logs/mongodb.log sudo mkdir /var/lib/mongodb/db -p
注册开机启动:sudo vim /etc/init.d/mongodb !/bin/sh ### BEGIN INIT INFO # Provides: mongodb # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: mongodb # Description: mongo db server ### END INIT INFO . /lib/lsb/init-functions PROGRAM=/usr/local/mongodb/bin/mongod MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'` test -x $PROGRAM || exit 0 case "$1" in start) ulimit -n 3000 log_begin_msg "Starting MongoDB server" $PROGRAM -f /etc/mongod.conf log_end_msg 0 ;; stop) log_begin_msg "Stopping MongoDB server" if [ ! -z "$MONGOPID" ]; then kill -15 $MONGOPID fi log_end_msg 0 ;; status) ;; *) log_success_msg "Usage: /etc/init.d/mongodb {start|stop|status}" exit 1 esac exit 0
sudo chmod +x /etc/init.d/mongodb
注册开机脚本:
sudo update-rc.d mongodb defaults (注意:移除使用sudo update-rc.d –f mongodb remove)
启动服务:
sudo service mongodb start
客户端连接:
mongo
四、安装redis
-
安装tcl:
sudo apt-get install tcl
Copy after login -
解压安装包:
tar -zxvf redis-3.2.5.tar.gz
Copy after login -
创建安装目录并进入该目录:
sudo mv redis-3.2.5/ /usr/local/redis cd /usr/local/redis
Copy after login -
编译安装:
sudo make sudo make test sudo make install
Copy after login -
测试:
/usr/local/redis/src/redis-server /usr/local/redis/src/redis-cli set name ice get name
Copy after login -
创建相关目录:
sudo mkdir /etc/redis(配置文件路径) sudo mkdir /var/lib/redis(redis数据存储路径)
Copy after login -
安装服务:
cd /usr/local/redis/utils sudo ./install_server.sh
Copy after login -
重启服务:
redis-server redis-cli
Copy after loginCopy after login -
测试:
redis-server redis-cli
Copy after loginCopy after login -
配置文件:
cd /etc/redis sudo vim /etc/redis/6379.conf bind 127.0.0.1 绑定IP daemonize yes 是否以守护进程运行 requirepass 密码 重启服务: ps ajx | grep redis kill -9 对应进程号 sudo redis-server /etc/redis/6379.conf
Copy after login -
直接开启客户机:
redis-cli
Copy after login
五、安装git
-
安装:
sudo apt-get install git
Copy after login -
配置git:
git config –global user.name “ice” git config –global user.email “152516xxxx@qq.com”
Copy after login -
生成秘钥:
ssh-keygen –t rsa –C 152516xxxx@qq.com
Copy after login 在~/.ssh/ id_rsa.pub文件中复制生成的秘钥,打开GitHub网管,创建一个公钥
-
验证秘钥:
ssh –T git@github.com
Copy after login -
测试:
git clone git@github.com:用户名/用户名.git
Copy after login
六、nginx安装
-
安装zlib依赖库:
sudo apt-get install zlib1g-dev
Copy after login -
进入解压相关文件:
tar –xzvf openssl-1.0.1.tar.gz tar –xzvf nginx-1.11.3.tar.gz tar –xzvf pcre-8.41. tar.gz,
Copy after login -
进入Nginx解压目录:
cd /home/ice/ nginx-1.11.3/
Copy after login -
配置环境:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.41 --with-openssl=../openssl-1.0.1
Copy after login -
编译:
make 如果出现”pcre.h No such file or directory”, 安装”sudo apt-get install libpcre3-dev”
Copy after login -
安装
sudo make install
Copy after login -
说明:
nginx会被安装在/usr/local/nginx目录下 conf:存放配置文件 html:静态网页 logs:存放日志文件 sbin:存放可执行文件
Copy after login -
相关命令
启动Nginx服务: sudo /usr/local/nginx/sbin/nginx 关闭Nginx服务: sudo /usr/local/nginx/sbin/nginx -s stop 重新加载配置: sudo /usr/local/nginx/sbin/nginx –s reload 指定配置文件: sudo /usr/local/nginx/sbin/nginx –c /usr/local/nginx/conf/nginx.conf 查看版本信息: sudo /usr/local/nginx/sbin/nginx –V 查看80端口的程序:nesta –ano | grep 80 关闭占用80端口的程序:sudo fuser –k 80/tcp
Copy after login -
启动服务:
sudo /usr/local/nginx/sbin/nginx 或cd切换到sbin目录下执行./nginx
Copy after login 打开浏览器,输入Nginx服务器IP地址
配置
/usr/local/nginx/conf/nginx.conf
Copy after login全局设置: 定义全局错误日志文件,需要什么等级可以设置开启 error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; worker_rlimit_nofile:指定一个nginx可以打开的最多文件描述符,可以使用“ulimit –n 65535”进行设置(虚拟机默认设置1024),阿里云服务器默认就是65535
Copy after loginevents(nginx工作模式) events { use epoll; linux标准的工作模式,nginx高效的基石 worker_connections 1024; 定义nginx每个进程的最大连接数 }
Copy after loginhttp(http设置) sendfile on; 开启高效文件传输模式 tcp_nopush on; 防止网络阻塞 tcp_nodelay on; keepalive_timeout 65; 设置客户端连接活动的超时时间 gzip on; 使用压缩模块
Copy after loginserver(主机设置) server{ listen 80; server_name localhsot www.ice.xin 39.105.61.52; charser utf-8; # 负载均衡模块,upstream是负载均衡器 upstream ice { server 39.105.61.52:8000 weight=1 max_fails=1 fail_timeout=300s; server 39.105.61.53:8000 weight=1 max_fails=1 fail_timeout=300s; } # 负载均衡采用轮循方式 server server 39.105.61.52:8000 weight=1 max_fails=1 fail_timeout=300s; } # 反向代理配置, location / { #适用于django自带的runserver方式启动 #proxy_pass http://www.ice.xin:8000; #proxy_pass http://www.ice.xin:8000; #proxy_set_header Host $http_host; # 设置uwsgi启动 include uwsgi_params; uwsgi_pass ice; } }
Copy after login
重启nginx服务:
sudo /usr/local/nginx/sbin/nginx
七、部署Django项目
-
安装Django:
sudo pip install Django==1.11.4
Copy after login 创建Django项目:部署前需要关闭调试,允许任何机器访问
-
安装uwsgi:
sudo apt-get install libpython3.6-dev(2.7不用安装) pip install uwsgi
Copy after login 创建:在工程目录下创建名为uwsgi.ini的文件
-
配置uwsgi.ini:
[uwsgi] #使用nginx连接时使用功能,上线时才使用socket socket=0.0.0.0:8000 #直接做web项目服务器使用 #http=0.0.0.0:8000 #项目目录 chdir=/home/'/project #项目中wsgi.py文件的目录,相对于项目目录 wsgi-file=project/wsgi.py processess=2 threads=2 master=True pidfile=uwsgi.pid #是否以守护进程的方式启动 daemonize=uwsgi.log
Copy after login -
启动:
uwsgi --ini uwsgi.ini
Copy after login -
停止:
uwsgi --stop uwsgi.pid
Copy after login 配置Nginx:
在/usr/local/nginx/conf/nginx.conf中添加: location /static { alias /var/www/xxx/static/; }
Copy after login创建静态文件的存储文件 sudo mkdir –vp /var/www/xxx/static/ sudo chmod 777 /var/www/xxx/static/
Copy after login
配置静态文件
在settings.py中添加: STATIC_ROOT = ‘var/www/xxx/static/' STATIC_URL = ‘/static/'
Copy after login迁移静态文件 python manage.py collectstatic
Copy after login
更多Linux文章,请访问Linux教程栏目进行学习!
The above is the detailed content of Linux: System related configurations. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.
