评论

收藏

[MySQL] open***+mysql+pam 构建强大的***系统

数据库 数据库 发布于:2021-07-04 10:41 | 阅读数:295 | 评论:0

open***+mysql+pam



  本次为新的生产环境部署系统而采用了这个方案,陆续会将实际的生产架构整理出来.由于涉及到公司的各种敏感信息,已经将IP做了替换中途可能有出入 敬请谅解。等我找时间画图出来一并奉上。
  如果有根本上的问题,请大家指正。
  

  本次为了测试使用了如下的软件版本:
  epel-release-6-8.noarch.rpm
  lzo-2.03.tar.gz
  open***-2.2.2.tar.gz
  open***-2.0.7.tar.gz
  open***-2.2.1-install.exe
  

  

  1  安装epel第三方源:
wget http://mirror.neu.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
  

  2  安装各种依赖关系:
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
  

  3  安装
yum install pam_krb5 pam_mysql pam pam-devel
yum install mysql mysql-server mysql-devel mysql-libs
  

  

  4  安装lzo:
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz
cd lzo-2.03 && ./configure && make && make install
  

  5  添加路径:
cat>>/etc/ld.so.conf<<EOF
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
EOF
ldconfig
  

  6  安装open***:
tar -zxvf open***-2.2.2.tar.gz
cd open***-2.2.2/
./configure --prefix=/usr/local/open*** && make && make install
mkdir -p /etc/open***
cd /root/open***-2.2.2
cp -R easy-rsa /etc/open***
cd /etc/open***/easy-rsa/2.0/
cp vars vars_bak
  

  7  修改vars的内容信息:
vim vars
###最下面修改内容:
export KEY_COUNTRY="CN"
export KEY_PROVINCE="BJ"
export KEY_CITY="beijing"
export KEY_ORG="beijingidc"
export KEY_EMAIL="你的邮箱地址"
  

  8  生成服务器和客户端需要的key文件:
source ./vars
./clean-all
./build-ca ca
./build-key-server server
./build-dh
/usr/local/open***/sbin/open*** --genkey --secret keys/ta.key
  

  9  创建mysql用于***的账号存放:
##启动mysql:
service mysqld  restart
###创建数据验证信息:
mysql> create database ***;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON ***.* TO ***@localhost IDENTIFIED BY '***123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use ***;
Database changed
mysql>  CREATE TABLE ***user (
  -> name char(20) NOT NULL,
  -> password char(128) default NULL,
  -> active int(10) NOT NULL DEFAULT 1,
  -> PRIMARY KEY (name)
  -> );
Query OK, 0 rows affected (0.30 sec)
mysql> insert into ***user (name,password) values('user1',password('123456'));
Query OK, 1 row affected (0.02 sec)
  

  10 创建pam用于验证:
###创建pam验证配置文件:
vim /etc/pam.d/open***
auth sufficient pam_mysql.so user=*** passwd=***123 host=localhost db=*** table=***user usercolumn=name passwdcolumn=password where=active=1 sqllog=0 crypt=2
account required pam_mysql.so user=*** passwd=***123 host=localhost db=*** table=***user usercolumn=name passwdcolumn=password where=active=1 sqllog=0 crypt=2
#crypt(0) -- Used to decide to use MySQL's PASSWORD() function or crypt()
#0 = No encryption. Passwords in database in plaintext. NOT recommended!
#1 = Use crypt
#2 = Use MySQL PASSWORD() function
  

  11 测试pam和mysql的连接:
yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-lib cyrus-sasl-gssapi
/etc/init.d/saslauthd restart
  

  12 open*** 2.0以上验证会出问题,需要编译低版本的模块:
wget http://down1.chinaunix.net/distfiles/open***-2.0.7.tar.gz
tar -zxvf open***-2.0.7.tar.gz
cd open***-2.0.7/
./configure
cd plugin/auth-pam/
make
cp open***-auth-pam.so /etc/open***/
  

  13  测试连接:
###显示如下内容即为正常:
[root@localhost 2.0]# testsaslauthd -u user1 -p 123456 -s open***
0: OK "Success."
  

  14  创建并修改open***的配置文件:
cp /opt/src/open***-2.2.2/sample-config-files/server.conf /etc/open***/
  

  15  配置文件的内容如下(取出了所有的注释部分)
  
vim server.conf
###内容如下:
port 1194
proto udp
dev tun
ca /etc/open***/easy-rsa/2.0/keys/ca.crt
cert /etc/open***/easy-rsa/2.0/keys/server.crt
key /etc/open***/easy-rsa/2.0/keys/server.key
dh /etc/open***/easy-rsa/2.0/keys/dh1024.pem
tls-auth /etc/open***/easy-rsa/2.0/keys/ta.key 0
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1"
push "dhcp-option DNS 10.8.0.1"
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
status open***-status.log
log     open***.log
verb 3
client-cert-not-required
username-as-common-name
plugin ./open***-auth-pam.so /usr/local/open***/sbin/open***
  

  16  开启内核路由转发:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 0   改成 net.ipv4.ip_forward = 1
sysctl -p
  

  17  设置防火墙的端口转发:
###iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 服务器的ip
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 192.168.80.151
  

  18  保存并重启iptables:
service iptables save
service iptables restart
  

  19  创建启动脚本:
cp -f /root/open***-2.2.2/sample-scripts/open***.init /etc/init.d/open***
  

  
vim /etc/init.d/open***
###编译安装的需要将第69行改成:
open***_locations="/usr/local/open***/sbin/open*** /usr/sbin/open*** /usr/local/sbin/open***"
chkconfig --add open***
chkconfig open*** on
/etc/init.d/open*** start
  

  ------------------至此服务端配置完成---------------
  下载open***客户端:
http://swupdate.open***.org/community/releases/open***-2.2.1-install.exe
  

  客户端的安装配置:
  

  

  在服务端操作将ca.crt ca.key ta.key 拷贝到客户端的conf目录下面:
  C:\Program Files (x86)\Open×××\config
  

  新建文件以.o*** 为结尾,并输入以下内容(remote服务器外网网卡地址):
client
dev tun
proto udp
remote 192.168.80.151 1194  ##服务端的IP
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-auth ta.key 1
ns-cert-type server
comp-lzo
verb 5
auth-user-pass
  

  拨号-->输入mysql里面添加的用户名:user1 123456 -->OK
  

  右下角出现的2个小电脑 变成绿色的 即表示连接到open***服务器上,在本地cmd执行ipconfig
  查看是否得到了open*** 设置的网段地址。

  
关注下面的标签,发现更多相似文章