歡迎您光臨本站 註冊首頁

RHEL5/CentOS5 輕鬆安裝 Subversion+apache+mysql+ssl

←手機掃碼閱讀     火星人 @ 2014-03-29 , reply:0

看到有很多人都在問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運行的用戶和組.
然後查看我們版本庫目錄的屬主屬組是否這個用戶.

[火星人 ] RHEL5/CentOS5 輕鬆安裝 Subversion+apache+mysql+ssl已經有390次圍觀

http://coctec.com/docs/linux/show-post-202382.html