记一次服务器配置环境全过程

一. 准备工作

 yum update
 yum -y install python-devel mysql-devel gcc wget bzip2 python-setuptools

二. 安装anaconda

  1. 下载

     wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.03-Linux-x86_64.sh
    
  2. 执行安装

     bash Anaconda3-2019.03-Linux-x86_64.sh
    

    安装过程中会出现的提示

     # 1.协议要求
     Do you accept the license terms? [yes|no]
     >>> yes
     
     # 2.安装位置(默认/root/anaconda3)
     [/root/anaconda3] >>>  # 此处修改anaconda的安装绝对路径
    
     # 3.自动添加环境变量(推荐no)
     >by running conda init? [yes|no]
     >no
    
  3. 手动修改环境变量

     vim ~/.bashrc
    
     # 文件末尾添加如下内容
     export PATH="/root/anaconda3/bin:$PATH" # 路径替换为安装路径
     
     vim /etc/profile
    
     # 文件末尾添加如下内容
     export PATH="/root/anaconda3/bin:$PATH" # 路径替换为安装路径
     
     #保存退出,刷新系统
     source /etc/profile
    
  4. 验证安装是否成功

     source activate # 进入conda环境 出现(base)则说明安装成功
     source deactivate # 退出conda环境
    

三. 安装MySQL

  1. 检查&删除 MariaDB

     # 检查
     shell> rpm -qa|grep mariadb
     mariadb-server-5.5.60-1.el7_5.x86_64
     mariadb-5.5.60-1.el7_5.x86_64
     mariadb-libs-5.5.60-1.el7_5.x86_64
     
     # 删除
     shell> rpm -e --nodeps mariadb-server
     shell> rpm -e --nodeps mariadb
     shell> rpm -e --nodeps mariadb-libs
    
  2. 检查&删除 MySQL

     # 检查
     shell> rpm -qa|grep mysql
     
     # 删除
     shell> rpm -e --nodeps xxx
    
  3. 下载MySQL源
    官网:https://dev.mysql.com/downloads/repo/yum/

     # 查看系统版本
     shell> cat /etc/redhat-release
     CentOS Linux release 7.7.1908 (Core)
     
     # 选择对应的版本进行下载,例如CentOS 7当前在官网查看最新Yum源的下载地址为:
     # https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
     shell> wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    
  4. 安装MySQL源

     shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm
     
     # 例如CentOS7当前最新MySQL源安装:
     shell> sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
    

    通过yum repolist enabled | grep "mysql.*-community.*"可以看到mysql相关资源

     shell> yum repolist enabled | grep "mysql.*-community.*"
     !mysql-connectors-community/x86_64 MySQL Connectors Community                108
     !mysql-tools-community/x86_64      MySQL Tools Community                      90
     !mysql80-community/x86_64          MySQL 8.0 Community Server                113
    
  5. 安装MySQL

     shell> sudo yum install mysql-community-server
    

    该命令会安装MySQL服务器 (mysql-community-server) 及其所需的依赖、相关组件,包括mysql-community-client、mysql-community-common、mysql-community-libs等
    安装时间根据带宽决定

  6. 操作MySQL服务(启动/停止/重启/状态)

      # 启动
      shell> sudo systemctl start mysqld.service
     
      # 查看状态
      shell> sudo systemctl status mysqld.service
     
      # 停止
      shell> sudo systemctl stop mysqld.service
     
      # 重启
      shell> sudo systemctl restart mysqld.service
    
  7. 修改密码

     # 查看默认密码
     shell> sudo grep 'temporary password' /var/log/mysqld.log
    
     # 修改密码
     shell> mysql -uroot -p
     mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
    

    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    出现这个错误提示是因为密码太简单了

    1. 使用复杂密码,MySQL默认的密码策略是要包含数字、字母及特殊字符
    2. 如果只是测试用,不想用那么复杂的密码,可以修改默认策略,即validate_password_policy(以及validate_password_length等相关参数),使其支持简单密码的设定,具体方法可以自行百度
    3. 修改配置文件/etc/my.cnf,添加validate_password=OFF,保存并重启MySQL
  8. 允许root远程访问 && navicat连接MySQL8+时出现2059错误解决方法

     mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
     # 'root'可以改为你自己定义的用户名,
     # 'localhost'指的是该用户开放的IP,可以是'localhost'(仅本机访问,相当于127.0.0.1),可以是具体的'*.*.*.*'(具体某一IP),也可以是'%'(所有IP均可访问)。
     # 'password'是你想使用的验证密码
    
  9. 设置编码为utf8 & 设置开机启动

     # 查看编码
     mysql> SHOW VARIABLES LIKE 'character%';
     # 编辑/etc/my.cnf,[mysqld]节点增加以下代码
     [mysqld]
     character_set_server=utf8
     init-connect='SET NAMES utf8'
     
     # 开机启动
     shell> systemctl enable mysqld
     shell> systemctl daemon-reload
    

四. 安装redis

  1. 更新yum源
     sudo yum install epel-release
     sudo yum update
    
  2. 安装
     sudo yum -y install redis
    
  3. 启动
     sudo systemctl start redis
    
  4. 常用操作
    systemctl start redis.service #启动redis服务器
    systemctl stop redis.service #停止redis服务器
    systemctl restart redis.service #重新启动redis服务器
    systemctl status redis.service #获取redis服务器的运行状态
    systemctl enable redis.service #开机启动redis服务器
    systemctl disable redis.service #开机禁用redis服务器
    

五. 安装supervisor

  1. 安装
     easy_install supervisor
    
  2. 创建配置文件
     echo_supervisord_conf > /etc/supervisord.conf
    

六. 安装Git

  1. 安装
     yum install git
    
  2. 生成密钥
     ssh-keygen -t rsa -C “your email address”
    
  3. GitHub添加公钥
    公钥位置:/root/.ssh/id_rsa.pub
  4. 测试
     shell > ssh git@github.com
     Are you sure you want to continue connecting (yes/no)?
     shell > yes
     Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell accessConnection to github.com closed.
    
  5. init后使用

七. 安装MySQLdb

  1. 安装
     yum -y install mysql-devel libffi-devel 
     pip install mysqlclient
    
  2. 检查
     (base)shell> python
     >>> import MySQLdb
     >>>
    

八. 安装各种Python包

  1. celery
    安装:

     install celery
    

    -bash: celery: command not found 解决方法

     export PATH=/anaconda3/bin:$PATH # 路径替换为python包所在目录
     
     # 避免重启丢失
     sudo echo 'export PATH=/ananaconda3/bin:$PATH' >> /etc/profile.d/python3.sh
    
  2. uwsgi
    安装

    pip install uwsgi
    
  3. scrapy
    安装

     pip install scrapy scrapyd scrapyd-client python-scrapyd-api
    

九. 配置迁移

  1. 获取文件
    scp -P 22 user@ip:SourceFilePath ReceviePath
    
  2. 获取目录
    scp -P 22 -r user@ip:SourceFilePath ReceviePath
    
  3. 将本地文件上传到服务器上
    scp -P 2223 SourceFile user@ip:RecevieFile
    
  4. 将本地目录上传到服务器上
    scp -P 2223 -r SourceDirPath user@ip:RecevieDirPath
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值