Photo Blog


A Personal Blog by Chris Chen
  1. 传个照片试一下

    April 1st, 2022 118 views

    Img 6694

    PS. 发现这里贴图片,只能贴网上已经有的图片

    PS2. Home页缩略图还有问题😭

    Last edit: Apr 01, 2022 Edit Delete
  2. Scrach 3.0 下载链接

    April 1st, 2022 118 views

    分享个Scrach3.28.0的下载链接吧

    Mac(inter架构) https://www.chrischen.site/scrach/Scratch%203.28.0.dmg

    Windows https://www.chrischen.site/scrach/Scratch%203.28.0%20Setup.exe

    Last edit: Apr 01, 2022 Edit Delete
  3. 磁盘已删除文件查找和清理

    September 9th, 2017 118 views

    今天磁盘一直告警,但是用du查看根目录大小又很少,和df的结果差了好几G,不知道被什么占着。

    解决: 用 sudo lsof -n | grep delete 查看已删除文件,输出结果可以看到类似

    apache2   25920         www-data    8w      REG              202,1 3090449563     276819 /var/log/apache2/access.log (deleted)
    apache2   25920         www-data    9w      REG              202,1 3090449563     276819 /var/log/apache2/access.log (deleted)
    

    第七列是文件大小。所以重启占用的进程,释放掉文件句柄。这里就是重启了下apache,然后终于安静,没告警了

    Last edit: Sep 09, 2017 Edit Delete
  4. django部署问题

    April 26th, 2017 118 views

    在使用apache2和wsgi尝试部署django项目时遇到几个问题

    1. wsgi无法执行, apache错误日志提示wsgi.py没有设置ExecCGI

    配置好WSGIScriptAlias和WSGIPythonHome之后发现无法运行,浏览器返回403 ,查看日志说需要设置ExecCGI。设置上之后又说执行错误,文件格式不对。最后明白是.py文件apache当成是cgi,可能直接运行了。于是加上"AddHandler wsgi-script .py"解决.

    Alias /media/ /data/aso.zhongbosoft.com/mysite/media/
    Alias /static/ /data/aso.zhongbosoft.com/mysite/static/
    
    <Directory /data/aso.zhongbosoft.com/mysite/static>
    Require all granted
    </Directory>
    
    <Directory /data/aso.zhongbosoft.com/mysite/media>
    Require all granted
    </Directory>
    
    ServerAdmin webmaster@localhost
    WSGIScriptAlias / /data/aso.zhongbosoft.com/mysite/wsgi.py
    
    <Directory /data/aso.zhongbosoft.com/mysite>
    AddHandler wsgi-script .py
    <Files wsgi.py>
    Require all granted
    </Files>
    </Directory>
    
    2. 执行collectstatic出错

    因为django无法处理静态文件,所以在apache2的配置上添加静态文件目录。然后按官方的教程,想调用collecstatic来拷贝静态文件。但是执行出错,

    You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

    stackflow上搜到在settings里面添加这两句 PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

    3. sqllite数据库写入失败

    需要数据库文件所在的文件夹有写权限。。。

    Last edit: Apr 26, 2017 Edit Delete
  5. windows下使用cygwin和gitolite安装git服务器

    February 12th, 2017 118 views

    使用了一段时间之后,感觉有条件最好还是直接在linux上面装。调试,日志可能会方便一点,最近ssh连接不上,看日志还需要另外装syslog-ng。同时也发现了gitlab,确实功能要强大很多,可以作为备选方案。gitolite好处是简单轻便一些

    最近想要在window上搭建一个git的代码版本控制系统。同时需要有必要的权限控制,经过一番Google之后,选择使用cygwin+gitolite的方式

    整个安装流程参考网上搜到的一篇文章 How To Set Up A Git Server On Windows Using Cygwin And Gitolite

    流程

    1. 安装cygwin
    2. 连接cgywin和windows系统安全
    3. 设置ssh server
    4. 打开ssh客户端访问
    5. 验证密码访问
    6. 创建gitolite管理员密钥
    7. 安装gitolite
    8. 管理gitolite
    9. 配置客户端

    安装cygwin

    Cygwin的安装程序比较简单,直接下载setup程序运行,选择需要安装的包就行了,除了默认选择的一系列包之外,需要额外选择下面这几个包 - Net | openssh - Devel | git - Editors | vim vim可有可无,只是为了后面编辑文件方便。也可换成别的文本编辑程序

    连接cgywin和windows系统安全

    为了后面设置使用ssh,需要首先配置cgywin集成windows系统安全,可以参阅cygwin文档中的integrating with Windows Security

    1.以管理员方式打开安装好的cgywin 2.执行/bin/cyglsa-config

    Warning: Registering the Cygwin LSA authentication package requires administrator privileges!  You also have to reboot the machine to activate the change.
    Are you sure you want to continue? (yes/no)
    

    3.输入yes

    Cygwin LSA authentication package registered.
    Activating Cygwin's LSA authentication package requires to reboot.
    

    4.重启机器

    设置ssh server

    1.以管理员方式打开安装好的cgywin

    2.执行ssh-host-config

    $ ssh-host-config
    *** Info: Generating /etc/ssh_host_key
    *** Info: Generating /etc/ssh_host_rsa_key
    *** Info: Generating /etc/ssh_host_dsa_key
    *** Info: Creating default /etc/ssh_config file
    *** Info: Creating default /etc/sshd_config file
    *** Info: Privilege separation is set to yes by default since OpenSSH 3.3.
    *** Info: However, this requires a non-privileged account called 'sshd'.
    *** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
    *** Query: Should privilege separation be used? (yes/no)
    

    3.输入yes

    *** Info: Note that creating a new user requires that the current account have
    *** Info: Administrator privileges.  Should this script attempt to create a
    *** Query: new local account 'sshd'? (yes/no)
    

    4.还是yes

    *** Info: Updating /etc/sshd_config file
    *** Warning: The following functions require administrator privileges!
    *** Query: Do you want to install sshd as a service?
    *** Query: (Say "no" if it is already installed as a service) (yes/no)
    

    5.还是yes

    *** Query: Enter the value of CYGWIN for the daemon: []
    

    6.直接回车

    *** Info: On Windows Server 2003, Windows Vista, and above, the
    *** Info: SYSTEM account cannot setuid to other users -- a capability
    *** Info: sshd requires.  You need to have or to create a privileged
    *** Info: account.  This script will help you do so.
    *** Info: You appear to be running Windows 2003 Server or later.  On 2003
    *** Info: and later systems, it's not possible to use the LocalSystem
    *** Info: account for services that can change the user id without an
    *** Info: explicit password (such as passwordless logins [e.g. public key
    *** Info: authentication] via sshd).
    *** Info: If you want to enable that functionality, it's required to create
    *** Info: a new account with special privileges (unless a similar account
    *** Info: already exists). This account is then used to run these special
    *** Info: servers.
    *** Info: Note that creating a new user requires that the current account
    *** Info: have Administrator privileges itself.
    *** Info: No privileged account could be found.
    *** Info: This script plans to use 'cyg_server'.
    *** Info: 'cyg_server' will only be used by registered services.
    *** Query: Do you want to use a different name? (yes/no)
    

    7.输入 no

    *** Query: Create new privileged user account 'cyg_server'? (yes/no)
    

    8.输入 yes

    *** Info: Please enter a password for new user cyg_server.  Please be sure
    *** Info: that this password matches the password rules given on your system.
    *** Info: Entering no password will exit the configuration.
    *** Query: Please enter the password:
    

    9.这里是给ssh服务账户添加一个密码,后面好像不太用得到

    10.如果需要要打开防火墙的tcp 22端口,可以通过windows的防火墙设置,后者使用命令。(我好像并没有走这一步)

    netsh advfirewall firewall add rule dir=in action=allow localport=22 protocol=tcp name="Cygwin SSHD"
    

    11.执行sc start sshd

    打开ssh客户端访问

    创建一个windows用户git用作后面git服务器使用,并且设置一个安全的密码。然后在cygwin命令行执行mkpasswd -l -u git >> /etc/passwd

    验证ssh密码登录

    接下来的内容都需要在客户端机器上操作,可以是mac,windows,linux等任何。需要安装好git客户端(windows同样需要安装cygwin)

    1.执行ssh git@server_addr

    git@git-server's password:
    

    2.输入git账户的密码,即应该登录成功

    创建gitolite管理员密钥

    1.执行ssh-keygen -f ~/.ssh/gitolite-admin

    安装gitolite

    1.拷贝管理员密钥到服务器上

    scp ~/.ssh/gitolite-admin.pub git@gitserver:yourname.pub
    

    2.确保~/.ssh/authorized_keys为空或者不存在。安装gitolite。可参照最新的gitolite说明文件

    git clone git://github.com/sitaramc/gitolite
    mkdir -p $HOME/bin
    gitolite/install -to $HOME/bin
    

    3.设置管理员用户

    $HOME/bin/gitolite setup -pk yourname.pub
    

    管理gitolite

    设置完管理员gitolite就算是安装好了,接下来关闭ssh连接。从客户端配置gitolite

    1.拉取gitolite-admin

    git clone git@host:gitolite-admin
    

    2.添加repo,用户和权限通过更新conf/gitolite.conf和keydirs/文件夹(用户密钥.pub直接放在keydirs里面)。然后直接git push到服务器即可。具体配置可参见 这里

    'conf/gitolite.conf'
    repo gitolite-admin
        RW+     =   yourname
    
    repo testing
        RW+     =   @all
    

    配置客户端

    根据操作系统下载相应的git版本并安装,https://git-scm.com/downloads

    windows安装时候需要选择一系列的选项,有一个关于文件换行格式的最好选成pull使用as it be, push使用unix style。其他的使用默认就行了

    安装完成后需要使用ssh-keygen来生成密钥, mac可以直接用命令行,windows可以用gitbash

    $ ssh-keygen -f "~/.ssh/YourName"
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    

    YourName是起的一个用户名字 passphrase是给这个key添加保护密码,可以设置也可直接return跳过

    这个命令会在~/.ssh/下面生成两个文件,YourName和YourName.pub, YourName.pub作为公钥用来创建相应用户

    同时最好配置ssh的config来适应多key的情况,创建或者编辑~/.ssh/config文件

    HOST git-server-host
        IdentityFile ~/.ssh/YourName
        User YourName
    

    git-server-host即是git服务器的地址

    Last edit: Mar 25, 2017 Edit Delete
  6. 开篇

    January 24th, 2017 118 views

    其实不是很喜欢写东西,也不擅长写东西。但是有时候又想把一些事情记下来。就像小时侯写日记,有那么几本,然而从来没有坚持过。

    一直想有一个自己的博客,却一直也担心自己不会耐住性子写下来。而今年刚好工作上过的也不是很顺心,于是不断的抽时间学习新东西充实自己。刚好因为需要做一些网页开发,学习到rails的入门博客系统,便想做一个来试手,一方面学习,一方面有个地方计点东西。反正服务器闲着也是闲着。

    加上偶然看到instagram的网页主页,觉得页面布局很漂亮,于是下定决心。本博客和本博客系统就诞生了。

    站点内容初步定为为一些技术类的记录性质的,或者是学习日志,或者是一些翻译内容(如果我有兴趣的话)。另外就是一些配图的游历日志,或者感悟(也可能没有),因为我喜欢摄影,所以很可能会贴一堆图片作为旅游日记^_^

    技术类的可能会包含网页,linux后台,unity,移动应用等内容,也许后面还会有些新的方向。

    好,就这样吧,尽量逼自己坚持下来

    Last edit: Jan 24, 2017 Edit Delete
  7. iptable配置导致服务器丢包严重的问题

    January 10th, 2017 118 views

    发现服务器网络慢,各种丢包问题严重,经过一系列尝试,最后发现是iptable的Nf_conntrack: Table Full问题

    最近服务器上网络连接非常慢,从页面访问速度,cgi速度到数据库连接,无论是入站数据和出站数据,都不正常。然后看是查找问题的原因

    一开始以为是客户端连接没有及时释放,同时连接数太多导致资源不够用。因为机器本身内存也很小,基本上当时内存也已经占满了,于是改了apache的服务器超时时间

    Timeout 30
    MaxKeepAliveRequests 500
    KeepAliveTimeout 2
    

    甚至一度关掉了KeepAlive,但是同时连接数还是一直没有下来。

    然后怀疑是python cgi的问题,因为没有用fastcgi,wsgi这类的mod,所以每次cgi执行都需要重新加载。于是把cgi用golang重写了一遍,因为它编出来的是二进制的。果然有一些效果,同时连接数一下子就下来了。但是cgi还是经常会连接超时。

    因为这个cgi的内部有网页下载和数据库连接,再检查机器本身的下载速度个数据库连接也是很慢,甚至dns服务器也经常连不上。一开始以为是dns服务器的问题,于是改了机器的dns,依然是效果不佳。

    今天在网上搜索,偶然发现有人有相同的情况,用dmesg这个命令看到类似这样的日志

    [5854719.582506] nf_conntrack: table full, dropping packet
    

    是因为iptable开启了conntrack,但是连接跟踪表满,于是开始丢包。而这个是在开了nat table之后默认开启的。于是在80端口上限制这个追踪

    iptables -t raw -A PREROUTING -i lo -j NOTRACK
    iptables -t raw -A OUTPUT -o lo -j NOTRACK
    
    iptables -t raw -A PREROUTING -p tcp -m tcp --dport 8080 -j NOTRACK
    iptables -t raw -A OUTPUT -p tcp -m tcp --sport 8080 -j NOTRACK
    

    重新检查,终于一切都好了

    参考页面: http://jerrypeng.me/2014/12/08/dreadful-nf-conntrack-table-full-issue/

    Last edit: Jan 23, 2017 Edit Delete