一、用户的创建与python3.6环境的安装
新的虚拟机或服务器,首先添加用户:useradd -m ice
为用户添加密码:passwd ice
-
新建的用户不能使用sudo, 为创建的普通用户添加sudo权限:
usermod -a -G adm wcy usermod -a -G sudo wcy vim /etc/sudoers 修改用户权限
-
修改~/.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
-
安装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
-
安装虚拟环境
sudo pip install virtualenv sudo pip install virtualenvwrapper mkdir ~/.virtualenvs sudo vim ~/.bashrc 添加export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
二、安装MySQL
-
安装过程中输入用户名和密码:
sudo apt-get install mysql-server
-
登录数据库:
sudo mysql -u root -p
-
开启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;
-
修改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;
-
重启服务:
sudo service mysql restart
三、安装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
-
解压安装包:
tar -zxvf redis-3.2.5.tar.gz
-
创建安装目录并进入该目录:
sudo mv redis-3.2.5/ /usr/local/redis cd /usr/local/redis
-
编译安装:
sudo make sudo make test sudo make install
-
测试:
/usr/local/redis/src/redis-server /usr/local/redis/src/redis-cli set name ice get name
-
创建相关目录:
sudo mkdir /etc/redis(配置文件路径) sudo mkdir /var/lib/redis(redis数据存储路径)
-
安装服务:
cd /usr/local/redis/utils sudo ./install_server.sh
-
重启服务:
redis-server redis-cli
-
测试:
redis-server redis-cli
-
配置文件:
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
-
直接开启客户机:
redis-cli
五、安装git
-
安装:
sudo apt-get install git
-
配置git:
git config –global user.name “ice” git config –global user.email “152516xxxx@qq.com”
-
生成秘钥:
ssh-keygen –t rsa –C 152516xxxx@qq.com
在~/.ssh/ id_rsa.pub文件中复制生成的秘钥,打开GitHub网管,创建一个公钥
-
验证秘钥:
ssh –T git@github.com
-
测试:
git clone git@github.com:用户名/用户名.git
六、nginx安装
-
安装zlib依赖库:
sudo apt-get install zlib1g-dev
-
进入解压相关文件:
tar –xzvf openssl-1.0.1.tar.gz tar –xzvf nginx-1.11.3.tar.gz tar –xzvf pcre-8.41. tar.gz,
-
进入Nginx解压目录:
cd /home/ice/ nginx-1.11.3/
-
配置环境:
./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
-
编译:
make 如果出现”pcre.h No such file or directory”, 安装”sudo apt-get install libpcre3-dev”
-
安装
sudo make install
-
说明:
nginx会被安装在/usr/local/nginx目录下 conf:存放配置文件 html:静态网页 logs:存放日志文件 sbin:存放可执行文件
-
相关命令
启动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
-
启动服务:
sudo /usr/local/nginx/sbin/nginx 或cd切换到sbin目录下执行./nginx
打开浏览器,输入Nginx服务器IP地址
配置
/usr/local/nginx/conf/nginx.conf
全局设置: 定义全局错误日志文件,需要什么等级可以设置开启 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
events(nginx工作模式) events { use epoll; linux标准的工作模式,nginx高效的基石 worker_connections 1024; 定义nginx每个进程的最大连接数 }
http(http设置) sendfile on; 开启高效文件传输模式 tcp_nopush on; 防止网络阻塞 tcp_nodelay on; keepalive_timeout 65; 设置客户端连接活动的超时时间 gzip on; 使用压缩模块
server(主机设置) 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; } }
重启nginx服务:
sudo /usr/local/nginx/sbin/nginx
七、部署Django项目
-
安装Django:
sudo pip install Django==1.11.4
创建Django项目:部署前需要关闭调试,允许任何机器访问
-
安装uwsgi:
sudo apt-get install libpython3.6-dev(2.7不用安装) pip install uwsgi
创建:在工程目录下创建名为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
-
启动:
uwsgi --ini uwsgi.ini
-
停止:
uwsgi --stop uwsgi.pid
配置Nginx:
在/usr/local/nginx/conf/nginx.conf中添加: location /static { alias /var/www/xxx/static/; }
创建静态文件的存储文件 sudo mkdir –vp /var/www/xxx/static/ sudo chmod 777 /var/www/xxx/static/
配置静态文件
在settings.py中添加: STATIC_ROOT = ‘var/www/xxx/static/' STATIC_URL = ‘/static/'
迁移静态文件 python manage.py collectstatic
更多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!

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft