Centos7安装配置ss客户端

Centos7安装配置ss客户端

注意:这是centos7.4安装配置酸酸(ss)客户端教程

1、配置epel源,安装python-pip

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install python-pip
pip install –upgrade pip
1
2
3
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install python-pip
pip install –upgrade pip

2、安装shadowsocks

pip install shadowsocks
1
pip install shadowsocks

3、创建配置文件

mkdir /etc/shadowsocks
1
mkdir /etc/shadowsocks

vi /etc/shadowsocks/shadowsocks.json
1
vi /etc/shadowsocks/shadowsocks.json
添加以下内容

{
“server”:”69.17.66.77″,
“server_port”:6666,
“local_address”: “127.0.0.1”,
“local_port”:1080,
“password”:”password”,
“timeout”:300,
“method”:”aes-256-cfb”,
“fast_open”: false,
“workers”: 1
}
1
2
3
4
5
6
7
8
9
10
11
{
“server”:”69.17.66.77″,
“server_port”:6666,
“local_address”: “127.0.0.1”,
“local_port”:1080,
“password”:”password”,
“timeout”:300,
“method”:”aes-256-cfb”,
“fast_open”: false,
“workers”: 1
}
备注:
server填写你代理服务器的IP
server_port代理服务器设置的端口
password代理服务器密码
这几个参数很好理解,前提是你了解过并且有ss代理

4、配置自启动

vi /etc/systemd/system/shadowsocks.service
1
vi /etc/systemd/system/shadowsocks.service
添加以下内容

[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/sslocal -c /etc/shadowsocks/shadowsocks.json
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/sslocal -c /etc/shadowsocks/shadowsocks.json
[Install]
WantedBy=multi-user.target
5、启动shadowsocks客户端

systemctl enable shadowsocks.service
systemctl start shadowsocks.service
systemctl status shadowsocks
1
2
3
systemctl enable shadowsocks.service
systemctl start shadowsocks.service
systemctl status shadowsocks
6、验证

验证shadowsocks客户端是否正常运行,正常会返回你的代理IP

curl –socks5 127.0.0.1:1080 http://httpbin.org/ip
1
curl –socks5 127.0.0.1:1080 http://httpbin.org/ip
7、安装配置privoxy

Shadowsocks是一个socket5服务,我们需要使用privoxy把流量转到http/https上

yum install privoxy
1
yum install privoxy
8、启动privoxy

systemctl enable privoxy
systemctl start privoxy
systemctl status privoxy
1
2
3
systemctl enable privoxy
systemctl start privoxy
systemctl status privoxy
9、配置privoxy

vi /etc/privoxy/config
1
vi /etc/privoxy/config
确保以下两行内容没有被注释掉,forward-socks5t这里端口改成1080,listen-address默认端口不用改

listen-address 127.0.0.1:8118
forward-socks5t / 127.0.0.1:1080 .
1
2
listen-address 127.0.0.1:8118
forward-socks5t / 127.0.0.1:1080 .
10、修改/etc/profile

vi /etc/profile
1
vi /etc/profile
在最下面添加以下内容

export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
1
2
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
使其生效

source /etc/profile
1
source /etc/profile
11、验证

curl www.google.com
1
curl www.google.com
如果可以正常返回内容,即表示配置成功

docker 从入门到放弃—5. docker sprintboot 日志时区不对

解决方案

方案1,
最傻瓜也最方便的处理方式(可能日志任然不对,系统的时间对了)

docker run -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime -ti centos bash
以上将宿主机的时间与本地时间绑定到容器中,这样时间就会跟宿主机一样了。

/etc/timezone 时区
/etc/localtime 时间

验证时间是否正确,在控制台输入以下命令即可

date

方案2

CentOS镜像在Dockerfile 中添加一行命令

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

方案3

终极解决方案,在以上设置完系统的时区后仍然不生效
springboot项目设置时区
    @PostConstruct
   void setDefaultTimezone() {
      TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
//    TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
   }

用任何一个都行,将默认时区设置为东八区。

应用场景:有时候应用服务器的时间是UTC协调世界时间,在我们用浏览器访问的时候,就会出现日期快八小时,

因为服务器的时区跟我们东八区差八个小时导致的,用以上方法可以解决这个问题

docker 从入门到放弃—4.Jenkins 构建node docker镜像

1.Dockerfile 内容如下:发布至代码根目录

# Start with a base image containing Java runtime
FROM node:latest

#未镜像设定作者
MAINTAINER liuhubo@*.com

# 给镜像制定标签
LABEL h5.*.com node

#set workdir
WORKDIR /work

# Add a volume pointing to /work
VOLUME /work

# Make port 8080 available to the world outside this container
EXPOSE 3000

#将打包好的jar 上传到镜像的对应工作目录
ADD . /work/

#将在当前镜像基础上执行指定命令,并提交为新的镜像
RUN npm install -g cnpm –registry=https://registry.npm.taobao.org \
npm install pm2 -g –registry=https://registry.npm.taobao.org

RUN chmod +x /work/docker_start.sh

CMD /bin/sh /work/docker_start.sh

 

2,docker_start.sh 内容如下:发布至代码根目录

cd /work
npm run start-test
pm2 logs -f 0

此处的启动需要解决启动后项目自动停止的问题,所以添加了pm2 logs -f 0

 

3.shell 内容

cd $WORKSPACE
project_name=”h5″
find $WORKSPACE -type d -name “.git”|xargs rm -rf
. ~/.nvm/nvm.sh
nvm use 8.11.2
echo `date +%y_%m_%d_%H%M_%S`_N_${BUILD_NUMBER} >version.txt
cnpm install
cnpm run build-test
chmod 755 docker_start.sh

docker build -t node_pm2_$project_name .
echo ‘================开始推送镜像================’
docker tag -f node_pm2_$project_name:latest registry.cn-beijing.aliyuncs.com/yourname/test:$project_name
docker push registry.cn-beijing.aliyuncs.com/yourname/test:$project_name
echo ‘================结束推送镜像================’

 

 

docker 从入门到放弃—3.Jenkins 构建sprint-boot镜像,推docker仓库,发布脚本

1.第一步,登录到Jenkins后台,添加Jenkins到发布的环境服务器的免密登录,并且测试可以连通

测试连接的结果需要是success

 

2,将Dockerfile 配置好提交到代码的根目录

Dockerfile内容如下

# Start with a base image containing Java runtime  这里需要根据自己的环境选择镜像
FROM registry.cn-beijing.aliyuncs.com/*com/pro:base

#未镜像设定作者
MAINTAINER name@*.com

# 给镜像制定标签
LABEL appapi.*.com springboot appapi.jar

#set workdir
WORKDIR /work

# Add a volume pointing to /work
VOLUME /work

# Make port 8080 available to the world outside this container
EXPOSE 9090

#将打包好的jar 上传到镜像的对应工作目录#根据自己打包后生成的项目名称更改
ADD name.jar /work/app.jar

#将在当前镜像基础上执行指定命令,并提交为新的镜像
RUN sh -c ‘touch /work/app.jar’
RUN  ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#设置java启动的参数
ENV JAVA_OPTS=”-server -Xms1024m -Xmx1024m”

#设置启动jar 包的命令
ENTRYPOINT [ “sh”, “-c”, “java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /work/app.jar” ]

 

3.新建项目并且正确的配置Git地址用户,打包等信息

Shell 内容如下

java -version

yourname=test
project_name=”app”
echo ‘================开始构建镜像================’

cd $yourname-$project_name
cp Dockerfile $WORKSPACE/$yourname-$project_name/target/
cd $WORKSPACE/$yourname-$project_name/target/
docker build -t spring-boot-$yourname-${project_name}api .
echo ‘================开始推送镜像================’
docker tag -f spring-boot-$yourname-${project_name}api:latest registry.cn-beijing.aliyuncs.com/$yourname/test:${project_name}api
docker push registry.cn-beijing.aliyuncs.com/$yourname/test:${project_name}api
echo ‘================结束推送镜像================’

ssh root@192.168.1.100 “/data/script/docker_pull.sh appapi 9010 9090”
echo ‘================服务启动完成================’

 

 

1.100服务器上的发布脚本内容如下

 

 

#!/bin/bash
#传入参数匹配
echo “开始匹配传入参数……”

if [ $# -lt 1 ]; then
echo “you must use like this : ./jenkins.sh <projectname> <serviceport> <dockerport>”
echo “sh jenkins.sh mapi 8080 8080”
exit
fi
if [ -n “$2” ]; then
echo ‘2’
serviceport=$2
fi

if [ -n “$3” ]; then
echo ‘3’
dockerport=$3
fi

docker stop $1
docker rm $1
docker login –username=username  –password=username   registry.cn-beijing.aliyuncs.com
docker pull registry.cn-beijing.aliyuncs.com/*com/test:$1
docker run –name=$1 -p $serviceport:$dockerport -v /data/www/$1:/work/logs -d registry.cn-beijing.aliyuncs.com/*com/test:$1

echo “finished!”

 

 

docker 从入门到放弃—2.docker 配置使用阿里云的源地址

1.打开阿里云控制台,没有的可以用淘宝账号或者支付宝账号直接登录

打开容器镜像服务,镜像加速器,复制加速器地址

2. 修改配置文件

$:    vi /etc/docker/daemon.json

添加加速器地址:

3.重启docker

systemctl daemon-reload

systemctl restart docker

完成后,你就会发现,下载oracle也就3分钟以内了,速度嗖嗖的

docker 从入门到放弃—1.docker 环境安装

Centos7上安装docker

Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE。

社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施、容器、插件等。

社区版按照stable和edge两种方式发布,每个季度更新stable版本,如17.06,17.09;每个月份更新edge版本,如17.09,17.10。

 一、安装docker

1、Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

通过 uname -r 命令查看你当前的内核版本

 $ uname -r

2、使用 root 权限登录 Centos。确保 yum 包更新到最新。

$ sudo yum update

3、卸载旧版本(如果安装过旧版本的话)

$ sudo yum remove docker  docker-common docker-selinux docker-engine

4、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

5、设置yum源

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

6、可以查看所有仓库中所有docker版本,并选择特定版本安装

$ yum list docker-ce --showduplicates | sort -r

7、安装docker

$ sudo yum install docker-ce  #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
$ sudo yum install <FQPN>  # 例如:sudo yum install docker-ce-17.12.0.ce

8、启动并加入开机启动

$ sudo systemctl start docker
$ sudo systemctl enable docker

9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

$ docker version

 

 二、问题

1、因为之前已经安装过旧版本的docker,在安装的时候报错如下:

复制代码
Transaction check error:
  file /usr/bin/docker from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd-shim from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/dockerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
复制代码

2、卸载旧版本的包

$ sudo yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

3、再次安装docker

$ sudo yum install docker-ce

阿里云的源yum方式安装Mongodb

1)在/etc/yum.repos.d 创建一个mongodb-org.repo 源文件

[root@qd-vpc-dev-op01 ~]$ cd /etc/yum.repos.d/
[root@qd-vpc-dev-op01 yum.repos.d]$ touch mongodb-org.repo
[root@qd-vpc-dev-op01 yum.repos.d]$ cat mongodb-org.repo
[mongodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1
根据自己的系统版本选择填写的5  6  7版本的源
2)清空缓存和更新yum源
[root@qd-vpc-dev-op01 yum.repos.d]$ yum clean all
[root@qd-vpc-dev-op01 yum.repos.d]$ yum make cache
#更新yum源
[root@qd-vpc-dev-op01 yum.repos.d]$ yum update
3) 安装MongoDB
[root@qd-vpc-dev-op01 yum.repos.d]$ yum install -y mongodb-org
4)启动MongoDB
[root@qd-vpc-dev-op01 yum.repos.d]$ service mongod start
[root@qd-vpc-dev-op01 yum.repos.d]$ chkconfig mongod on
5)配置远程访问
[root@qd-vpc-dev-op01 yum.repos.d]$cat /etc/mongod.conf|grep -v "#"|grep -v "^$"
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
processManagement:
net:
  port: 27017
[root@qd-vpc-dev-op01 yum.repos.d]$ service mongod restart
Restarting mongod (via systemctl):                         [  OK  ]
6)打开MongoDB
[root@qd-vpc-dev-op01 yum.repos.d]$ mongo 127.0.0.1:27017
MongoDB shell version: 3.2.16
connecting to: 127.0.0.1:27017/test
Server has startup warnings:
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten]
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten]
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten]
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2017-09-30T18:27:19.681+0800 I CONTROL  [initandlisten]

利用阿里云pythonSDK修改RSD白名单

因为公司没有购买公网IP,每次路由器重启后IP 就会变动,阿里云服务器上的RDS需要指定白名单才能访问!为了安全性也不能开放所有的IP,每次IP变更后就需要去修改白名单不厌其烦!
参考了GiveMeFive_Y的博客源码https://blog.csdn.net/GiveMeFive_Y/article/details/78687665
修改了一个适合自己的使用的版本
第一步安装SDK

#pip install aliyun-python-sdk-rds
#pip install aliyun-python-sdk-ecs

第二步修改参数

#!/usr/bin/env python
# coding=utf-8
import requests
import json
import os
import re
import sys
from aliyunsdkcore import client
from aliyunsdkecs.request.v20140526 import DescribeSecurityGroupAttributeRequest
from aliyunsdkecs.request.v20140526 import AuthorizeSecurityGroupRequest
from aliyunsdkecs.request.v20140526 import AuthorizeSecurityGroupEgressRequest
from aliyunsdkecs.request.v20140526 import RevokeSecurityGroupRequest
from aliyunsdkecs.request.v20140526 import RevokeSecurityGroupEgressRequest
from aliyunsdkecs.request.v20140526 import DescribeSecurityGroupsRequest
from aliyunsdkrds.request.v20140815 import ModifySecurityIpsRequest
AccessKey = “666666666” #此处填写阿里云的accesskey
AccessSecret = “7777777777” #此处填写阿里云的accesssecret
RegionId = “cn-shanghai” #此处填写RDS服务器所属地域
dbInstanceId = “rm-XXXXXX” #此处填写RDS服务器的实例ID
dbInstanceIPArrayName = “gongshi” #此处填写RDS数据库安全组的名称
dbInstanceIPArrayAttribute = “,” #此处填写RDS数据库安全组的IP的分割符
class Alis():
def __init__(self, AccessKey, AccessSecret, RegionId):
self.AccessKey = AccessKey
self.AccessSecret = AccessSecret
self.RegionId = RegionId
def client(self):
c = client.AcsClient(self.AccessKey, self.AccessSecret, self.RegionId)
return c
def describeSecurityGroupsRequest(self):
request = DescribeSecurityGroupsRequest.DescribeSecurityGroupsRequest()
request.set_accept_format(‘json’)
return request
def modifySecurityIpsRequest(self, DBInstanceId, SecurityIps, DBInstanceIPArrayName, DBInstanceIPArrayAttribute):
“””修改数据库实例白名单
“””
request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
request.set_DBInstanceId(DBInstanceId)
request.set_SecurityIps(SecurityIps)
request.set_DBInstanceIPArrayName(DBInstanceIPArrayName)
request.set_DBInstanceIPArrayAttribute(DBInstanceIPArrayAttribute)
return request
def my_ip_method_1(self):
get_ip_method = os.popen(‘curl -s ip.cn’)
get_ip_responses = get_ip_method.readlines()[0]
get_ip_pattern = re.compile(r’\d+\.\d+\.\d+\.\d+’)
get_ip_value = get_ip_pattern.findall(get_ip_responses)[0]
print get_ip_value
return get_ip_value
def my_ip_method_2(self):
get_ip_method = os.popen(‘curl -s http://ip-api.com/json’)
get_ip_responses = get_ip_method.readlines()[0]
get_ip_responses = eval(str(get_ip_responses))
get_ip_value = get_ip_responses[‘query’]
return get_ip_value
def my_ip_method_3(self):
get_ip_method = requests.get(‘http://ifconfig.co/json’).content
get_ip_value = eval(get_ip_method)
get_ip_value = get_ip_value[‘ip’]
request = get_ip_value
return request
def read_old_ip(slef):
f = open(‘./ip.txt’)
line = f.read().splitlines()
print line[0]
f.close()
return line[0]
def write_ip_txt(slef,ip):
f = open(‘./ip.txt’,’w’)
print ip
f.write(ip)
f.close()
if __name__ == ‘__main__’:
ali = Alis(AccessKey, AccessSecret, RegionId) # 阿里云后台创建
clt = ali.client()
securityIps = ali.my_ip_method_1()#根据自己情况确定使用哪个公网IP查询接口
old_ip = ali.read_old_ip()
if old_ip == securityIps:
print(‘The specified value of parameter Value is the same as old’)
else:
req = ali.modifySecurityIpsRequest(dbInstanceId, securityIps,dbInstanceIPArrayName, dbInstanceIPArrayAttribute)
res = clt.do_action_with_exception(req)
print(“修改RDS白名单%s” % res)
ip=securityIps
ali.write_ip_txt(ip)
第三步在python的目录下建立一个ip.txt的空文件夹,用于存储记录之前的历史IP
 
 
 
 

利用阿里云接口动态设置DDNS

因为公司没有购买公网IP,每次路由器重启后IP 就会变动,但是公司有很多服务器需要外网的回调进行开发调试!本来是使用的花生壳的动态域名解析,但是花生壳不争气啊,免费的动态服务,动不动就挂掉,不厌其烦!
还好阿里云的域名提供了接口更新DNS映射,并且阿里云的DNS修改后生效非常的快!
本着重来不干重复造轮子的事情,通过收索找到了一个可以动态通过接口修改IP的python源码  ,github地址https://github.com/terencechuen/terence_proj/tree/master/aliyun_ddns
我的centos服务器使用的是python2的环境,使用的下面这个版本的python代码
将此代码下载到linux 服务器,然后编辑源代码
# -*- coding: UTF-8 -*-
import json
import os
import re
import sys
from datetime import datetime
import requests
from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest, DescribeDomainRecordsRequest, \
DescribeDomainRecordInfoRequest
from aliyunsdkcore import client
access_key_id = “”
access_Key_secret = “”
# 请填写你的账号ID
account_id = “”
# 如果填写yes,则运行程序后仅显示域名信息,并不会更新记录,用于获取解析记录ID。
# 如果填写no,则运行程序后不显示域名信息,仅更新记录。
i_dont_know_record_id = ‘no’
# 请填写你的一级域名
rc_domain = ‘baidu.com’
# 请填写你的解析记录
rc_rr = ‘vpn’
# 请填写你的记录类型,DDNS请填写A,表示A记录
rc_type = ‘A’
# 请填写解析记录ID
rc_record_id = ‘3825227609856000’
# 请填写解析有效生存时间TTL,单位:秒
rc_ttl = ‘600’
# 请填写返还内容格式,json,xml
rc_format = ‘json’
def my_ip_method_1():
get_ip_method = os.popen(‘curl -s ip.cn’)
get_ip_responses = get_ip_method.readlines()[0]
get_ip_pattern = re.compile(r’\d+\.\d+\.\d+\.\d+’)
get_ip_value = get_ip_pattern.findall(get_ip_responses)[0]
return get_ip_value
def my_ip_method_2():
get_ip_method = os.popen(‘curl -s http://ip-api.com/json’)
get_ip_responses = get_ip_method.readlines()[0]
get_ip_responses = eval(str(get_ip_responses))
get_ip_value = get_ip_responses[‘query’]
return get_ip_value
def my_ip_method_3():
get_ip_method = requests.get(‘http://ifconfig.co/json’).content
get_ip_value = eval(get_ip_method)
get_ip_value = get_ip_value[‘ip’]
return get_ip_value
def check_records(dns_domain):
clt = client.AcsClient(access_key_id, access_Key_secret, ‘cn-hangzhou’)
request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
request.set_DomainName(dns_domain)
request.set_accept_format(rc_format)
result = clt.do_action_with_exception(request)
result = result.decode()
result_dict = json.JSONDecoder().decode(result)
result_list = result_dict[‘DomainRecords’][‘Record’]
for j in result_list:
print(‘Subdomain:’ + j[‘RR’].encode() + ‘ ‘ + ‘| RecordId:’ + j[‘RecordId’].encode())
return
def old_ip():
clt = client.AcsClient(access_key_id, access_Key_secret, ‘cn-hangzhou’)
request = DescribeDomainRecordInfoRequest.DescribeDomainRecordInfoRequest()
request.set_RecordId(rc_record_id)
request.set_accept_format(rc_format)
result = clt.do_action_with_exception(request).decode()
result = json.JSONDecoder().decode(result)
result = result[‘Value’]
return result
def update_dns(dns_rr, dns_type, dns_value, dns_record_id, dns_ttl, dns_format):
clt = client.AcsClient(access_key_id, access_Key_secret, ‘cn-hangzhou’)
request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
request.set_RR(dns_rr)
request.set_Type(dns_type)
request.set_Value(dns_value)
request.set_RecordId(dns_record_id)
request.set_TTL(dns_ttl)
request.set_accept_format(dns_format)
result = clt.do_action_with_exception(request)
return result
def write_to_file():
time_now = datetime.now().strftime(‘%Y-%m-%d %H:%M:%S’)
current_script_path = sys.path[1]
print current_script_path
log_file = ‘/root/ddns’ + ‘/’ + ‘aliyun_ddns_log.txt’
write = open(log_file, ‘a’)
write.write(time_now + ‘ ‘ + str(rc_value) + ‘\n’)
write.close()
return
if i_dont_know_record_id == ‘yes’:
check_records(rc_domain)
elif i_dont_know_record_id == ‘no’:
rc_value = my_ip_method_1()
print rc_value
rc_value_old = old_ip()
if rc_value_old == rc_value:
print(‘The specified value of parameter Value is the same as old’)
else:
print(update_dns(rc_rr, rc_type, rc_value, rc_record_id, rc_ttl, rc_format))
write_to_file()
 
执行改脚本
[root@localhost ddns]# python AliyunDDNS_NonSDK.py
[#180328-15:19] DNS Record was updated from [1797x1q502.imwork.net] to [171.217.104.245].