风声竹影's profile听风竹轩的书架BlogListsNetwork Tools Help

Blog


    May 06

    [转] RHEL5/CentOS5 轻松安装 Subversion+apache+mysql+ssl

    [转] RHEL5/CentOS5 轻松安装 Subversion+apache+mysql+ssl

    Submitted by admin on Fri, 04/25/2008 - 08:20

    来源地址:http://www.iusesvn.com/html/33/t-1733.html

    常来论坛寻找东西,从各位大哥贴里学了不少东西,今天在iuserSVN奉献我的处女贴.
    看到有很多人都在问RHEL5如何安装subversion等等,很多人无奈安装的问题就不用RHEL5系统自带的服务,而自己去编译,这样花费了很多不需要的时间,并且RHEL5的这些服务RedHat已经做过安全修改以及优化过的.并且RHEL5的服务本身安装就十分简单,RHEL5提供了这些服务,我们还在上面重新编译,而且并不是因为版本的原因,这样不是很讽刺吗?CentOS是用Red Hat Enterprise linux 5的源码重新编译的,所以两个系统基本没有什么差别.今天我来跟大家一起在CentOS 5.0做一次这样的实验.写的不清楚的地方,欢迎讨论,及时修改。
    skype_ID:zhenrain@gmail.com

    1.安装检查
    *********************Command***************************************************************
    [root@rep CentOS]# rpm -q httpd-2.2.3-7.el5.centos
    httpd-2.2.3-7.el5.centos
    [root@rep httpd]# rpm -q openssl-0.9.8b-8.3.el5
    openssl-0.9.8b-8.3.el5
    [root@rep CentOS]# rpm -q mod_ssl-2.2.3-7.el5.centos
    mod_ssl-2.2.3-7.el5.centos
    httpd-2.2.3-6.el5.centos.1
    [root@rep ~]# rpm -q mysql-server-5.0.22-2.1
    mysql-server-5.0.22-2.1
    [root@rep ~]# rpm -q mysql-devel-5.0.22-2.1
    mysql-devel-5.0.22-2.1
    [root@rep ~]# rpm -q mod_auth_mysql-3.0.0-3.1
    mod_auth_mysql-3.0.0-3.1
    [root@rep ~]# rpm -q subversion-1.4.2-2.el5
    subversion-1.4.2-2.el5
    [root@rep ~]# rpm -q mod_dav_svn-1.4.2-2.el5
    package mod_dav_svn-1.4.2-2.el5 is not installed
    [root@rep ~]# rpm -ivh mod_dav_svn-1.4.2-2.el5.i386.rpm
    warning: mod_dav_svn-1.4.2-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
    Preparing... ########################################### [100%]
    1:mod_dav_svn ########################################### [100%]

    *********************Command End************************************************************

    2.检查Apache模块
    ***************Command***************
    [root@rep ~]cd /etc/httpd/modules
    [root@rep modules]# ls | grep svn
    mod_authz_svn.so
    mod_dav_svn.so
    [root@rep modules]# ls | grep mysql
    mod_auth_mysql.so
    ***************Command END*************

    3.初始化repository.
    a.创建配置管理库的主目录(服级目录),任意位置
    [root@rep ~]# mkdir repository
    b.创建测试库
    [root@rep ~]# svnadmin create /repository/test
    c.更改权限
    [root@rep ~]# chown apache.apache repository/ -R
    d.拷贝权限认证文件(路径任意,但会影响到Step5的配置文件内容)
    [root@rep /]# mkdir /repository/auth
    [root@rep /]# cp /repository/test/conf/authz /repository/auth/ -p

    4.创建认证数据库
    a.配置服务
    ********************************Command*************************************
    [root@rep /]# /etc/init.d/mysqld start #启动MySQL服务
    Starting MySQL: [ OK ]
    [root@rep /]# chkconfig --level 35 mysqld on #设置mysqld在运行级别为3和5的时候开机自动启动
    ******************************Command End***********************************

    b.创建SVN用户的认证数据库
    *********************************Command*********************************
    [root@rep /]# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 8 to server version: 5.0.22

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> create database auth;
    Query OK, 1 row affected (0.00 sec)

    mysql> use auth; #创建数据库,为什么创建这样的数据库可以参看/etc/httpd/conf.d/auth_mysql.conf
    Database changed
    mysql> CREATE TABLE users (
    -> user_name CHAR(30) NOT NULL,
    -> user_passwd CHAR(20) NOT NULL,
    -> PRIMARY KEY (user_name)
    -> );

    Query OK, 0 rows affected (0.01 sec)

    mysql> GRANT SELECT #更改数据库权限
    -> ON auth.users
    -> TO authuser@localhost
    -> IDENTIFIED BY 'Your Password Here';
    Query OK, 0 rows affected (0.01 sec)

    mysql> flush privileges; #权限生效
    Query OK, 0 rows affected (0.00 sec)

    mysql> INSERT INTO users VALUES ('test', ENCRYPT('PaSsWoRd')); #添加测试帐号
    Query OK, 1 row affected (0.00 sec)

    mysql> exit
    Bye

    ********************************Command END********************************

    5.修改Apache主配置文件
    那些认证模块等不需要添加到主配置文件. #如果你想问为什么可以去看看/etc/httpd/conf.d下面的配置文件
    [root@rep ~]# vi /etc/httpd/conf/httpd.conf
    修改User/Group
    查看是否有如下行:
    User apache #Apache运行的用户
    Group apache #Apache运行的用户组
    在配置文件末尾添加如下描述 #当然你也可以放在你希望的地方

    DAV svn
    SVNParentPath /repository #这个就是SVN的父级目录,如果你只有一个库可以写成SVNPath /path
    AuthzSVNAccessFile /repository/auth/authz #权限验证文件
    AuthName "Please Login.."
    AuthType Basic
    AuthMYSQLEnable on
    AuthMySQLUser authuser #访问mysql的用户名
    AuthMySQLPassword "Your Password Here" #访问mysql的密码
    AuthMySQLDB auth
    AuthMySQLUserTable users #用户验证的数据库
    AuthMySQLNameField user_name #用户验证数据库的用户名字段
    AuthMySQLPasswordField user_passwd #用户验证数据库的密码字段
    require valid-user

    6.使https生效.
    在这之前要先确认我们使用的域名,ServerName
    修改/etc/httpd/conf/httpd.conf
    ServerName "***.****.***"
    因为向CA提交我们的数字证书是需要收费的,我们测试的时候可以使用生成测试证书.
    [root@rep etc]# cd /etc/pki/tls/
    [root@rep tls]# rm private/localhost.key -f #删除旧的证书文件
    [root@rep tls]# openssl genrsa 1024 > private/localhost.key #生成服务器测试密钥
    Generating RSA private key, 1024 bit long modulus
    ...............++++++
    .....................................................++++++
    e is 65537 (0x10001)

    [root@rep tls]# cd certs/
    [root@rep certs]# make testcert #生成测试证书
    umask 77 ; \
    /usr/bin/openssl req -utf8 -new -key /etc/pki/tls/private/localhost.key -x509 -days 365 -out /etc/pki/tls/certs/localhost.crt -set_serial 0
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [GB]:CN
    State or Province Name (full name) [Berkshire]:BeiJing
    Locality Name (eg, city) [Newbury]:BeiJing
    Organization Name (eg, company) [My Company Ltd]:RTS InfoTech
    Organizational Unit Name (eg, section) []:System Management
    Common Name (eg, your name or your server's hostname) []:"***.****.***" #这里填写的内容一定要与你域名相符,否则证书会显示不合法
    Email Address []:Rain.Li@rts-it.com

    7.赋予测试用户权限.
    vi/repository/auth/authz
    在最后添加
    [test:/]
    testuser= rw #这里的测试用户帐户就是刚才我们在Step4最后一步添加的测试帐户
    * =

    8.启动Apache.
    [root@rep conf.d]# /etc/init.d/httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]
    [root@rep conf.d]# chkconfig --level 35 httpd on

    9.如果你决定投入使用可以通过重复Step3的a.b以及7来添加新的版本库。

    现在就可以开始测试了.
    首先你可以来验证一下ssl是否已经ok.
    打开一个浏览器,地址栏输入https://YourServerName
    如果你使用IE浏览器的话会谈出一个安全提示.没关系,这是正常的因为我们使用的是测试证书,他会提示我们的证书颁发者没有经过认证.
    主要是查看"证书的日期有效"和"该证书有一个与您试图查看的网页名称匹配的有效名称"这两项,如果你发现你的"证书过期或者还没有生效."那么去查查你的服务器日期是否正确,通常这种问题会经常性的发生在VMware里面.
    OK,我们现在可以使用SVN的TortoiseSVN客户端来测试了.
    Checkout以后在URL of repository栏输入https://rep.rts.com/svn/test同样会给出一个安全警告,仔细查看是否是你的证书后选择"Accept permanently",以后就不会有这样的提示了,但其他服务器来欺骗你试图代替你的服务器的时候会提示安全警告证书发生变化.是否信任.
    测试的时候看清楚你是否填写的https.不至于你会问为什么我的证书没有生效.

    排错的过程主要是依靠查看系统日志,tail /var/log/httpd/ssl_error_log.所有的错误已经在这里描述的很清楚了.
    下面给两个常见的错误,以及解决的方法.
    1.验证不通过,查看日志后发现
    [Mon Aug 20 20:53:05 2007] [error] [client 192.168.101.99] MySQL user "USERNAME" not found: /svn/test
    [Mon Aug 20 20:53:05 2007] [error] [client 192.168.101.99] MySQL ERROR: Access denied for user 'authuser'@'localhost' (using password: YES)
    一般情况是httpd.conf配置文件对mysql用户帐号密码描述有问题.
    2.认证通过,但是没有权限
    我们可以查看一下httpd.conf文件里面apache运行的用户和组.
    然后查看我们版本库目录的属主属组是否这个用户.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://tfzxbookshell.spaces.live.com/blog/cns!EB39D7FA27BCD1A1!587.trak
    Weblogs that reference this entry
    • None