Press "Enter" to skip to content

月度归档: 2012 年 6 月

Linux下c读取MysqL中文乱码解决方案

在编写接口API时,发现中文字utf8输入的在linux下采用c读取显示为”??”问号,这是由于编码造成的。很简单的两个地方做修改就搞定。
1.先找到mysql的my.cnf配置文件/etc/my.cnf编辑添加
[mysqld]
default-character-set=utf8

2.在程序中添加 mysql_set_character_set(&db,”utf8″); 语句
例子:kiccleaf.c 文件

#include <stdio.h>
//这里需要找到相应地址不知道可以用“ find / -name mysql.h ”查询
#include "/usr/include/mysql/mysql.h"
int main()
{
    MYSQL db;/*connector*/
    MYSQL_RES* result;/*result buffer*/
    MYSQL_ROW row;/*one row of the result*/
    int i;
    if(mysql_init(&db) ==NULL)
    {
      fprintf(stderr,"Fail to initialize the db.\n");
      return -1;
    }
    if(!mysql_real_connect(&db,"localhost","root","password","kiccleaf",3306,NULL,0))
    {
      fprintf(stderr,"Fail to connect to the server");
      return -1;
    }
    //添加字符集防止乱码
    mysql_set_character_set(&db,"utf8");
    if(mysql_query(&db,"SELECT * FROM user") != 0)
    {
      fprintf(stderr,"Fail to query the db for information.\n");
      return -1;
    }
    if ((result = mysql_store_result(&db)) == NULL)
    {
      fprintf(stderr,"Fail to get the result.\n");
      return -1;
    }

    while((row=mysql_fetch_row(result)) != NULL)/*fetching each row*/
    {
      puts("================================================");
      printf("id: %s\n",row[0]);
      printf("name: %s\n",row[1]);
      printf("pwd: %s\n",row[2]);
      printf("flag: %s\n",row[3]);
      puts("================================================");
    }

    mysql_free_result(result);
    mysql_close(&db);
    return 0;
}

编译时也会出现问题,可以添加参数 “-lz /usr/lib/mysql/libmysqlclient.so.15.0.0”

gcc -o kiccleaf -g kiccleaf.c -lz /usr/lib/mysql/libmysqlclient.so.15.0.0

原来乱码的情况

[root@kiccleaf c]# ./kiccleaf
================================================
id: 0000000001
name: ???
pwd: 123456
flag: 0
================================================
================================================
id: 0000000002
name: ???
pwd: 654123
flag: 0
================================================
================================================
id: 0000000003
name: ???
pwd: 789456
flag: 0
================================================
================================================
id: 0000000004
name: ???
pwd: 456321
flag: 0
================================================

添加字符集后输出结果:

[root@kiccleaf c]# ./kiccleaf
================================================
id: 0000000001
name: 测试1
pwd: 123456
flag: 0
================================================
================================================
id: 0000000002
name: 测试2
pwd: 654123
flag: 0
================================================
================================================
id: 0000000003
name: 测试3
pwd: 789456
flag: 0
================================================
================================================
id: 0000000004
name: 测试4
pwd: 456321
flag: 0
================================================
Leave a Comment

Linux X64下Nginx1.0.4无缝升级到新版本1.3.0版本操作方法[原创]

服务器近一年没有更新Nginx版本了,为了提高性能和稳定,采用了最新的Nginx版本。可以到http://nginx.org/en/download.html 进行下载。升级仅花了几分钟时间就搞定了。
注:以下代码是真实环境直接配置复制进来,可以根据代码从上至下进行操作配置。

[root@kiccleaf leaf]# wget http://nginx.org/download/nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# tar -zxvf nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# cd nginx-1.3.0
#如果需要服务器个性化名称可以修改
[root@kiccleaf nginx-1.3.0]# vi src/core/nginx.h
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_


#define nginx_version      1003000
#define NGINX_VERSION      "1.3.0"  #可修改成自己需要的版本
#define NGINX_VER          "Nginx/" NGINX_VERSION #可修改成自己需要服务的名称

#define NGINX_VAR          "NGINX"  #可修改成自己需要服务的名称
#define NGX_OLDPID_EXT     ".oldbin"


#endif /* _NGINX_H_INCLUDED_ */

#进行配置操作,根据自己的实际配置来,以下是我简单的配置

[root@kiccleaf nginx-1.3.0]# ./configure --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
checking for OS
 + Linux 2.6.18-274.12.1.el5 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.1.2 20080704 (Red Hat 4.1.2-51)
…………………………编译代码省略………………
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
[root@kiccleaf nginx-1.3.0]# make  #看清咯,只make,而不是make install,这里升级不需要install操作
make -f objs/Makefile
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
…………………………编译代码省略………………
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'
make -f objs/Makefile manpage
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'

检查配置是否正确,这里出现了警告,因为从低版本升级至高版本产生了配置的问题

[root@kiccleaf nginx-1.3.0]# ./objs/nginx -t
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf:22
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.qimutian.com.conf:22
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#升级后出现配置文件conf有错误,如果有其的虚拟主机开启了日志,也按要求移出server段放在server段的前面即可。
[root@kiccleaf nginx-1.3.0]# vi /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf
#把server里面的log_format代码拿到上面来,保存退出
    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
server
{
    listen       80;
    server_name  www.kiccleaf.com;
    index index.html index.htm index.php;
    root  /data/kiccleaf;
    #limit_conn   crawler  20;    
                            
    location ~ .*\.(php|php5)?$
    {      
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }

#以下代码的问题,升级后需要把以下代码拿到server上面去。这里先注释掉
#    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
#             '$status $body_bytes_sent "$http_referer" '
#              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data/logs/www_kiccleaf_com.log www_kiccleaf_com;

}
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t  #再检查,没有warn警告信息了
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

操作升级,出错误不管它

[root@kiccleaf nginx-1.3.0]# make upgrade #出现错误,就先不管它
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
cat: /usr/local/nginx/logs/nginx.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] Error 1

备份老的Nginx程序,复制新的过去

[root@kiccleaf nginx-1.3.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
mv: overwrite `/usr/local/nginx/sbin/nginx.old'? y
[root@kiccleaf nginx-1.3.0]# cp objs/nginx /usr/local/nginx/sbin/nginx
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t #查看复制过去配置是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -v  #再查看一下新版本,老的是1.0.4版本
nginx version: Nginx/1.3.0  #已经是新版本

无缝升级到新版本

[root@kiccleaf nginx-1.3.0]# kill -USR2 `cat /usr/local/nginx/nginx.pid` #
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #查看一下进程
root      2169  0.0  0.0 248708  1788 ?        Ss    2011   0:00 nginx: master process /usr/local/nginx/sbin/nginx  #老的进程都是2011年开启的,嘿嘿
www       6891  0.0  0.3 274308 27796 ?        S    Apr20   0:13 nginx: worker process               
www       6892  0.0  0.3 274308 27616 ?        S    Apr20   0:13 nginx: worker process               
www       6893  0.0  0.3 274308 27596 ?        S    Apr20   0:13 nginx: worker process               
www       6894  0.0  0.3 274308 27612 ?        S    Apr20   0:13 nginx: worker process               
www       6895  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6896  0.0  0.3 274308 27796 ?        S    Apr20   0:15 nginx: worker process               
www       6897  0.0  0.3 274308 27700 ?        S    Apr20   0:15 nginx: worker process               
www       6898  0.0  0.3 274308 27600 ?        S    Apr20   0:12 nginx: worker process               
www       6899  0.0  0.3 274308 27592 ?        S    Apr20   0:13 nginx: worker process               
www       6900  0.0  0.3 274308 27620 ?        S    Apr20   0:13 nginx: worker process               
www       6901  0.0  0.3 274308 27616 ?        S    Apr20   0:14 nginx: worker process               
www       6902  0.0  0.3 274308 27652 ?        S    Apr20   0:11 nginx: worker process               
www       6903  0.0  0.3 274308 27856 ?        S    Apr20   0:13 nginx: worker process               
www       6904  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6905  0.0  0.3 274308 27644 ?        S    Apr20   0:12 nginx: worker process               
www       6906  0.0  0.3 274308 27612 ?        S    Apr20   0:16 nginx: worker process               
www       6907  0.0  0.0 248708  1500 ?        S    Apr20   0:00 nginx: cache manager process        
root     30293  0.0  0.0 248008  3764 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30294  0.0  0.3 273968 27524 ?        S    22:17   0:00 nginx: worker process               
www      30295  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30296  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30297  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30298  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30299  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30300  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30301  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30302  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30303  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30304  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30305  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30306  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30307  0.0  0.3 273936 27392 ?        S    22:17   0:00 nginx: worker process               
www      30308  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30309  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30310  0.0  0.0 248188  1396 ?        S    22:17   0:00 nginx: cache manager process        
root     30316  0.0  0.0  61172   800 pts/1    S+   22:36   0:00 grep nginx

原来存放nginx.pid的目录下自动出现了nginx.pid.oldbin。现在新的和旧的一起在提供服务,我们执行一下命令把老的进程给Kill掉就可以了。

[root@kiccleaf nginx-1.3.0]# kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin` 
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #现在查看进程只有新的了
root     30293  0.0  0.0 248720  3924 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30332  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30333  0.1  0.3 274320 27552 ?        S    22:43   0:00 nginx: worker process               
www      30334  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30335  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30336  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30337  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30338  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30339  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30340  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30341  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30342  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30343  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30344  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30345  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30346  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30347  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30348  0.0  0.0 248720  1400 ?        S    22:43   0:00 nginx: cache manager process        
root     30418  0.0  0.0  61172   796 pts/1    S+   22:45   0:00 grep nginx

好了进行访问网站,是不是正常不间断切换至最新的Nginx版本了!

Leave a Comment

Win2003下安装Team Foundation Server 2010安装失败解决方案

Win2003下安装Team Foundation Server 2010 安装失败,找了好久网络上最多的是在win2003安装的时候就告诉你不要安装FrontPage 服务器扩展,但很不幸的事情,而且我服务器运行了三四年了,现在要安装TFS失败了。相信也有同样碰到这样的问题但找不到解决办法的人,就看看我是怎么安装成功的!!
土办法!有招可解!一步一步教你实现
1.首先安装好MSSQL2008数据库,当然你也可以安装SQL2005数据库。
2.去“控制面板”–“添加删除”中选择IIS中的FrontPage 服务器扩展,去掉并“下一步”。(光这样删除是不行的,安装TFS不是会提示你FrontPage 服务器扩展问题失败)



3.接下来需要手工操作了,找到C:\WINDOWS\system32\inetsrv下的MetaBase.xml配置文件

4.去服务里停止IIS,服务–找到“IIS Admin Service” 右击停止。

5.开始手动修改代码了,先备份一个MetaBase.xml,然后找到以下代码并删除:
删除 FrontPage Server Extensions;FPSE,ASP,IndexingService” 此行


<IIsWebService	Location ="/LM/W3SVC"
		AllowKeepAlive="TRUE"
		AnonymousUserName="IUSR_KICCLEAFSERVER"
		AnonymousUserPass="49634462700000002200000040000000475cbf110c40b876b7298c567297c5a6f2293855cecfef3ef15a5a7933a6e1f0fffb49004e004400ce9594fe9ea98168d799e40cafc23a53e28281b3d4e85da3a6801884dde6777b736af2f7a846d059b9ffc5eee95a11c19d4f4499ba36b8a4b15e1b152b174a5b"
		AppAllowClientDebug="FALSE"
		AppAllowDebugging="FALSE"
		AppPoolId="DefaultAppPool"
		ApplicationDependencies="Active Server Pages;ASP
			Internet 数据连接器;HTTPODBC
			在服务器端的包含文件;SSINC
			WebDAV;WEBDAV
			ASP.NET v1.1.4322;ASP.NET v1.1.4322
			ASP.NET v2.0.50727;ASP.NET v2.0.50727
			ASP.NET v4.0.30319;ASP.NET v4.0.30319
			FrontPage Server Extensions;FPSE,ASP,IndexingService"

删除以下几行


WebSvcExtRestrictionList="1,C:\WINDOWS\system32\inetsrv\gzip.dll,1,,gzip
			0,C:\WINDOWS\system32\inetsrv\httpodbc.dll,0,HTTPODBC,Internet 数据连接器
			0,C:\Program Files\Common Files\microsoft shared\web server extensions\50\isapi\_vti_adm\admin.dll,0,FPSE,FrontPage Server Extensions
			0,C:\WINDOWS\system32\inetsrv\ssinc.dll,0,SSINC,在服务器端的包含文件
			1,C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll,0,ASP.NET v4.0.30319,ASP.NET v4.0.30319
			1,C:\WINDOWS\system32\inetsrv\asp.dll,0,ASP,Active Server Pages
			0,C:\Program Files\Common Files\microsoft shared\web server extensions\50\isapi\shtml.dll,0,FPSE,FrontPage Server Extensions
			1,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,0,ASP.NET v2.0.50727,ASP.NET v2.0.50727
			0,C:\Program Files\Common Files\microsoft shared\web server extensions\50\isapi\_vti_adm\fpadmdll.dll,0,FPSE,FrontPage Server Extensions
			1,C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,0,ASP.NET v1.1.4322,ASP.NET v1.1.4322
			1,C:\php\php5isapi.dll,1,,php
			0,C:\Program Files\Common Files\microsoft shared\web server extensions\50\isapi\_vti_aut\author.dll,0,FPSE,FrontPage Server Extensions
			0,*.exe
			0,C:\WINDOWS\system32\inetsrv\httpext.dll,0,WEBDAV,WebDAV
			0,*.dll
			0,C:\Program Files\Common Files\microsoft shared\web server extensions\50\isapi\fpcount.exe,0,FPSE,FrontPage Server Extensions"

修改后:


		WebSvcExtRestrictionList="1,C:\WINDOWS\system32\inetsrv\gzip.dll,1,,gzip
			0,C:\WINDOWS\system32\inetsrv\httpodbc.dll,0,HTTPODBC,Internet 数据连接器
			0,C:\WINDOWS\system32\inetsrv\ssinc.dll,0,SSINC,在服务器端的包含文件
			1,C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll,0,ASP.NET v4.0.30319,ASP.NET v4.0.30319
			1,C:\WINDOWS\system32\inetsrv\asp.dll,0,ASP,Active Server Pages
			1,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,0,ASP.NET v2.0.50727,ASP.NET v2.0.50727
			1,C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,0,ASP.NET v1.1.4322,ASP.NET v1.1.4322
			1,C:\php\php5isapi.dll,1,,php
			0,*.exe
			0,C:\WINDOWS\system32\inetsrv\httpext.dll,0,WEBDAV,WebDAV
			0,*.dll"

删除代码以下全部


<IIsFilter	Location ="/LM/W3SVC/1/Filters/fpexedll.dll"
		FilterDescription="Microsoft FrontPage Server Extensions"
		FilterEnableCache="TRUE"
		FilterFlags="NotifySecurePort | NotifyNonSecurePort | NotifyPreProcHeaders | NotifyOrderLow"
		FilterPath="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\50\bin\fpexedll.dll"
		FilterState="1"
	>
</IIsFilter>

删除 FrontPageWeb=”TRUE” 此行


<IIsWebVirtualDir	Location ="/LM/W3SVC/1/ROOT"
		AccessFlags="AccessRead | AccessScript"
		AppFriendlyName="默认应用程序"
		AppIsolated="2"
		AppPoolId="vss"
		AppRoot="/LM/W3SVC/1/ROOT"
		AuthFlags="AuthAnonymous | AuthNTLM"
		DefaultDoc="index.asp,Default.htm,Default.asp,Default.html,Default.aspx,index.htm,index.html,index.aspx,index.php"
		FrontPageWeb="TRUE"
		HttpCustomHeaders="MicrosoftOfficeWebServer: 5.0_Pub

修改后


<IIsWebVirtualDir	Location ="/LM/W3SVC/1/ROOT"
		AccessFlags="AccessRead | AccessScript"
		AppFriendlyName="默认应用程序"
		AppIsolated="2"
		AppPoolId="vss"
		AppRoot="/LM/W3SVC/1/ROOT"
		AuthFlags="AuthAnonymous | AuthNTLM"
		DefaultDoc="index.asp,Default.htm,Default.asp,Default.html,Default.aspx,index.htm,index.html,index.aspx,index.php"
		HttpCustomHeaders="MicrosoftOfficeWebServer: 5.0_Pub

6.以上删除代码后,可以保存并重启IIS服务后,可以再次安装TFS软件了。我就是这么安装成功的!

Leave a Comment