Project

General

Profile

Database Server Installation Shared » History » Version 50

Amber Herold, 05/17/2010 01:36 PM

1 1 Amber Herold
h1. Database Server Installation
2
3
h2. Install MySQL 
4
5
The following is for the computer that hosts the databases. This involves installing MySQL server and creation/configuration of the leginondb and projectdb databases.
6
7 38 Amber Herold
8 1 Amber Herold
 
9 42 Amber Herold
h3. 1 Install MySQL-Server and MySQL-Client
10 38 Amber Herold
11
*Note:* You may already have MySQL Server and Client installed. Check by typing mysql at the command line. 
12
If you see a MySQL prompt (mysql>), you may skip this step.
13 1 Amber Herold
14 15 Neil Voss
To install Mysql on Linux you have two options (the first option is better):
15 1 Amber Herold
16 15 Neil Voss
# Use your package installer (yum, zypper, YaST, apt-get). For example:
17
<pre>sudo yum install mysql mysql-server</pre>
18
# Download the latest MySQL-server package for Linux from http://www.mysql.com
19 1 Amber Herold
20 42 Amber Herold
h3. 2 Locate Example MySQL configuration files 
21 1 Amber Herold
22 42 Amber Herold
They are usually located in /usr/share/mysql.
23
24 1 Amber Herold
<pre>
25
ls /usr/share/mysql/my*
26 15 Neil Voss
    /usr/share/mysql/my-huge.cnf
27
    /usr/share/mysql/my-innodb-heavy-4G.cnf
28
    /usr/share/mysql/my-large.cnf
29
    /usr/share/mysql/my-medium.cnf
30
    /usr/share/mysql/my-small.cnf
31 20 Neil Voss
</pre>
32
If that does not work try the locate function
33
<pre>
34 15 Neil Voss
locate my | egrep "\.cnf$"
35
    /etc/my.cnf
36 1 Amber Herold
    /usr/share/mysql/my-huge.cnf
37
    /usr/share/mysql/my-innodb-heavy-4G.cnf
38
    /usr/share/mysql/my-large.cnf
39
    /usr/share/mysql/my-medium.cnf
40
    /usr/share/mysql/my-small.cnf
41 3 Amber Herold
</pre>
42 1 Amber Herold
43 42 Amber Herold
h3. 3 Configure my.cnf in /etc using my-huge.cnf as the template
44 1 Amber Herold
45 18 Neil Voss
# Copy my-huge.cnf to my.cnf
46 19 Neil Voss
<pre>sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf</pre>
47 22 Neil Voss
# Edit /etc/my.cnf to add or change query cache variables like these (be sure to place them under the @[mysqld]@ section):
48 1 Amber Herold
<pre>
49 39 Amber Herold
query_cache_type = 1
50 1 Amber Herold
query_cache_size = 100M
51 21 Neil Voss
query_cache_limit= 100M
52 1 Amber Herold
</pre>
53 11 Neil Voss
# Search for the text default-storage-engine in /etc/my.cnf.  If it exists and is set to other than MyISAM, you should change it to:
54 1 Amber Herold
<pre>default-storage-engine=MyISAM</pre>
55 10 Neil Voss
56 42 Amber Herold
h3. 4 Start the MySQL Server
57 1 Amber Herold
58 10 Neil Voss
For CentOS/Fedora/RHEL system use the service command:
59
60 1 Amber Herold
<pre>
61 10 Neil Voss
sudo /sbin/service mysqld start
62 1 Amber Herold
</pre>
63
64 10 Neil Voss
For other Unix systems:
65
66
<pre>
67
sudo /etc/init.d/mysqld start
68
</pre>
69
70 12 Neil Voss
or on some installations,
71 1 Amber Herold
72
<pre>
73 10 Neil Voss
sudo /etc/init.d/mysql start
74 1 Amber Herold
</pre>
75
76
For future reference: start | stop | restart MySQL Server with similar commands:
77
78
<pre>
79 10 Neil Voss
sudo /etc/init.d/mysqld start
80
sudo /etc/init.d/mysqld stop
81
sudo /etc/init.d/mysqld restart
82 1 Amber Herold
sudo /sbin/service mysqld start
83 10 Neil Voss
sudo /sbin/service mysqld stop
84
sudo /sbin/service mysqld restart
85 1 Amber Herold
</pre>
86
87 42 Amber Herold
h3. 5 Configure MySQL to start automatically at boot
88 1 Amber Herold
89
<pre>
90
sudo /sbin/chkconfig mysqld on
91
</pre>
92 23 Neil Voss
or for SuSe:
93
<pre>
94
sudo /sbin/chkconfig mysql on
95
</pre>
96 1 Amber Herold
97 42 Amber Herold
h3. 6 For future reference, the database location will be:
98 1 Amber Herold
99 10 Neil Voss
<pre>
100
ls /var/lib/mysql
101 1 Amber Herold
    ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
102
</pre>
103
104 42 Amber Herold
h3. 7 Create the Leginon database, call it leginondb
105 3 Amber Herold
106 10 Neil Voss
<pre>
107 1 Amber Herold
sudo mysqladmin create leginondb
108
</pre>
109
110 42 Amber Herold
h3. 8 Create the Project database, call it projectdb
111 1 Amber Herold
112
<pre>
113
sudo mysqladmin create projectdb
114
</pre>
115
116 42 Amber Herold
h3. 9 Connect to mysql db
117 11 Neil Voss
118 40 Amber Herold
If starting from scratch, the mysql root user will have no password. This is assumed to be the case and we will set it later.
119 1 Amber Herold
120 23 Neil Voss
<pre>
121 28 Neil Voss
mysql -u root mysql
122 23 Neil Voss
</pre>
123 1 Amber Herold
124 40 Amber Herold
You should see a mysql prompt: mysql>
125
126
You can view the current mysql users with the following command.
127 11 Neil Voss
<pre>
128 40 Amber Herold
select user, password, host from user;
129 1 Amber Herold
      +------+----------+-----------+
130
      | user | password | host      |
131
      +------+----------+-----------+
132
      | root |          | localhost |
133
      | root |          | host1     |
134
      |      |          | host1     |
135
      |      |          | localhost |
136
      +------+----------+-----------+
137
      4 rows in set (0.00 sec)
138
</pre>
139
140 42 Amber Herold
h3. 10 Create user
141 1 Amber Herold
142 41 Amber Herold
Create and grant privileges to a user called usr_object for the databases on both the localhost and other hosts involved. For example, use wild card '%' for all hosts. You can set specific (@ALTER, CREATE, DROP, DELETE, INSERT, RENAME, SELECT, UPDATE@) privileges or @ALL@ privileges to the user. See MySQL Reference Manual for details. The following examples demonstrate some of the options available.
143 3 Amber Herold
144 36 Amber Herold
At the mysql prompt execute the following commands:
145 1 Amber Herold
<pre>
146 36 Amber Herold
CREATE USER usr_object@'localhost' IDENTIFIED BY 'YOUR PASSWORD';
147
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* TO usr_object@'localhost';
148
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* TO usr_object@'localhost';
149 1 Amber Herold
</pre>
150
151 41 Amber Herold
You may choose to use the following less secure version (no password and all privileges) of the commands above, however, we recommend not allowing the DROP and DELETE privileges.
152 1 Amber Herold
153 36 Amber Herold
At the mysql prompt execute the following commands:
154 24 Neil Voss
<pre>
155 36 Amber Herold
CREATE USER usr_object@'localhost';
156
GRANT ALL PRIVILEGES ON leginondb.* TO usr_object@'localhost';
157 1 Amber Herold
GRANT ALL PRIVILEGES ON projectdb.* TO usr_object@'localhost';
158
</pre>
159 24 Neil Voss
160 41 Amber Herold
You may also choose to assign a domain to your commands and use a wildcard to allow access from all computers in the domain. 
161 26 Neil Voss
162 1 Amber Herold
<pre>
163 36 Amber Herold
CREATE USER usr_object@'%.mydomain.edu' IDENTIFIED BY 'YOUR PASSWORD';
164
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* to usr_object@'%.mydomain.edu';
165 1 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* to usr_object@'%.mydomain.edu';
166 24 Neil Voss
</pre>
167 3 Amber Herold
168 42 Amber Herold
h3. 11 Give create and access privileges for the processing databases which begin with "ap".
169 10 Neil Voss
170 24 Neil Voss
<pre>
171 27 Neil Voss
# if your web host is local
172 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@localhost; 
173 27 Neil Voss
# for all other hosts if you are accessing the databases from another computer
174 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@'%.mydomain.edu';       
175 1 Amber Herold
</pre>
176
177 42 Amber Herold
h3. 12 Change Root password
178 1 Amber Herold
179 28 Neil Voss
To set the root password use the command: 
180 1 Amber Herold
181 28 Neil Voss
<pre>
182
sudo mysqladmin -u root password NEWPASSWORD
183
</pre>
184 1 Amber Herold
185 28 Neil Voss
Or you can do it from within mysql
186 10 Neil Voss
<pre>
187 36 Amber Herold
update user set password=password('your_own_root_password') where user="root";
188 1 Amber Herold
Query OK, 2 rows affected (0.01 sec)
189
Rows matched: 2  Changed: 2  Warnings: 0
190
191 43 Amber Herold
# run the flush privileges command to avoid problems
192 36 Amber Herold
flush privileges;
193
^D or exit;
194 3 Amber Herold
</pre>
195 1 Amber Herold
196 3 Amber Herold
197 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
198
199 30 Neil Voss
<pre>
200 36 Amber Herold
mysql -u root -p mysql
201 1 Amber Herold
</pre>
202
203 42 Amber Herold
h3. 13 Check MySQL variables
204 1 Amber Herold
205 31 Neil Voss
<pre>
206 44 Amber Herold
# at the command prompt, log into the leginon database
207
208 36 Amber Herold
mysql -u usr_object -p leginondb
209 1 Amber Herold
210 44 Amber Herold
# At the mysql prompt show variables that begin with 'query'.
211
# Check that the changes you made to my.cfg are in place.
212
213 36 Amber Herold
SHOW VARIABLES LIKE 'query%';
214 1 Amber Herold
      +------------------------------+-----------+
215
      | Variable_name                | Value     |
216
      +------------------------------+-----------+
217
      | ft_query_expansion_limit     | 20        |
218
      | have_query_cache             | YES       |
219
      | long_query_time              | 10        |
220
      | query_alloc_block_size       | 8192      |
221 44 Amber Herold
      | query_cache_limit            | 104857600 | ---This should correspond to your change
222 1 Amber Herold
      | query_cache_min_res_unit     | 4096      |
223 44 Amber Herold
      | query_cache_size             | 104857600 | ---This should correspond to your change
224
      | query_cache_type             | ON        | ---This should correspond to your change
225 1 Amber Herold
      | query_cache_wlock_invalidate | OFF       |
226
      | query_prealloc_size          | 8192      |
227
      +------------------------------+-----------+
228
      10 rows in set (0.00 sec)
229 36 Amber Herold
230 1 Amber Herold
exit;
231
</pre>
232 42 Amber Herold
233 1 Amber Herold
h3. 14 Make sure MySQL is running
234 3 Amber Herold
235 36 Amber Herold
<pre>
236 45 Amber Herold
mysqlshow -u root
237 1 Amber Herold
      +--------------+
238 30 Neil Voss
      | Databases    |
239
      +--------------+
240
      | mysql        |
241
      | leginondb    |
242 1 Amber Herold
      | projectdb    |
243
      +--------------+
244 30 Neil Voss
</pre>
245 36 Amber Herold
246 1 Amber Herold
h3. Run the following command from the command line:
247 30 Neil Voss
248 46 Amber Herold
249 1 Amber Herold
<pre>
250
php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo ""
251 30 Neil Voss
</pre>
252 1 Amber Herold
253
Expected output:
254
255
<pre>
256
Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
257 47 Amber Herold
</pre>
258
259 48 Amber Herold
If there are any error messages, mysql may be configured incorrectly.
260
261 47 Amber Herold
*Note:* If you do not have php and php-mysql packages installed you need to install them to run the above command. The yum installation is:
262
<pre>
263
sudo yum -y install php php-mysql
264 36 Amber Herold
</pre>
265 30 Neil Voss
266 1 Amber Herold
267 30 Neil Voss
h2. Configure phpMyAdmin 
268 1 Amber Herold
269 50 Amber Herold
You are not required to install phpMyAdmin for Appion or Leginon, however, it is a useful tool for interfacing with the mysql databases. 
270 49 Amber Herold
271 12 Neil Voss
Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines:
272 30 Neil Voss
273 1 Amber Herold
<pre>
274
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
275 30 Neil Voss
</pre>
276 1 Amber Herold
277
Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines:
278
279
<pre>
280
<Directory /usr/share/phpMyAdmin/>
281
   order deny,allow
282
   deny from all
283
   allow from 127.0.0.1
284
   allow from YOUR_IP_ADDRESS
285 31 Neil Voss
</Directory>
286
</pre>
287 1 Amber Herold
288 33 Neil Voss
*Note:* If you want to access phpMyAdmin from another computer, you can also add it to this config file with an @allow from@ tag
289
290
Next restart the web server to take on the new setting
291
<pre>
292
sudo /sbin/service httpd restart
293 1 Amber Herold
</pre>
294 35 Neil Voss
295
To test the phpMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpMyAdmin or http://localhost/phpMyAdmin and login with the usr_object user.
296 33 Neil Voss
297
!phpMyAdmin.png!
298
299
A common problem is that the firewall may be blocking access to the web server and mysql server. On CentOS/Fedora you can configure this with the system config:
300
301
<pre>
302
system-config-securitylevel
303
</pre>
304 1 Amber Herold
305
Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines.