*********************
* 1. 安装数据库
*********************
下载源码:
postgresql-9.1.3.tar.bz2
添加用户
# useradd postgres (自动建立 postgres 组)
# vi ~postgres/.bash_profile
添加:
PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH
以 postgres 用户登录,
# su - postgres
建立数据库目录:
$ mkdir data
编译安装源码:
以postgres用户登录
tar jxvf postgresql-9.1.3.tar.bz2
./configure --prefix=/usr/local/pgsql
gmake
以root用户登录
gmake install
拷贝 contrib 目录下 start-scripts 下的linux文件到 /etc/init.d,并改名为 postgres,此乃启动文件,需要修改其中的PG_DATA到实际路径。
[root@HS22_blade11 postgresql-9.1.3]# cp contrib/start-scripts/linux /etc/init.d/postgres
[root@HS22_blade11 init.d]# chmod +x postgres
初始化数据库
su - postgres
#/usr/local/pgsql/bin/initdb --locale=C --encoding=EUC_CN -D /home/postgres/data
#/usr/local/pgsql/bin/initdb --locale=C --encoding=WIN -D /home/postgres/data
[postgres@hpserv postgres]$ initdb -D /home/postgres/data --locale=C -E UTF-8
启动数据库
/et/init.d/postgres start
修改超级用户postgres的密码
[root@HS22_blade11 init.d]# su - postgres
[postgres@HS22_blade11 ~]$ psql
psql (9.1.3)
Type "help" for help.
postgres=# alter user postgres with password '超级口令';
ALTER ROLE
postgres=#
配置数据库:
vi /home/postgres/data/postgresql.conf
去掉下面两行注释
#listen_addresses = 'localhost'
#port = 5432
修改 log_min_messages = error 否则日志太多
vi /home/postgres/data/pg_hba.conf
将行
host all all 127.0.0.1/32 trust
改成
host all all 127.0.0.1/32 md5
若要被除本机外的其他机器访问,则需要添加相应的行,例如:
host all all 192.168.154.0 255.255.255.0 md5
且修改 postgresql.conf 中的 listen_addresses = 'localhost' 为 listen_addresses = '*'
若要增加 sharemem,请设置:
vi /etc/sysctl.conf
kernel.shmmax=2147483648
kernel.shmmni=4096
kernel.shmall=2097152
kernel.sem=250 32000 100 128
fs.file-max=65536
net.ipv4.ip_local_port_range=1024 65000
[postgres@hpserv postgres]$ psql -h127.0.0.1 -p5432
psql (8.4.8)
Type "help" for help.
postgres=# show client_encoding;
client_encoding
-----------------
UTF8
(1 row)
postgres=# CREATE USER pureftpd WITH PASSWORD 'ftp库口令';
postgres=# CREATE DATABASE pureftpd WITH OWNER=pureftpd TEMPLATE=template0 ENCODING='UTF-8';
postgres=# \q
[postgres@hpserv postgres]$ psql -l
创建表, pureftpd 用户登录
[postgres@hpserv postgres]$ psql -h127.0.0.1 -p5432 -Upureftpd pureftpd
CREATE TABLE admin (
Username varchar(35) NOT NULL default '',
Password char(32) NOT NULL default '',
PRIMARY KEY (Username)
);
INSERT INTO admin VALUES ('admin',MD5('admin口令'));
CREATE TABLE users (
Username varchar(16) NOT NULL,
Password varchar(32) NOT NULL,
Uid int NOT NULL,
Gid int NOT NULL,
Dir varchar(128) NOT NULL,
QuotaFiles int NOT NULL default 500,
QuotaSize int NOT NULL default 30,
ULBandwidth int NOT NULL default 80,
DLBandwidth int NOT NULL default 80,
Ipaddress varchar(15) NOT NULL default '*',
Comment varchar(256),
Status char(1) NOT NULL default '1',
ULRatio int NOT NULL default 1,
DLRatio int NOT NULL default 1,
PRIMARY KEY (Username)
);
INSERT INTO users (Username, status, Password, Uid, Gid, Dir, ULBandwidth, DLBandwidth, comment, Ipaddress, QuotaSize, QuotaFiles)
VALUES ('testuser', '1', MD5('secret'), '2001', '2001', '/home/ftpdir/testuser', '100', '100', '', '*', '50', '0');
create table ftplog
(
action varchar(20),
username varchar(20),
host varchar(20),
time varchar(20),
size varchar(20),
msg varchar(512)
);
说明:
ftplog 记录日志的表名
action ftp动作, U/D
msg 记录日志信息的列
user 登录用户
host 登录主机
time 登录时间
size 处理该用户连接的进程pid
*****************
* 2. 创建ftp用户
*****************
#Then we create an ftp group ("pftpgroup") and user ("pftpuser") that all our virtual users will be mapped to.
#Replace the group- and userid 2001 with a number that is free on your system:
groupadd -g 2001 pftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g pftpgroup pftpuser
mkdir /home/ftpdir
*********************************************************************************************************
* 3. pure-ftpd 源码编译安装
*
* 修改的源文件: log_mysql_p.h log_mysql.h log_mysql.c ftpd.c log_pgsql.h log_pgsql_p.h log_pgsql.c ftpd_p.h
**********************************************************************************************************
[root]$ ./configure --prefix=/usr/local/pureftpd --with-pgsql=/usr/local/pgsql --without-ascii --with-everything
[root]$ make && make install
mkdir /usr/local/pureftpd/etc
cp pureftpd-pgsql.conf /usr/local/pureftpd/etc
cp configuration-file/pure-config.pl /usr/local/pureftpd/bin
cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc
chmod 755 /usr/local/pureftpd/bin/pure-config.pl
cp contrib/redhat.init /etc/init.d/pureftpd
[root]$ vi pure-ftpd.conf
ChrootEveryone yes
#TrustedGID 2001 #根据实际Gid修改
DisplayDotFiles no
PGSQLConfigFile /usr/local/pureftpd/etc/pureftpd-pgsql.conf
Umask 111:007 #同组可删改, :
CreateHomeDir yes
Bind *,21 #端口
IPV4Only yes
SyslogFacility none #不往 /var/log/message 里记录日志
AltLog clf:/var/log/pureftpd.log
[root]$ vi pureftpd-pgsql.conf
PGSQLServer 127.0.0.1 此处不能用 localhost! 否则日志无法写入
PGSQLPort 5432
PGSQLUser pureftpd
PGSQLPassword ftpdpass
PGSQLCrypt md5
PGSQLInsertLog INSERT INTO ftplog (action,msg,username,host,time,size) VALUES ('%s','%s','%s','%s','%s','%s')
PGSQLGetPW User -> Username
后面的User 都要改为 Username
[root]$ vi /etc/init.d/pureftpd
fullpath=/usr/local/pureftpd/bin/$prog
pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho
$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize
status)
status pure-ftpd
*************************************************************
* 4. pure-ftpd RPM安装
*
export PATH=$PATH:/usr/local/pgsql/bin
rpmbuild -tb pure-ftpd-1.0.36.tar.gz --define 'with_pgsql 1'
pure-ftpd-1.0.36.tar.gz 中已修改的项:
%define con_ascii 0 避免二进制文件被修改
*************************************************************
4.1 rpm -ivh --nodeps pure-ftpd-1.0.36-1.x86_64.rpm
4.2 修改配置文件
[root]# cd /etc
[root]# vi pure-ftpd.conf
ChrootEveryone yes
#TrustedGID 2001 #根据实际Gid修改
DisplayDotFiles no
PGSQLConfigFile /etc/pureftpd-pgsql.conf
Umask 111:007 #同组可删改, :
CreateHomeDir yes
Bind *,21 #端口
IPV4Only yes
SyslogFacility none #不往 /var/log/message 里记录日志
# AltLog clf:/var/log/pureftpd.log #urlencode汉字
AltLog xferlog:/var/log/pureftpd.log #正常显示汉字
[root]$ vi pureftpd-pgsql.conf
PGSQLServer 127.0.0.1 此处不能用 localhost! 否则日志无法写入
PGSQLPort 5432
PGSQLUser pureftpd
PGSQLPassword ftpdpass
PGSQLCrypt md5
PGSQLInsertLog INSERT INTO ftplog (action,msg,username,host,time,size) VALUES ('%s','%s','%s','%s','%s','%s')
PGSQLGetPW User -> Username
后面的User 都要改为 Username
4.4 环境变量
若服务器端字符编码为 UTF-8, 需要指定客户端的字符编码为 GBK, 否则汉字不能入库.
修改 /etc/init.d/pure-ftpd :
[root]$ vi /etc/init.d/pureftpd
export PGCLIENTENCODING=GBK
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
status)
status pure-ftpd
******************************************************************************************