《FreeTDS库文件之在BC-Linux服务器上的编译安装》
安装freetds软件包命令
sudo yum install freetds
[fenghx@localhost ~]$ sudo yum install freetds
我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:
#1) 尊重别人的隐私。
#2) 输入前要先考虑(后果和风险)。
#3) 权力越大,责任越大。
[sudo] fenghx 的密码:
fenghx 不在 sudoers 文件中。此事将被报告。
[fenghx@localhost ~]$
此处提示用户不在sudoers的文件中,即安装软件需要使用root权限,普通用户要想安装软件需要提升自己的权限,此时需要使用sudo命令,能使用这个命令的用户必须在sudo用户列表中,即sudoers系统配置文件中。所以需要将fenghx用户配置到sudoers系统配置文件中。
-
切换到root用户
[fenghx@localhost ~]$ su - root
密码:
上一次登录:五 2月 10 09:27:10 CST 2023从 xxx.xxx.xxx.xxxpts/0 上
Welcome to BigCloud Enterprise Linux 7 (GNU/Linux 3.10.0-1127.19.1.el7.x86_64 x86_64)
System information as of Fri Feb 10 09:56:52 CST 2023
* System CPU load: 0.25 0.12 0.08 * System uptime: 09:56:52 up 2 days
* Active sessions: 3 * Memory usage: 2127 / 7990 MB
* Processes count: 399
* Get Support :
* Ask Questions:
http://forum.bclinux.org
* Contact US :
MAIL : support@bclinux.org / TEL : 4001-10086-5
58 packages can be updated.
0 updates are security updates.
type 'yum check-update --security' to see details.
[root@localhost ~]#
-
打开sudoers文件查看,路径:/etc/sudoers
[root@localhost ~]# vim /etc/sudoers
[root@localhost ~]#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults env_keep += "HOME"
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
-- 插入 -- W10: 警告: 正在修改一个只读文件
当我准备修改文件配置的时候,进入编辑状态时,最下面命令栏提示:W10:警告:正在修改一个只读文件,也就是说当前的这个系统配置文件没有写的权限。那么就需要修改文件权限再编辑。
-
修改系统配置文件sudoers
[root@localhost ~]# ls -al /etc/sudoers
-r--r-----. 1 root root 4328 11月 28 2019 /etc/sudoers
[root@localhost ~]# chmod u+w /etc/sudoers
[root@localhost ~]# ls -al /etc/sudoers
-rw-r-----. 1 root root 4328 11月 28 2019 /etc/sudoers
[root@localhost ~]# vim /etc/sudoers
[root@localhost ~]#
上面先查看了sudoers文件的权限,发现只有读的权限,于是用chmod命令添加了写的权限,然后打开文件编辑如下,此时就不会提示上面只读文件的警告了。
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
fenghx ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
-- 插入 --
可以在 ## Allow root to run any commands anywhere 提示信息的下面的root行之后添加你要执行sudo命令的用户,其它和root行内容一样即可,注意:列于列之间用 tab 符分割
保存文件后退出,然后我们用普通用户先来执行关闭防火墙的命令,看能否成功。
-
验证是否修改成功
[root@localhost ~]# su - fenghx
上一次登录:五 2月 10 13:48:13 CST 2023pts/0 上
[fenghx@localhost ~]$ sudo systemctl stop firewalld
[sudo] fenghx 的密码:
[fenghx@localhost ~]$ sudo firewall-cmd --state
not running
[fenghx@localhost ~]$ sudo systemctl start firewalld
[fenghx@localhost ~]$ sudo firewall-cmd --state
running
[fenghx@localhost ~]$ sudo chmod u-w /etc/sudoers
[fenghx@localhost ~]$ sudo ls -al /etc/sudoers
-r--r-----. 1 root root 4350 2月 10 13:51 /etc/sudoers
[fenghx@localhost ~]$
以上命令中,先从root用户切换到普通用户fenghx,然后用sudo命令关闭防火墙,发现可以执行,并且没有提示“fenghx 不在 sudoers 文件中。此事将被报告。”的告警信息。并且通过查看防火墙状态,发现确实关闭了,到这里就说明我们已经将普通用户添加到了sudo列表中,可以正常的使用sudo命令来临时提升自己的权限。
验证完之后我们需要重启防火墙,并修改系统配置文件sudoers为只读的权限。
接下来我们就可以安装FreeTDS软件包了。
-
再次安装FreeTDS
[fenghx@localhost ~]$ sudo yum install freetds
[sudo] fenghx 的密码:
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
kernel-bek | 2.9 kB 00:00:00
kernel-lt | 2.9 kB 00:00:00
kernel-ml | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
docker-ce-stable/7/x86_64/primary_db | 97 kB 00:00:01
没有可用软件包 freetds。
错误:无须任何处理
[fenghx@localhost ~]$
提示没有当前的软件库中没有freetds软件包。于是需要我们安装一个Linux的扩展软件包EPEL(Extra Packages for Enterprise Linux),企业版Linux额外包。
-
安装EPEL
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[fenghx@localhost freetds]$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
已加载插件:fastestmirror
epel-release-latest-7.noarch.rpm | 15 kB 00:00:01
正在检查 /var/tmp/yum-root-G36fwv/epel-release-latest-7.noarch.rpm: epel-release-7-14.noarch
/var/tmp/yum-root-G36fwv/epel-release-latest-7.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-14 将被 安装
--> 解决依赖关系完成
......
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
......
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : epel-release-7-14.noarch 1/1
验证中 : epel-release-7-14.noarch 1/1
已安装:
epel-release.noarch 0:7-14
完毕!
[fenghx@localhost freetds]$
-
再次安装FreeTDS
[fenghx@localhost freetds]$ sudo yum install freetds
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirror.01link.hk
正在解决依赖关系
--> 正在检查事务
---> 软件包 freetds.x86_64.0.1.3.3-1.el7 将被 安装
--> 正在处理依赖关系 freetds-libs(x86-64) = 1.3.3-1.el7,它被软件包 freetds-1.3.3-1.el7.x86_64 需要
--> 正在处理依赖关系 libodbc.so.2()(64bit),它被软件包 freetds-1.3.3-1.el7.x86_64 需要
--> 正在处理依赖关系 libsybdb.so.5()(64bit),它被软件包 freetds-1.3.3-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 freetds-libs.x86_64.0.1.3.3-1.el7 将被 安装
---> 软件包 unixODBC.x86_64.0.2.3.1-14.el7 将被 安装
--> 解决依赖关系完成
......
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
......
已安装:
freetds.x86_64 0:1.3.3-1.el7
作为依赖被安装:
freetds-libs.x86_64 0:1.3.3-1.el7 unixODBC.x86_64 0:2.3.1-14.el7
完毕!
[fenghx@localhost freetds]$
到这里freetds软件就安装好了。
-
查看freetds安装信息
查看命令:tsql -C
[root@localhost freetds]# tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v1.3.3
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: auto
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: no
GnuTLS: yes
MARS: yes
[root@localhost freetds]#
-
使用tsql命令行访问sql server 数据库
tsql工具是安装FreeTDS软件包时附带安装的命令行工具。
-
登陆数据库命令
tsql {-S servername [-I interface] | -H hostname [-L] [-p port]} [-D dbname] [-U username] [-P password] [-o options]
这里Linux服务器本地已经安装了Sql Server数据库,并新建了fy2000数据库,里面有一张名为tb_student_info的表,构建了一些人物信息。下面就来查询下这张表看下能否成功。
- 登陆数据库
[fenghx@localhost ~]$ tsql -H 127.0.0.1 -p 1433 -D fy2000 -U sa -P 123456
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Setting fy2000 as default database in login packet
1>
如上所示,表示登陆成功,接下来就可以编辑sql语句操作了。
- 查询表内容
sql语句:select * from tb_student_info
1> select * from tb_student_info
2> go
name age height weight
xiaoli 5 25 128
ming 4 27 124
shuai 6 35 130
hong 3 30 100
jaing 7 23 126
xiaomei 5 24 110
(6 rows affected)
1>
如上所示,我们可以查询到表中的内容。
由上述的操作,说明我们的FreeTDS软件安装成功了,并可以使用。