Centos7环境使用docker搭建sql-server数据库!
Docker 安装
#卸载旧版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
设置存储库
安装所需的包。yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序。
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用以下命令设置稳定存储库。
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce docker-ce-cli containerd.io
启动
$ sudo systemctl start docker
Docker加速 | 阿里云加速(下载的时候发现好像也没有什么效果)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://loikhmrf.mirror.aliyuncs.com"]
}
EOF
修改服务器时间:(已经修改好的可以跳过这一步)
[root@cmzw-01 mssql]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5 #### 选择亚洲
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 9 #### 中国
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1 #### 北京
The following information has been given:
China
Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Thu Oct 17 08:56:14 CST 2019.
Universal Time is now: Thu Oct 17 00:56:14 UTC 2019.
Is the above information OK?
1) Yes
2) No
#? yes #### 同意
Please enter 1 for Yes, or 2 for No.
#? 1 #### 确认
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
[root@cmzw-01 mssql]# date
Thu Oct 17 08:57:27 CST 2019
安装MSSQL
1.服务器需要大于2G内存。如果不够则可能无法正常启动,查看日志报如下错误:This program requires a machine with at least 2000 megabytes of memory
2、获取 sqlserver 镜像
# 2017 版本
[root@master ~]# docker pull mcr.microsoft.com/mssql/server:2017-latest
3、镜像下载成功后,运行镜像
docker run -d --name mssql \
-e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Cmzw.2019' \
-p 1433:1433 \
-e 'TZ=Asia/Shanghai'\
-v /data/mssql/:/var/opt/mssql/data/ \
--restart=always \
mcr.microsoft.com/mssql/server:2017-latest
4 登录 sqlserver 容器
# 连接容器 [root@master ~]# docker exec -it mssql "bash" # 登录容器中的数据库 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Cmzw.2019" # 如果成功,应会显示 sqlcmd 命令提示符:1>
更改 SA 密码
SA 帐户是安装过程中在 SQL Server 实例上创建的系统管理员。 创建 SQL Server 容器后,通过在容器中运行
echo $SA_PASSWORD
,可发现指定的SA_PASSWORD
环境变量。 出于安全考虑,请考虑更改 SA 密码。1、选择 SA 用户要使用的强密码。 2、使用 docker exec 运行sqlcmd ,以使用 Transact-SQL 更改密码。 在下面的示例中,将旧密码 <YourStrong!Passw0rd> 和新密码 <YourNewStrong!Passw0rd> 替换为你自己的密码值。 [root@master ~]# docker exec -it mssl /opt/mssql-tools/bin/sqlcmd \ -S localhost -U SA -P "<YourStrong@Passw0rd>" \ -Q 'ALTER LOGIN SA WITH PASSWORD="<YourNewStrong@Passw0r>"'
网友评论