Tips and Tricks for Applying SCORCH 2016 UR4 and Later Versions

Note: The issues mentioned below may occur after you install Orchestrator 2016 UR4, or install later versions directly without installing UR4 first.

Issue 1

After upgrading Orchestrator to 2016 UR4 or 1801, you may get the following error message:

“Could Not Connect To The Specified Database Server”

or

“The Server Threw an Exception”

Resolution

To avoid that, install Microsoft SQL Server 2012 Native Client on your Orchestrator before installing the Update Rollup. It is a new prerequisite introduced by 2016 UR4, but hasn’t been well documented.

If you have already installed Update Rollup 4 and are getting that error, do the following on your Orchestrator.

  1. Close Orchestrator
  2. Install SQL Native Client if not installed already
  3. Open Data Store Configuration
  4. Enter your SQL server/instance info in the Server field, click Next
  5. Confirm Data Store information is correct, click Finish
  6. Re-open Orchestrator

Issue 2

You may get below error when accessing SCORCH web service after upgrading to UR4.

The server encountered an error processing the request. The exception message is ‘An error occurred while executing the command definition. See the inner exception for details.’. See server logs for more details. The exception stack trace is:
   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.EntityClient.EntityCommandDefinition.Execute(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.EntityClient.EntityCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.EntityClient.EntityCommand.ExecuteScalar[T_Result](Func`2 resultSelector)
   at System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)
   at Microsoft.SystemCenter.Orchestrator.WebService.OrchestratorContext.OnContextCreated()
   at invoke_constructor()
   at System.Data.Services.DataService`1.CreateDataSourceInstance()
   at System.Data.Services.DataService`1.CreateProvider()
   at System.Data.Services.DataService`1.HandleRequest()
   at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody)
   at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Resolution

To resolve the issue, run below queries on Orchestrator DB to grant EXECUTE and SELECT permission to Orchestrator Operators.

1
2
GRANT EXECUTE ON object::[Microsoft.SystemCenter.Orchestrator].[GetSecurityToken] TO [Microsoft.SystemCenter.Orchestrator.Operators]
GRANT SELECT ON object::[Microsoft.SystemCenter.Orchestrator.Internal].[Settings] TO [Microsoft.SystemCenter.Orchestrator.Operators]

Detailed troubleshooting steps can be found in Fail to connect to Orchestrator Web Service.

如何用WordPress + Nginx + MySQL + PHP搭建个人博客

准备工作

1. 云服务器

我选用的是阿里云服务器,操作系统是Ubuntu。因此本文搭建过程中涉及到的具体操作都以Ubuntu为例,其他操作系统可类推。

2. 域名及云解析DNS

有了服务器后,第二步便是申请域名及购买云解析DNS,也是在阿里云上购买的。阿里云会根据我们申请的域名个数自动调整云解析DNS的域名个数和费用。

主要步骤

这里给出用WordPress + Nginx + MySQL + PHP搭建个人博客的主要步骤,让大家对整体流程有一个完整的概念。详细步骤及操作方法见后文。文末附有可能遇到的问题及解决方案。

  1. 下载WordPress
  2. 安装PHP
  3. 安装Nginx
  4. 安装MySQL
  5. 创建WordPress用户名和数据库
  6. 复制WordPress文件到网站根目录
  7. 配置Nginx使用PHP及我们申请好的域名
  8. 为WordPress设置wp-config.php文件
  9. 安装及配置WordPress

详细步骤

一、下载WordPress

  1. 在WordPress官网下载安装文件到PC。
  2. 下载并安装WinSCP。通过WinSCP将WordPress安装文件从PC传输到Ubuntu服务器上。
  3. 解压WordPress安装文件。
1
sudo apt install unzip
1
unzip wordpress-5.2.1.zip

二、安装PHP

1
sudo apt install php

检查PHP的安装路径:

1
whereis php-fpm

启动PHP:

1
service php7.2-fpm start

三、安装Nginx

1
sudo apt install nginx

启动Nginx:

1
service nginx start

启动完成后,在浏览器中访问服务器公网IPhttp://xx.xx.xx.xx,应该可以看到如下页面。实际上打开的是/var/www/html/下的index.nginx-debian.html页面。

四、安装MySQL

我们需要为WordPress创建一个数据库,这里选用的是MySQL数据库服务。

安装MySQL:

1
2
3
sudo apt install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev

安装完后可以通过以下命令来检查安装结果,如果处于LISTEN状态,则安装成功。

1
sudo netstat -tap | grep mysql

五、创建WordPress用户名和数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 替换*adminusername*为你的数据库用户名
$ mysql -u *adminusername* -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

# 创建WordPress数据库,替换*databasename*为数据库名称,如blogdb
mysql> CREATE DATABASE *databasename*;
Query OK, 1 row affected (0.00 sec)

# 替换dabasename, wordpressusername, hostname和password。hostname通常是localhost
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
-> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
$

下面是我替换关键内容后的范例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE blogdb;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON blogdb.* TO "wendi"@"localhost"
-> IDENTIFIED BY "mypassword";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
$

六、复制WordPress文件到网站根目录

将解压后的WordPress目录下所有内容(无需转移目录本身)转移到网站根目录下。网站根目录默认为/var/www/html/,为了便于管理,我建立了路径/var/www/www.wendicai.net/作为我的网站根目录。

七、配置Nginx使用PHP及我们申请好的域名

修改Nginx的default配置文件,该文件位于/etc/nginx/sites-available/default。需要更改的地方已在下面列出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
server {
# 【更改点1】因为我们要使用域名访问,这里删除default_server
listen 80;
listen [::]:80;

# 【更改点2】网站根目录,默认路径为/var/www/html
# 为了便于管理,我建立了路径/var/www/www.wendicai.net为我的网站根目录
# 如果使用非默认路径,需要将原路径/var/www/html/下的所有文件拷贝到新路径中
root /var/www/www.wendicai.net;

#【更改点3】在index.html前加上index.php,以支持WordPress
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

#【更改点4】替换“_”为我们申请好的域名
server_name www.wendicai.net;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

#【更改点5】取消此部分注释,因为WordPress需要用到PHP。如果安装的PHP版本不是7.0,需要手动改下版本号
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

配置修改后需要重启Nginx服务生效:

1
sudo service nginx restart

如何配置Nginx绑定多个域名

值得一提的是,这台Ubuntu服务器是我和小伙伴共用的,我们各自申请了不同的域名,因此需要让Nginx同时识别两个域名,且两个域名对应各自的页面内容。

具体的配置方法如下:

  1. 分别给每个域名创建一个根目录
1
2
root@WebServer:/var/www# ls
www.wendicai.net www.xia-weiwen.com

并将原路径/var/www/html/下的所有文件拷贝过去。

  1. 分别给每个域名创建一个配置文件

/etc/nginx/vhost路径下为每个域名创建一个配置文件,命名为vhost_<域名关键字>.conf

1
2
root@Ubuntu:/etc/nginx/vhost# ls
vhost_wendicai.conf vhost_xia-weiwen.conf

/etc/nginx/sites-available/default文件内容拷贝到新配置文件中,并按前文所述的配置文件修改方法,分别修改两个域名的配置信息。root网站根目录应分别为步骤1中创建的对应目录。

  1. 将新配置文件路径加入到nginx.config

修改/etc/nginx/nginx.conf文件,在http代码块中添加新的配置文件路径:

1
2
3
4
5
6
7
8
http {
......
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

# 添加新配置文件所在路径/etc/nginx/vhost/*.conf
include /etc/nginx/vhost/*.conf;
}
  1. 重启Nginx服务以生效
1
service nginx restart

现在,分别访问两个域名www.wendicai.netwww.xia-weiwen.com,实际打开的页面将分别是/var/www/www.wendicai.net/var/www/www.xia-weiwen.com下的文件。

八、为WordPress设置wp-config.php文件

在浏览器中访问http://<域名>/wp-admin/install.php, 出现以下页面,要求填入数据库信息。

说明:

Database Name是步骤六中创建的数据库名称,我的是blogdb。

User NamePassword分别是是步骤六中创建的数据库用户名和密码。

Database Host与步骤六中设定的hostname一致,通常是localhost
Table Prefix可以不改,但由于我们要在同一个数据库中管理两个域名下的数据,我在默认前缀后又加上了各自的域名。

点击Submit,可能会遇到以下两种情况:

配置文件自动修改成功。此时不要点击Run the Install,进入步骤八继续。

如果WordPress无法查找到wp-config.php文件,则会根据我们填入的信息自动生成配置文件内容,并建议我们手动创建并编辑wp-config.php文件。

如果是第二种情况,我们只需要在WordPress的解压路径中找到wp-config-sample.php文件,将其重命名为wp-config.php,并将上面自动生成的配置文件内容拷贝到wp-config.php中。

九、安装WordPress

  • 如果配置文件自动修改成功,此时点击Run the install安装即可。
  • 如果wp-config.php为手动创建,需要重新访问http://<域名>/wp-admin/install.php,进入安装。
    填入以下个人信息和偏好设置后,点击Install WordPress进行安装。这一页填入的信息将来在WordPress后台http://<域名>/wp-admin都是可更改的。

安装成功啦!接下来就可以登录进入后台愉快地玩耍了~

WordPress怎么玩?可以参考WordPress的官方文档。

WordPress官方中文文档:http://codex.wordpress.org.cn/%E9%A6%96%E9%A1%B5

使用WordPress:http://codex.wordpress.org.cn/%E4%BD%BF%E7%94%A8_WordPress

可能遇到的问题

我在搭建过程中遇到了不少问题,在这里将这些问题与其解决方法分享出来,希望可以帮助大家少走弯路。

  • “nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)”

Nginx安装完成后,启动Nginx失败并出现以下报错

这是因为80端口被其他服务占用。可以通过以下命令来检查:

1
lsof -i:80

我的情况是云服务器本身预装了apache,从结果中可以看出80端口被apaceh2占用。

将apache2服务停掉后,成功启动Nginx。

  • 主题、插件等“安装失败:无法创建目录”

用以下命令添加权限:

1
chmod -R 777 /var/www/www.wendicai.net # 网站根目录
  • “在裁剪您的图像时发生了错误”

在WordPress中裁剪图片时,报错“在裁剪您的图像时发生了错误”。

这是由于PHP的GD库未安装。运行以下命令安装:

1
apt-get install php7.2-gd
  • 设置中英文摘要长度

外观->主题编辑器中找到functions.php,在末尾加上以下代码。

中文摘要(替换“100”为你想要的长度):

1
2
3
4
5
6
7
8
9
10
function iesay_filter_chinese_excerpt( $output ) {
global $post;
//check if its chinese character input
$chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
if($chinese_output) {
$output = mb_substr( $output, 0, 100 ) . '...';
}
return $output;
}
add_filter( 'get_the_excerpt', 'iesay_filter_chinese_excerpt' );

英文摘要(替换“50”为你想要的长度)

1
2
3
4
5
6
7
8
9
10
function ie_longer_excerpts( $length ) {
// Don't change anything inside /wp-admin/
if ( is_admin() ) {
return $length;
}
// Set excerpt length to 50 words
return 50;
}
// "999" priority makes this run last of all the functions hooked to this filter, meaning it overrides them
add_filter( 'excerpt_length', 'ie_longer_excerpts', 999 );
  • 设置文章中所有链接在新窗口中打开

外观->主题编辑器中找到functions.php,在末尾加上以下代码。

1
2
3
4
5
function autoblank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
add_filter('the_content', 'autoblank');
  • 域名变更了怎么办?

有段时间工作很忙疏于维护博客,结果之前申请的域名就到期被收回了,而且紧接着还被人抢注了= =无奈之下只得更换域名。。

这种情况直接用新域名访问肯定是不行的,需要在Nginx和Wordpress相应的配置文件中也更改为新的域名。

需要修改的主要是以下几处:

  1. Nginx的配置文件,默认路径是/etc/nginx/sites-available/default

如果你像我一样自己创建了另外的网站根目录,则需要修改对应目录下的配置文件。按照前文所述的配置,我需要修改的是/etc/nginx/vhost/vhost_wendicai.conf

修改后需重启Nginx服务以生效:service nginx restart

  1. Wordpress上的更改可参考这篇博客

我的情况是原域名WordPress管理区域已经无法访问,因此采取了方法2,在/wp-content/themes/your-theme-folder/functions.php文件底部添加以下代码:

1
2
update_option( 'siteurl', 'http://www.wendicai.net' );
update_option( 'home', 'https://www.wendicai.net' );

重新访问新URL,确认一切正常后就可以删除这两行代码了。