一.使用网络yum源安装软件
1.rpm包管理
- 光盘挂载
cd /etc/yum.repos.d/
mount /dev/cdrom /mnt
cd /mnt
ls
- 安装rpm包
rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
下面一个可以升级
rpm -Uvh vsftpd-3.0.2-22.el7.x86_64.rpm
- 卸载rpm
rpm -e vsftpd-3.0.2-22.el7.x86_64
- rpm包的查询
[root@python3 ~]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64
[root@python3 ~]# rpm -q vsftp
package vsftp is not installed
- 所有软件包查询
[root@python3 ~]# rpm -qa
[root@python3 ~]# rpm -qa |grep vsf #过滤
- which查看命令的路径
[root@python3 ~]# which vim
/usr/bin/vim
[root@python3 ~]# rpm -qf /usr/bin/vim
2 .yum 使用
- 使用aliyun yum站点源
cd /etc/yum.repos.d/
mkdir
mv *.repo /tmp
- 在阿里云的光盘
wget http://mirrors.aliyun.com/repo/Centos-7.repo
- EPEL源
yum install -y epel-release
- 使用yum安装软件
yum install -y openssl openssl-devel
二.本地yum源和局域网yum优化
1.软件包查询及组安装
yum list |grep vsftpd
yum grouplist
yum groupinstall "Development Tools"
2.卸载软件包
yum remove
3.优化yum源
- 本地镜像yum源(光盘挂载到/mnt下)
[local]
name=localios
baseurl=file:///mnt
gpgcheck=0
清除缓存
yum clean all
yum install -y vsftpd
- 局域网yum源(ftp)
1.安装ftp软件
yum install -y vsftpd
2.启动ftp服务
[root@python3 ~]# systemctl start vsftpd
开机自动启动
[root@python3 ~]# systemctl enable vsftpd
3.创建站点目录,并将光盘软件拷贝其中
[root@python3 ~]# mkdir /var/ftp/pub/centos7
[root@python3 ~]# cp -a /mnt/* /var/ftp/pub/centos7
4.生成ftp站点的yum源配置文件
[ftp]
name=centos7
baseurl=ftp://10.0.0.100/pub/centos7
gpgcheck=0
三.linux压缩包解压方式
1.解压
.zip
unzip xxx.zip
.tar
.tar.gz
.tgz
.tar.bz2
.tar.xz
tar xf xxx.tar
.iso
mount -o loop xxx.iso /test
.cpio
cpio -idcmv < xxx.cpio
四.python安装
准备工作
yum install -y gcc
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel -y
- python3.6源码包安装
./configure #配置 ------> 定制功能
make #gcc编译源码生成二进制
make install #把编译好的二进制拷贝到具体目录
make & make install
-----------------------------------------------------------------------------------------
#若是安装失败可执行下面的操作
1. 解压,编译
tar Jxvf Python-3.5.1.tar.xz
cd Python-3.5.1
./configure --prefix=/usr/local/python3
make && make install
这里注意这个 –prefix选项,将python3安装在/usr/local/python3目录下,而之前下载的压缩包和安装包就都可以直接删除了。
2. 更换系统默认的python和pip版本
备份系统旧的python版本
mv /usr/bin/python /usr/bin/python2.7
3.建立指向新python3和pip3的软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
之前出错就是把pip的软链接路径写错导致找不到pip3
4.检查python和pip版本
python -V
pip -V
可以参考:https://www.cnblogs.com/simuhunluo/p/7704765.html
出错解决方法:https://segmentfault.com/q/1010000003894661
https://blog.csdn.net/chaojiwanwan/article/details/71439066
五.mysql安装
- mysql源码包安装
cmake
make
make install
六.redis安装
1.redis源码包安装
make
2.修改环境变量
vim /etc/profile
在命令模式输入G进入最后一行添加以下命令:
export PATH=/opt/redis-3.2.10/src:$PATH
3.生效配置
source /etc/profile
4.启动redis
[root@petrus redis-3.2.10]# redis-server redis.conf
#后台启动redis
5.查看redis端口启动没有
netstat -tulnp
#如果netstat没安装:yum install net-tools
6.让python链接redis
unzip redis-py-master.zip
cd redis-py-master
python3 setup.py install #手动安装python包
7.对redis的单实例进行连接操作
cd redis-py-master
python3
import redis
r = redis.StrictRedis(host='localhost', port=6379)
r.set('name', 'petrus')
r.get('name')
'petrus'
8.安装过程中出现的问题
- 问题一:
在阿里云主机上安装完redis后,在进行连接测试的时候可能测试正常,但在本地通过redis客户端连接的时候连接不上,无非是以下几个问题:
1.开放6379端口,去阿里云管理后台 添加安全组规则,将入网方向和出网方向添加6379端口
2.去redis配置文件,改以下几个地方的配置
[root@petrus redis-3.2.10]# vim redis.conf
bind 0.0.0.0 #如果为127.0.0.1 改成0.0.0.0 或者注释掉
daemonize yes #允许后台启动
protected-mode no
requirepass 123456
然后重新启动redis
七.mysql(5.7.20)二进制包简易安装
1.解压及制作软连接
tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql #软连接
2.编辑环境变量
vim /etc/profile
添加以下一行:
export PATH=/opt/mysql/bin:$PATH
3.生效配置
source /etc/profile
4.卸载自带mariadb
yum remove mariadb-libs
5.生成配置文件(/etc/my.cnf)
vim /etc/my.cnf
---------------------------
[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
user=mysql
log_error=/var/log/mysql.log
log_bin=/opt/mysql/data/mysql-bin
server_id=100
bind-address=0.0.0.0
[mysql]
socket=/tmp/mysql.sock
bind-address=0.0.0.0
------------------------------
6.创建用户和数据目录,并授权
useradd mysql
mkdir /opt/mysql/data
chown -R mysql.mysql /opt/mysql #授权
7.初始化数据
mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
报错解决:
问题:mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum install -y libaio //安装后在初始化就OK了
问题:2019-04-10T04:00:38.252207Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-10T04:00:38.270079Z 0 [ERROR] Could not open file '/var/log/mysql.log' for error logging: Permission denied
2019-04-10T04:00:38.270154Z 0 [ERROR] Aborting
解决:touch /var/log/mysql.log
chown -R mysql.mysql /var/log/mysql.log
再次运行:mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
8.启动mysql
cd /opt/mysql/support-files
./mysql.server start
9.为了方便管理将mysql.server 拷贝到/etc/init.d/mysqld
cp mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld restart #重启mysql
#扩展:使用systemctl 管理mysql
vim /etc/systemd/system/mysqld.service
复制粘贴以下代码:
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl restart mysqld #首先要关闭以其他方式启动的mysqld /etc/init.d/mysqld stop
systemctl daemon-reload #如果修改里面的配置,需要执行这条命令
netstat -tulnp |grep 3306
10.测试python3链接mysql
1.创建mysql链接用户
grant all on * . * to root@'10.0.0.%' identified by '123';
2.需要建一个库
create database bbs charset utf8;
3.安装pymysql
pip3 install --upgrade pip
pip3 install pymysql
4.python代码测试:
vim testmysql.py
#!/usr/bin/python3
import pymysql
db = pymysql.connect("10.0.0.7","root","123","bbs" )
cursor=db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : %s " % data)
db.close()
5.执行脚本
python3 testmysql.py
八.Nginx安装
1.使用官方仓库安装Nginx
vim /etc/yum.repos.d/nginx.repo
-----------------------------------
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
---------------------------------------
2.安装Nginx
yum install nginx -y
3.启动Nginx,并将Nginx加入开机自启
systemctl start nginx
systemctl enable nginx
九.Django安装所需包
1.依赖包
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel -y
2.安装Django框架
pip3 install --upgrade pip
pip3 install uwsgi
pip3 install django
pip3 install pymysql
pip3 install pyredis
pip3 install bs4
#下载速度太慢,进行批量安装
vim re.txt #生成版本文件
asn1crypto==0.24.0
beautifulsoup4==4.6.3
bs4==0.0.1
certifi==2018.4.16
cffi==1.11.5
chardet==3.0.4
Click==7.0
cryptography==2.3.1
Django==1.11.9
Flask==1.0.2
Flask-Cors==3.0.6
gevent==1.3.6
greenlet==0.4.15
idna==2.7
ItsDangerous==1.1.0
Jinja2==2.10
lxml==4.2.6
MarkupSafe==1.0
numpy==1.15.3
Pillow==5.3.0
pycparser==2.18
PyMySQL==0.9.2
pytz==2018.7
requests==2.19.1
selenium==3.141.0
six==1.11.0
urllib3==1.23
virtualenv==16.1.0
Werkzeug==0.14.1
wordcloud==1.5.0
pip3 install -i https://pypi.doubanio.com/simple/ -r re.txt
3.安装并测试uwsgi
pip3 install -i https://pypi.doubanio.com/simple/ uwsgi
vim test.py #新建 test.py文件内容如下:---在其他目录下创建
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello Django"]
进入到test.py所在目录进行测试:uwsgi --http :8001 --wsgi-file test.py & #建议用普通用户进行测试
然后在浏览器上输入:10.0.0.7:8001 出现Hello Django 说明测试成功
#杀掉uwsgi进程:ps -ef|grep python3 kill -9 PID 或者是pkill uwsgi
4.测试django是否正常,运行:
[root@web01 ~]# django-admin.py startproject demosite
[root@web01 ~]# cd demosite
[root@web01 demosite]# python3 manage.py runserver 0.0.0.0:8002
报错:
在运行这行命令的时候可能会提示sqlite3没安装,
解决:
1.先安装sqlite3
2.对python3进行重新编译
在浏览器内输入:http://127.0.0.1:8002,检查django是否运行正常。
报错:
Invalid HTTP_HOST header: '10.0.0.7:8002'. You may need to add '10.0.0.7' to ALLOWED_HOSTS.
解决:
[root@web01 demosite]# cd demosite/
[root@web01 demosite]# ls
__init__.py __pycache__ settings.py urls.py wsgi.py
[root@web01 demosite]# vim settings.py
修改settings.py里面的ALLOWED_HOSTS = ['*']
重新执行python3 manage.py runserver 0.0.0.0:8002
报错:执行django-admin.py startproject test_project(project名称)
ImportError: No module named dajango.core.management
解决:
https://blog.csdn.net/u013632854/article/details/70170195
5.配置uwsgi
[root@web01 demosite]# vim /root/demosite/uwsgi.ini
[uwsgi]
socket = 127.0.0.1:9999
master = true
workers = 2
max-requests = 1000
buffer-size = 30000
pidfile = /run/uwsgi.pid
daemonize = /var/log/uwsgi.log
uwsgi --ini /root/demosite/uwsgi.ini &
报错: 执行uwsgi --ini /root/demosite/uwsgi.ini &
-bash:uwsgi:command not found 一般是软连接的问题 ,这个错误我遇到过好多次,都是没有设置软连接造成的
解决:
https://blog.csdn.net/weixin_34297300/article/details/87601462
6.配置Nginx
[root@web01 demosite]# vim /etc/nginx/conf.d/py.conf
server {
listen 80;
server_name 10.0.0.7;
client_max_body_size 100M;
location / {
index index.html;
include uwsgi_params;
uwsgi_pass 127.0.0.1:9999; #转发的地址和端口号
uwsgi_param UWSGI_SCRIPT demosite.wsgi;
uwsgi_param UWSGI_CHDIR /root/demosite;
}
}
7.重启Nginx