【博客项目】服务器环境搭建与问题解决(完)

3 篇文章 0 订阅
2 篇文章 0 订阅
开发时用的是python3.6而服务器python还是2.6,2.X 与3.X版本存在兼容性问题,所以我把服务器python版本升级到3.X版本。


``` 
[root@host ~] wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz 


[root@host ~] yum install xz


xz -d Python-3.6.0.tar.xz    


// 会产生一个 Python-3.6.0.tar, 再用tar解压


tar -zxvf Python-3.6.0.tar


cd Python-3.6.0
```
源码安装一般由3个步骤组成: 配置(configure)、编译(make)、安装(make intall)。


我们将python3.6 安装到 /usr/local/python3.6 方便以后管理。


```


[root@host Python-3.6.0] ./configure --prefix=/usr/local/python3.6 
 
// ./configure 会自动创建python3.6


[root@host Python-3.6.0] make && make install


// 备份原有python,centos 6.5 默认python版本为2.6


[root@host Python-3.6.0] mv /usr/bin/python /usr/bin/python2.6


// 建立软链接指向python3.6.0 修改默认python


ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python


python --version // 查看版本
```


因为yum依赖python而我们修改了默认python,所以要将yum 指向旧版本,这是python升级后与yum不兼容带来的问题


centos 没有安装vim 所以现在将vim装上 ,当然也可以使用自带的 vi编辑器。


```
yum install vim


// yum指向旧版本python


vim /usr/bin/yum
```


将第一行中 "#!/usr/bin/python" 修改为 #!/usr/bin/python2.6   // python2.6 在上面的部分备份过


现在可以愉快的安装 django、uwsgi、nginx


```
pip install django
```


出错了!! 大致意思缺少SSL模块


```
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 
```


这也是python升级后必然产生的问题


```
[root@host ~] python
Python 3.6.0 (default, Mar  9 2018, 08:16:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>import ssl
```
果然提示找不到 ssl模块 


1.查看openssl


```
[root@host ~] rpm -aq|grep openssl


openssl-1.0.1e-57.el6.x86_64
```


原来是缺少openssl-devel 开发包


```
yum install openssl-devel -y
```


2.修改Setup.py文件


```
[root@host ~] cd /Python-3.6.0/Modules


[root@host Python-3.6.0] vim Setup


# Socket module helper for socket(2)
#_socket socketmodule.c


# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
:wq  
```


3.退出并保存


```
[root@host Python-3.6.0] make && make install


[root@host ~] python
Python 3.6.0 (default, Mar  9 2018, 08:17:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 
```


成功!!!


现在才真正的愉快的安装django、uwsgi、nginx.


```
pip install django
```


为了全局能够使用django-admin,建立软链接


```
ln -s /usr/local/python3.6/bin/django-admin.py /usr/bin/django-admin
```


创建django项目


```
django-admin starproject Blog


cd Blog
```


##### 安装 uwsgi


```
pip install uwsgi


ln -s /usr/local/python3.6/bin/uwsgi /usr/bin/uwsgi
```
测试安装是否成功


```
vim test.py


def application(env, response):
    response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]
```
执行该文件
```
uwsgi --http :8002 --wsgi-file test.py
```


在客户端浏览器中输入地址:


远程ip:8002 


成功出现 "hello world"




##### 安装mysql5.7


1.查看系统是否自带mysql


```
rpm -qa | grep mysql
```


2.删除自带的mysql


```
rpm -ev mysql-server-5.1.73-7.el6.x86_64 


rpm -ev mysql-5.1.73-7.el6.x86_64
```


3.下载mysql5.7


```
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm


```
4.安装rpm文件


```
yum install mysql-community-release-el6-5.noarch.rpm
````


将/etc/yum.repos.d/mysql-community.repo下MySQL5.7源改为enable=1


```
vim /etc/yum.repos.d/mysql-community.repo
```
mysql-connectors-community  
mysql-tools-community
这俩个也是需要的


正式安装mysql5.7


```
yum install mysql-community-server
```


5.启动mysql


```
service mysqld start
```


6.查看默认密码


```
 grep 'temporary password' /var/log/mysqld.log


A temporary password is generated for root@localhost:******
```


7.登录mysql
```
mysql -u root -p
Enter password:


mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');
```
在这里修改密码时,简单密码会出错


ERROR 1819 (HY000): Your password does not satisfy the current policy requirements


执行


```
set global validate_password_policy=0;


set global validate_password_length=1;
```
再执行


```
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');
```


8.查看是否开机自启动


```
chkconfig --list | grep mysqld
```


如果都为off


执行


```
chkconfig mysqld on
```


修改字符集


```
vim /etc/my.cnf
```


在[mysqld]下添加:


```
character-set-server=utf8
init_connect='SET NAMES utf8'
```


我这里没有客户端,所以客户端就不用管了。


9.重启mysql


```
service mysqld restart


mysql>show variables like "%character%";
```


这里有个小坑 当创建数据库后 django migrate到数据中还是报编码错误,前面已经设置了编码为utf-8为什么还会报错呢,原来我指定的是数据表
数据库的编码还是默认的编码


这时只需将原来的数据库删除。重新建一个数据库并指定默认编码为utf8


```
mysql> create database xxxx  charset=utf8;
```


##### 安装nginx


1.安装nginx依赖


```
yum install gcc-c++
yum -y install pcre*
```


前面已经有openssl,这里就不需要安装了


2.下载nginx-1.13.9


```
wget https://nginx.org/download/nginx-1.13.9.tar.gz
```


3.解压


```
tar -zxvf nginx-1.13.9.tar.gz
cd nginx-1.13.9
```


4.设置安装目录


```
./configure --prefix=/usr/local/nginx
```


5.编译安装


```
make & make install 
```


6.启动nginx


```
cd /usr/local/nginx


./nginx
```


python升级后产生的问题: 缺少SSL模块


同样是修改Setup.py文件时,依然出现缺少SSL模块的错误


猜想: 可能是原先我胡乱安装 openssl 导致有多个目录 无法确定到底哪个才是运行的,所以修改Setup.py文件无效。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值