服务器

首页服务器
11
Aug
0

安装uwsgi出错

错误1:
centos 6.5
python 3.6
core/routing.o: In function `uwsgi_route_condition_regexp':

routing.c:(.text+0x365c): undefined reference to `pcre_free_study'
routing.c:(.text+0x3680): undefined reference to `pcre_free_study'
collect2: ld 返回 1
*** error linking uWSGI ***

解决方法:
需要先御载pcre-devel

yum remove pcre-devel
pip3 install uwsgi 
08
Aug
0

Let's Encrypt(https证书)

支持

python2.7
git

证书申请

#获取letsencrypt
git clone https://github.com/letsencrypt/letsencrypt
#进入letsencrypt目录
cd letsencrypt
#生成证书
./letsencrypt-auto certonly --standalone --email 123@123.com -d 123.com -d www.123.com

证书保存位置

/etc/letsencrypt/live/123.com/

文件说明

cert.pem - Apache服务器端证书
chain.pem - Apache根证书和中继证书
fullchain.pem - Nginx所需要ssl_certificate文件
privkey.pem - 安全证书KEY文件

Nginx配置

#打开linux配置文件,找到HTTPS 443端口配置的server
ssl_certificate /etc/letsencrypt/live/123.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/123.com/privkey.pem;

续证书有效期(默认只有90天)

./letsencrypt-auto certonly --renew-by-default --email 123@123.com -d 123.com -d www.123.com
28
Jun
0

fastdfs安装配置

相关包的下载网址

FastDFS_v5.08.tar.gz

https://sourceforge.net/projects/fastdfs/files/

所有用得上的包下面这个链接都有

https://github.com/happyfish100

安装FastDFS依赖包libfastcommon

wget https://codeload.github.com/happyfish100/libfastcommon/zip/master
unzip master
cd libfastcommon-master/
./make.sh
./make.sh install

安装FastDFS

wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
tar xf FastDFS_v5.08.tar.gz
cd FastDFS
./make.sh && ./make.sh install

服务脚本位置

ll /etc/init.d/ |grep fdfs

样例配置文件

ll /etc/fdfs/

命令行工具

ll /usr/bin|grep fdfs
  1. 虽然FastDFS区分tracker和storage服务器,但是安装的软件及步骤均相同,只是不同的配置文件而已,因此以上安装适用tracker server和storage server

配置跟踪服务器(tracker server)

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

编辑tracker server配置文件tracker.conf

disabled=false(默认为false,表示是否无效)
port=22122(默认为22122)
base_path=/data/fastdfs/tracker

编辑client端的配置文件client.conf

base_path=/data/fastdfs/tracker
tracker_server=172.18.10.232:22122

创建tracker server数据目录

mkdir -p /data/fastdfs/tracker

启动tracker server,启动成功会自动在/data/fastdfs/tracker目录新建data和logs目录

/etc/init.d/fdfs_trackerd start
cd /data/fastdfs/tracker/
ls #自动生成了 data  logs 两个文件夹

编辑storage server配置文件storage.conf

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

disabled=false(默认为false,表示是否无效)
port=23000(默认为23000)
base_path=/data/fastdfs/storage
tracker_server=172.18.10.232:22122
store_path0=/data/fastdfs/storage
http.server_port=8888(默认为8888,nginx中配置的监听端口那之一致)

创建storage server数据目录

mkdir -p /data/fastdfs/storage

试启动storage server,启动成功会自动在/data/fastdfs/tracker目录新建data和logs目录(启动storage server的前提是tracker server必须事先已启动)

/etc/init.d/fdfs_storaged start
cd /data/fastdfs/storage/
ls #自动生成了 data  logs 两个文件夹

文件上传测试

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /download/test.jpg
返回
group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg
success ok!!
21
Jun
0

做负载均衡时遇到的多机session不正确(时间同步)

做负载均衡时遇到的多机session不正确

原因:
两个机器时间相差太大,导致session一个过期

处理:
用时间服务器同步 方法如下

同步时间服务器命令

/usr/sbin/ntpdate 10.86.1.76 &> /dev/null
开启定时同步

crontab -e

/5 * /usr/sbin/ntpdate 10.86.1.76 &> /dev/null

21
Jun
0

expect 脚本示例

最近老是在服务器上更新代码并执行 太繁琐 写个脚本玩一下

在凡事都会遇到坑的思想指导下

所以就遇到了坑:

连续执行以下两句语句,第二句就无法执行起来
spawn uwsgi /geelyapp/itil-python/uwsgi/uwsgi.ini
spawn uwsgi /geelyapp/itil-python-test/uwsgi/uwsgi.ini
或者
exec sh -c {uwsgi /geelyapp/itil-python/uwsgi/uwsgi.ini}
exec sh -c {uwsgi /geelyapp/itil-python-test/uwsgi/uwsgi.ini}
原因 应该是有输出
前者
可以用expect {eof}
试试 看看能不屏闭 (还未试过 应该可行)
后者是只要有输出,就一定会停止,暂时没有找到相关处理办法 expect脚本似乎没有异常捕获之类的东西

安装:
yum install expect

可执行:
chmod +x autosu.sh

脚本:

!/bin/expect

set timeout 60

stty -echo

cd /geelyapp/itil-python/itil-python/

spawn git checkout .

spawn git pull

expect {

"*sername*" {
             send "huang.xiao\n" ; exp_continue
            }

"*Password*" {
             send "AA123456\n"; exp_continue
             }
eof
  }

cd /geelyapp/itil-python-test/itil-python/

spawn git checkout .

spawn git pull

expect {

"*sername*" {
             send "huang.xiao\n" ; exp_continue
            }
"*Password*" {
             send "AA123456\n"; exp_continue
             }
eof
  }

spawn cd /geelyapp/itil-python-test/itil-python/Itil/

spawn rm -f /geelyapp/itil-python-test/itil-python/Itil/settings_production.py

spawn mv /geelyapp/itil-python-test/itil-python/Itil/settings_uwsgi_test.py /geelyapp/itil-python-test/itil-python/Itil/settings_production.py

exec sh -c {pgrep uwsgi | xargs kill -9}

spawn uwsgi /geelyapp/itil-python/uwsgi/uwsgi.ini

exec sh -c {nohup uwsgi "/geelyapp/itil-python/uwsgi/uwsgi.ini"}

exec sh -c {uwsgi /geelyapp/itil-python-test/uwsgi/uwsgi.ini}